|
@@ -1,5 +1,6 @@
|
|
|
import { cloneDeep } from 'lodash';
|
|
|
import { useUserStore } from '@/store';
|
|
|
+import { DialogPlugin } from 'tdesign-vue-next';
|
|
|
|
|
|
export const extractFileName = (str) => {
|
|
|
if (/filename=([^;\s]*)/gi.test(str)) {
|
|
@@ -513,3 +514,38 @@ export function isEqual(objA, objB) {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+export const appUpdateObserver = () => {
|
|
|
+ window.addEventListener(
|
|
|
+ 'error',
|
|
|
+ (e) => {
|
|
|
+ if (e.target.localName === 'script' || e.target.localName === 'link') {
|
|
|
+ DialogPlugin({
|
|
|
+ header: '提示',
|
|
|
+ body: `检测到系统功能已升级,点击"确定"自动刷新获取更新`,
|
|
|
+ confirmBtn: '确定',
|
|
|
+ cancelBtn: null,
|
|
|
+ onConfirm: async () => {
|
|
|
+ if ('caches' in window) {
|
|
|
+ caches
|
|
|
+ .keys()
|
|
|
+ .then((cacheNames) => {
|
|
|
+ const arr = cacheNames.map((cacheName) => {
|
|
|
+ return caches.delete(cacheName);
|
|
|
+ });
|
|
|
+ return arr;
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ location.reload();
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ location.reload();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ e.preventDefault();
|
|
|
+ },
|
|
|
+ true
|
|
|
+ );
|
|
|
+};
|