Skip to content

Commit bea8d1a

Browse files
committed
feat: 恢复数据后清除 PWA 缓存
1 parent 20acf76 commit bea8d1a

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store-front-end",
3-
"version": "2.15.73",
3+
"version": "2.15.74",
44
"private": true,
55
"scripts": {
66
"dev": "vite --host",

src/views/My.vue

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,23 @@ const fileChange = async (event) => {
463463
type: "success",
464464
title: t(`myPage.notify.restore.succeed`),
465465
});
466-
window.location.reload()
466+
467+
if ("serviceWorker" in navigator) {
468+
const registrations = await navigator.serviceWorker.getRegistrations();
469+
for (let registration of registrations) {
470+
await registration.unregister();
471+
}
472+
}
473+
if ("caches" in window) {
474+
const cacheNames = await caches.keys();
475+
for (let cacheName of cacheNames) {
476+
await caches.delete(cacheName);
477+
}
478+
}
479+
480+
setTimeout(() => {
481+
window.location.reload();
482+
}, 1000);
467483
} else {
468484
throw new Error('restore failed')
469485
}
@@ -517,7 +533,22 @@ const sync = async (query: "download" | "upload", options?: { keep?: string[], e
517533
title: t(`myPage.notify.${query}.succeed`),
518534
});
519535
if (query === "download") {
520-
window.location.reload()
536+
if ("serviceWorker" in navigator) {
537+
const registrations = await navigator.serviceWorker.getRegistrations();
538+
for (let registration of registrations) {
539+
await registration.unregister();
540+
}
541+
}
542+
if ("caches" in window) {
543+
const cacheNames = await caches.keys();
544+
for (let cacheName of cacheNames) {
545+
await caches.delete(cacheName);
546+
}
547+
}
548+
549+
setTimeout(() => {
550+
window.location.reload();
551+
}, 1000);
521552
}
522553
}
523554

0 commit comments

Comments
 (0)