浏览代码

Offline mode

master
Flo Smilari 4 年前
父节点
当前提交
cea0385089

+ 9
- 0
Components/WarningImage.razor 查看文件

@page "/warningimage"
<div class="text-center">
<img src="./images/warning.png" class="w-50" alt="Warning!" />
</div>
@code {
}

+ 36
- 24
Pages/CaritasServiceFundVeloFoundConclusion.razor 查看文件

<div class="row no-gutters align-items-start justify-content-center w-100"> <div class="row no-gutters align-items-start justify-content-center w-100">
<MatHeadline4 Style="font-family:Ubuntu;padding-top:1em">@i18n["Confirmation"]</MatHeadline4> <MatHeadline4 Style="font-family:Ubuntu;padding-top:1em">@i18n["Confirmation"]</MatHeadline4>
</div> </div>
@if (responseOk) {
@if (ResposeStatus.OK == responseStatus) {
<div class="row no-gutters align-items-start justify-content-center w-100" style="height:fit-content"> <div class="row no-gutters align-items-start justify-content-center w-100" style="height:fit-content">
<div class="w-100" style="text-align: center"> <div class="w-100" style="text-align: center">
<MatHeadline6 Style="font-family:Ubuntu">@i18n["FinishedTextFound"]</MatHeadline6> <MatHeadline6 Style="font-family:Ubuntu">@i18n["FinishedTextFound"]</MatHeadline6>
</div> </div>
</div> </div>
} }
<div class="row no-gutters align-items-start justify-content-center w-100" style="height:fit-content">
@if (running) {
<div style="width:48px;margin:0 auto;">
<MatProgressCircle Indeterminate="true" Size="MatProgressCircleSize.Large" />
</div>
<div class="w-100" style="text-align:center;">
<h6 style="font-style:italic;padding-bottom:1em">@i18n["Info.Report.Transmitting"]</h6>
</div>
<div class="row no-gutters align-items-start justify-content-center w-100" style="height:fit-content">
@if (running) {
<div style="width:48px;margin:0 auto;">
<MatProgressCircle Indeterminate="true" Size="MatProgressCircleSize.Large" />
</div>
<div class="w-100" style="text-align:center;">
<h6 style="font-style:italic;padding-bottom:1em">@i18n["Info.Report.Transmitting"]</h6>
</div>
} else {
if (ResposeStatus.OK == responseStatus) {
<Animate Animation="Animations.ZoomIn" Duration="TimeSpan.FromSeconds(2.5)">
<DoneImage></DoneImage>
</Animate>
} else if (ResposeStatus.Error == responseStatus) {
<Animate Animation="Animations.ZoomIn" Duration="TimeSpan.FromSeconds(2.5)">
<FailureImage></FailureImage>
</Animate>
} else { } else {
if (responseOk) {
<Animate Animation="Animations.ZoomIn" Duration="TimeSpan.FromSeconds(2.5)">
<DoneImage></DoneImage>
</Animate>
} else {
<Animate Animation="Animations.ZoomIn" Duration="TimeSpan.FromSeconds(2.5)">
<FailureImage></FailureImage>
</Animate>
}
<Animate Animation="Animations.ZoomIn" Duration="TimeSpan.FromSeconds(2.5)">
<WarningImage></WarningImage>
</Animate>
} }
</div>
}
</div>
<div class="row no-gutters align-items-end justify-content-center w-100" style="padding-bottom:2em;padding-top:2em"> <div class="row no-gutters align-items-end justify-content-center w-100" style="padding-bottom:2em;padding-top:2em">
<div class="col w-100 text-center"> <div class="col w-100 text-center">
<MatButton Class="w-50" Raised="true" @onclick="Finished">@i18n["Finished"]</MatButton> <MatButton Class="w-50" Raised="true" @onclick="Finished">@i18n["Finished"]</MatButton>
@code { @code {
enum ResposeStatus : ushort {
OK = 1,
Error = 10,
NoConnection = 20
}
private Animate doneAnimZoom; private Animate doneAnimZoom;
private bool responseOk = false;
private ResposeStatus responseStatus = ResposeStatus.NoConnection;
private bool running = true; private bool running = true;
private string referenceNumber; private string referenceNumber;
ReportResponse response; ReportResponse response;
PageHistoryManager.AddPageToHistory(NavigationManager.Uri); PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
try { try {
response = await IBicycleRestService.SendFoundReport(ReportDataProvider.Report); response = await IBicycleRestService.SendFoundReport(ReportDataProvider.Report);
responseOk = System.Net.HttpStatusCode.OK == response.StatusCode ? true : false;
responseStatus = response==null ? ResposeStatus.NoConnection : System.Net.HttpStatusCode.OK == response.StatusCode ? ResposeStatus.OK : ResposeStatus.Error;
} catch (HttpRequestException ex) { } catch (HttpRequestException ex) {
response = new(i18n.GetString("FoundBike"), new string[] { ex.Message }); response = new(i18n.GetString("FoundBike"), new string[] { ex.Message });
responseOk = false;
responseStatus = ResposeStatus.Error;
} }
running = false; running = false;
if (responseOk) {
if (ResposeStatus.OK == responseStatus) {
Toaster.ShowSuccess(i18n.GetString("FoundBike"), response.Message); Toaster.ShowSuccess(i18n.GetString("FoundBike"), response.Message);
referenceNumber = (response.Data != null && response.Data.Length > 0) ? response.Data[0] : "-"; referenceNumber = (response.Data != null && response.Data.Length > 0) ? response.Data[0] : "-";
PageHistoryManager.Reset(); PageHistoryManager.Reset();
} else {
} else if (ResposeStatus.Error == responseStatus) {
Toaster.ShowError(response.Message, response.GetDataAsFormattedList()); Toaster.ShowError(response.Message, response.GetDataAsFormattedList());
} else {
Toaster.ShowWarning(i18n.GetString("Warning.NoConnection.Title"), i18n.GetString("Warning.NoConnection.Msg"));
} }
StateHasChanged(); StateHasChanged();
AppState.NotifyChanged(); AppState.NotifyChanged();

+ 7
- 6
Pages/IndexPage.razor 查看文件

@inject Toaster Toaster; @inject Toaster Toaster;
@inject IConfiguration Configuration; @inject IConfiguration Configuration;
@inject IBicycleRestService IBicycleRestService; @inject IBicycleRestService IBicycleRestService;
@inject OnlineStatusProvider OnlineStatusProvider;
<div class="row h-100 justify-content-center"> <div class="row h-100 justify-content-center">
<div class="row align-items-end vw-100 h-50"> <div class="row align-items-end vw-100 h-50">
<div class="col text-center"> <div class="col text-center">
<h3 style="font-style:italic;padding-bottom:1em">@i18n["Welcome"]</h3> <h3 style="font-style:italic;padding-bottom:1em">@i18n["Welcome"]</h3>
<div>
<MatButton Disabled="@btnDisabled" Raised="true" Style="width:50%" @onclick="@((e) => ButtonClicked())">@i18n["Login"]</MatButton>
</div>
@*<div>
<MatButton Disabled="@btnDisabled" Raised="true" Style="width:50%" @onclick="@((e) => NavigateToNext())">@i18n["Login"]</MatButton>
</div>*@
</div> </div>
</div> </div>
<div class="row align-items-center justify-content-center vw-100 h-25"> <div class="row align-items-center justify-content-center vw-100 h-25">
showProgressCircle = true; showProgressCircle = true;
StateHasChanged(); StateHasChanged();
try { try {
IBicycleRestService.Initialize(Configuration);
IBicycleRestService.Initialize(Configuration, OnlineStatusProvider);
await MasterDataService.SynchronizeMasterdata(); await MasterDataService.SynchronizeMasterdata();
} catch (Exception) { } catch (Exception) {
Toaster.ShowWarning(i18n.GetString("Warning.Masterdata.Title"), i18n.GetString("Warning.Masterdata.Msg")); Toaster.ShowWarning(i18n.GetString("Warning.Masterdata.Title"), i18n.GetString("Warning.Masterdata.Msg"));
} finally { } finally {
showProgressCircle = false; showProgressCircle = false;
NavigateToNext();
} }
} }
btnDisabled = false; btnDisabled = false;
StateHasChanged(); StateHasChanged();
} }
private void ButtonClicked() {
private void NavigateToNext() {
NavigationManager.NavigateTo("./caritas_services"); NavigationManager.NavigateTo("./caritas_services");
AppState.LoggedIn = true;
} }
} }

+ 20
- 24
Shared/NavMenu.razor 查看文件

<MatAppBarSection> <MatAppBarSection>
<MatIconButton Icon="menu" OnClick="@((e) => ButtonClicked())"></MatIconButton> <MatIconButton Icon="menu" OnClick="@((e) => ButtonClicked())"></MatIconButton>
@if (PageHistoryManager.CanGoBack()) { @if (PageHistoryManager.CanGoBack()) {
<MatIconButton Icon="keyboard_backspace" OnClick="@((e) => ButtonBackClicked())" Disabled="@BackButtonDisabled()"></MatIconButton>
<MatIconButton Icon="@MatIconNames.Keyboard_backspace" OnClick="@((e) => ButtonBackClicked())" Disabled="@BackButtonDisabled()"></MatIconButton>
} }
<MatAppBarTitle Class="navBar-title">@LocationUrl</MatAppBarTitle> <MatAppBarTitle Class="navBar-title">@LocationUrl</MatAppBarTitle>
</MatAppBarSection> </MatAppBarSection>
</MatRipple> </MatRipple>
<MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default"> <MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default">
<MatListItem Class="@((Index == 3) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0" <MatListItem Class="@((Index == 3) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0"
Href="info"
Disabled="true"
Href="extras"
@onclick="@((e) => ButtonClicked(3))"> @onclick="@((e) => ButtonClicked(3))">
<MatIcon Icon="@MatIconNames.Error_outline" Style="transform: rotate(180deg)"></MatIcon>
<MatListItemText Style="padding-left:0.5em">@i18n["info"]</MatListItemText>
<MatIcon Icon="@MatIconNames.View_quilt"></MatIcon>
<MatListItemText Style="padding-left:0.5em">@i18n["Extras"]</MatListItemText>
</MatListItem> </MatListItem>
</MatRipple> </MatRipple>
<MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default"> <MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default">
<MatListItem Class="@((Index == 4) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0" <MatListItem Class="@((Index == 4) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0"
href=""
Match="NavLinkMatch.All"
Href="info"
@onclick="@((e) => ButtonClicked(4))"> @onclick="@((e) => ButtonClicked(4))">
<MatIcon Icon="@MatIconNames.Exit_to_app"></MatIcon>
<MatListItemText Style="padding-left:0.5em">@i18n["Logout"]</MatListItemText>
<MatIcon Icon="@MatIconNames.Error_outline" Style="transform: rotate(180deg)"></MatIcon>
<MatListItemText Style="padding-left:0.5em">@i18n["info"]</MatListItemText>
</MatListItem> </MatListItem>
</MatRipple> </MatRipple>
</MatList> </MatList>
} }
protected override void OnInitialized() { protected override void OnInitialized() {
base.OnInitialized();
AppState.OnChange += StateHasChanged; AppState.OnChange += StateHasChanged;
NavigationManager.LocationChanged += LocationChanged; NavigationManager.LocationChanged += LocationChanged;
PageHistoryManager.AddPageToHistory(NavigationManager.Uri); PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
base.OnInitialized();
locUrl = i18n.GetString(NavigationManager.Uri.Replace(NavigationManager.BaseUri, ""));
StateHasChanged();
} }
private void ButtonClicked() { private void ButtonClicked() {
private void ButtonClicked(int _Index) { private void ButtonClicked(int _Index) {
Index = _Index; Index = _Index;
ButtonClicked(); ButtonClicked();
if (_Index == 4) {
AppState.LoggedIn = false;
}
} }
private void ButtonBackClicked() { private void ButtonBackClicked() {
} else if (e.Location.Contains("account")) { } else if (e.Location.Contains("account")) {
Index = 2; Index = 2;
} else if (e.Location.Contains("info")) { } else if (e.Location.Contains("info")) {
Index = 3;
} else {
Index = 4; Index = 4;
} else {
Index = 3;
} }
StateHasChanged(); StateHasChanged();
} }
string baseUri = NavigationManager.BaseUri; string baseUri = NavigationManager.BaseUri;
string delta = uri.Replace(baseUri, ""); string delta = uri.Replace(baseUri, "");
if (delta == null || delta.Equals("")) {
if (delta.Equals("caritas_services")) {
Index = 1;
} else if (delta.Equals("account")) {
Index = 2;
} else if (delta.Equals("info")) {
Index = 4; Index = 4;
return false;
} else { } else {
if (delta.Equals("caritas_services")) {
Index = 1;
} else if (delta.Equals("account")) {
Index = 2;
} else if (delta.Equals("info")) {
Index = 3;
}
return true;
Index = 3;
} }
return true;
} }
private bool BackButtonDisabled() { private bool BackButtonDisabled() {

+ 9
- 0
Shared/ResourceFiles/Resources.de.resx 查看文件

<data name="Error.PhotoOrPictureToBig.Title" xml:space="preserve"> <data name="Error.PhotoOrPictureToBig.Title" xml:space="preserve">
<value>Bilddatei zu gross!</value> <value>Bilddatei zu gross!</value>
</data> </data>
<data name="Extras" xml:space="preserve">
<value>Extras</value>
</data>
<data name="Female" xml:space="preserve"> <data name="Female" xml:space="preserve">
<value>Frau</value> <value>Frau</value>
</data> </data>
<data name="Warning.Masterdata.Title" xml:space="preserve"> <data name="Warning.Masterdata.Title" xml:space="preserve">
<value>Stammdaten nicht verfügbar!</value> <value>Stammdaten nicht verfügbar!</value>
</data> </data>
<data name="Warning.NoConnection.Msg" xml:space="preserve">
<value>Die Meldung konnte nicht übertragen werde. Sie wurde gespeichert und wird sobald wie möglich übertragen.</value>
</data>
<data name="Warning.NoConnection.Title" xml:space="preserve">
<value>Keine Verbindung zum Internet!</value>
</data>
<data name="Warning.Nominatim.Msg" xml:space="preserve"> <data name="Warning.Nominatim.Msg" xml:space="preserve">
<value>Die Adresse konnte beim Aufrufen des Nominatim-Dienstes nicht aufgelöst werden. Bitte geben Sie die Straße und Postleitzahl/Ort manuell ein.</value> <value>Die Adresse konnte beim Aufrufen des Nominatim-Dienstes nicht aufgelöst werden. Bitte geben Sie die Straße und Postleitzahl/Ort manuell ein.</value>
</data> </data>

+ 9
- 0
Shared/ResourceFiles/Resources.fr.resx 查看文件

<data name="Error.PhotoOrPictureToBig.Title" xml:space="preserve"> <data name="Error.PhotoOrPictureToBig.Title" xml:space="preserve">
<value>La taille de la photo est trop grande!</value> <value>La taille de la photo est trop grande!</value>
</data> </data>
<data name="Extras" xml:space="preserve">
<value>Extras</value>
</data>
<data name="Female" xml:space="preserve"> <data name="Female" xml:space="preserve">
<value>Madame</value> <value>Madame</value>
</data> </data>
<data name="Warning.Masterdata.Title" xml:space="preserve"> <data name="Warning.Masterdata.Title" xml:space="preserve">
<value>Les données de base ne sont pas disponibles!</value> <value>Les données de base ne sont pas disponibles!</value>
</data> </data>
<data name="Warning.NoConnection.Msg" xml:space="preserve">
<value>Le message n'a pas pu être transmis. Il a été sauvegardé et sera transmis dès que possible.</value>
</data>
<data name="Warning.NoConnection.Title" xml:space="preserve">
<value>Pas de connexion à l'internet !</value>
</data>
<data name="Warning.Nominatim.Msg" xml:space="preserve"> <data name="Warning.Nominatim.Msg" xml:space="preserve">
<value>L'adresse n'a pas pu être résolue en invoquant le service Nominatim. Veuillez saisir l'adresse en indiquant la rue et le code postal/ville.</value> <value>L'adresse n'a pas pu être résolue en invoquant le service Nominatim. Veuillez saisir l'adresse en indiquant la rue et le code postal/ville.</value>
</data> </data>

+ 9
- 0
Shared/ResourceFiles/Resources.it.resx 查看文件

<data name="Error.PhotoOrPictureToBig.Title" xml:space="preserve"> <data name="Error.PhotoOrPictureToBig.Title" xml:space="preserve">
<value>Dimensione dell'immagine troppo grande!</value> <value>Dimensione dell'immagine troppo grande!</value>
</data> </data>
<data name="Extras" xml:space="preserve">
<value>Extras</value>
</data>
<data name="Female" xml:space="preserve"> <data name="Female" xml:space="preserve">
<value>Signora</value> <value>Signora</value>
</data> </data>
<data name="Warning.Masterdata.Title" xml:space="preserve"> <data name="Warning.Masterdata.Title" xml:space="preserve">
<value>Dati anagrafici non disponibili!</value> <value>Dati anagrafici non disponibili!</value>
</data> </data>
<data name="Warning.NoConnection.Msg" xml:space="preserve">
<value>Il messaggio non può essere trasmesso. È stato salvato e sarà trasmesso al più presto.</value>
</data>
<data name="Warning.NoConnection.Title" xml:space="preserve">
<value>Nessuna connessione a Internet!</value>
</data>
<data name="Warning.Nominatim.Msg" xml:space="preserve"> <data name="Warning.Nominatim.Msg" xml:space="preserve">
<value>L'indirizzo non può essere risolto invocando il servizio Nominatim. Si prega di digitare la via e CAP/città.</value> <value>L'indirizzo non può essere risolto invocando il servizio Nominatim. Si prega di digitare la via e CAP/città.</value>
</data> </data>

+ 9
- 0
Shared/ResourceFiles/Resources.resx 查看文件

<data name="Error.PhotoOrPictureToBig.Title" xml:space="preserve"> <data name="Error.PhotoOrPictureToBig.Title" xml:space="preserve">
<value>Size of picture to big!</value> <value>Size of picture to big!</value>
</data> </data>
<data name="Extras" xml:space="preserve">
<value>Extras</value>
</data>
<data name="Female" xml:space="preserve"> <data name="Female" xml:space="preserve">
<value>Madam</value> <value>Madam</value>
</data> </data>
<data name="Warning.Masterdata.Title" xml:space="preserve"> <data name="Warning.Masterdata.Title" xml:space="preserve">
<value>Master data not available!</value> <value>Master data not available!</value>
</data> </data>
<data name="Warning.NoConnection.Msg" xml:space="preserve">
<value>The report could not be transmitted. It was stored and will be transmitted as soon as possible!</value>
</data>
<data name="Warning.NoConnection.Title" xml:space="preserve">
<value>No connection to the internet!</value>
</data>
<data name="Warning.Nominatim.Msg" xml:space="preserve"> <data name="Warning.Nominatim.Msg" xml:space="preserve">
<value>The address could not be resolved invoking Nominatim service. Please type in the address street and zip/town.</value> <value>The address could not be resolved invoking Nominatim service. Please type in the address street and zip/town.</value>
</data> </data>

+ 18
- 13
Shared/Services/BicycleRestService.cs 查看文件

using cwebplusApp.Shared.Models; using cwebplusApp.Shared.Models;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
private static readonly string VERSION = "v1"; private static readonly string VERSION = "v1";
private HttpClient httpClient; private HttpClient httpClient;
[Inject]
public IConfiguration Configuration { get; set; } public IConfiguration Configuration { get; set; }
public OnlineStatusProvider OnlineStatusProvider { get; set; }
public void Initialize(IConfiguration configuration) {
public void Initialize(IConfiguration configuration, OnlineStatusProvider onlineStatusProvider) {
this.Configuration = configuration; this.Configuration = configuration;
this.OnlineStatusProvider = onlineStatusProvider;
string hostBaseUrl = Configuration.GetValue<string>("host_base_url"); string hostBaseUrl = Configuration.GetValue<string>("host_base_url");
if (!String.IsNullOrEmpty(hostBaseUrl)) { if (!String.IsNullOrEmpty(hostBaseUrl)) {
this.httpClient = new HttpClient { BaseAddress = new Uri(hostBaseUrl) }; this.httpClient = new HttpClient { BaseAddress = new Uri(hostBaseUrl) };
} }
protected async Task<ReportResponse> SendReport(Report report, string subResourceUrl) { protected async Task<ReportResponse> SendReport(Report report, string subResourceUrl) {
if (httpClient != null) {
if (!String.IsNullOrEmpty(subResourceUrl)) {
string reportJson = JsonConvert.SerializeObject(report);
HttpContent content = new StringContent(reportJson, Encoding.UTF8, "application/json");
HttpResponseMessage httpResult = await httpClient.PostAsync(string.Format(subResourceUrl, VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName), content);
string msg = await httpResult.Content.ReadAsStringAsync();
ReportResponse response = JsonConvert.DeserializeObject<ReportResponse>(msg);
response.StatusCode = httpResult.StatusCode;
return response;
if (OnlineStatusProvider.Online) {
if (httpClient != null) {
if (!String.IsNullOrEmpty(subResourceUrl)) {
string reportJson = JsonConvert.SerializeObject(report);
HttpContent content = new StringContent(reportJson, Encoding.UTF8, "application/json");
HttpResponseMessage httpResult = await httpClient.PostAsync(string.Format(subResourceUrl, VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName), content);
string msg = await httpResult.Content.ReadAsStringAsync();
ReportResponse response = JsonConvert.DeserializeObject<ReportResponse>(msg);
response.StatusCode = httpResult.StatusCode;
return response;
}
} }
throw new HttpRequestException("HTTP client not initialized!");
} else {
//TODO: Save to app storage
return null;
} }
throw new HttpRequestException("HTTP client not initialized!");
} }
} }
} }

+ 1
- 1
Shared/Services/IBicycleRestService.cs 查看文件

namespace cwebplusApp.Shared.Services { namespace cwebplusApp.Shared.Services {
public interface IBicycleRestService { public interface IBicycleRestService {
void Initialize(IConfiguration configuration);
void Initialize(IConfiguration configuration, OnlineStatusProvider onlineStatusProvider);
Task<List<ColorItem>> GetColors(); Task<List<ColorItem>> GetColors();

二进制
wwwroot/images/warning.png 查看文件


+ 20
- 63
wwwroot/service-worker.js 查看文件

'images/caritas_logo.png', 'images/caritas_logo.png',
'images/integrate_logo.png', 'images/integrate_logo.png',
'images/done.png', 'images/done.png',
'images/failure.png',
'images/warning.png',
'images/icon_camera.png', 'images/icon_camera.png',
'images/icon_driveupload.png', 'images/icon_driveupload.png',
'images/icon_location.png', 'images/icon_location.png',
}); });
// fetch events (appsettings are always first fetched from network) // fetch events (appsettings are always first fetched from network)
self.addEventListener('fetch', event => {
if (event.request.url.endsWith(appsettings_url)) {
fetch(event.request).then(function (response) {
return caches.open(staticCacheName).then(function (cache) {
console.log('update cache');
cache.put(event.request, response.clone());
return response;
});
}).catch(function () {
var cr;
console.log('catch network fetch failure 1');
event.waitUntil(
caches.match(event.request).then(cacheRes => {
console.log('catch network fetch failure 2');
console.log(cacheRes);
cr = cacheRes;
})
);
console.log('catch network fetch failure 3');
console.log(cr);
return cr;
//fromCache(event.request);
})
} else {
event.respondWith(
caches.match(event.request).then(cacheRes => {
return cacheRes || fetch(event.request);
})
);
}
});
//self.addEventListener('fetch', event => {
// if (event.request.url.endsWith(appsettings_url)) {
// networkOrCache(event.request);
// } else {
// event.respondWith(
// caches.match(event.request).then(cacheRes => {
// return cacheRes || fetch(event.request);
// })
// );
// }
//});
self.addEventListener('fetch', function (event) {
event.respondWith(networkOrCache(event.request).catch(function () {
}));
})
//function networkOrCache(request) {
// return fetch(request).then(function (response) {
// caches.open(staticCacheName).then(function (cache) {
// console.log('update cache');
// cache.put(request, response.clone());
// });
// return response.ok ? response : fromCache(request);
// //}).catch(function () {
// // return fromCache(request);
// });
//}
function networkOrCache(request) {
return fetch(request).then(function (response) {
return response.ok ? response : fromCache(request);
}).catch(function () {
return fromCache(request);
});
}
//function fromCache(request) {
// return caches.open(staticCacheName).then(function (cache) {
// return cache.match(request).then(function (matching) {
// return matching || Promise.reject('request-not-in-cache');
// });
// });
//}
function fromCache(request) {
return caches.open(staticCacheName).then(function (cache) {
return cache.match(request).then(function (matching) {
return matching || Promise.reject('request-not-in-cache');
});
});
}

正在加载...
取消
保存