forked from soybeanjs/soybean-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
66 lines (53 loc) · 1.53 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { h } from 'vue';
import { NButton } from 'naive-ui';
import { $t } from '../locales';
export function setupAppVersionNotification() {
let isShow = false;
document.addEventListener('visibilitychange', async () => {
const preConditions = [!isShow, document.visibilityState === 'visible', !import.meta.env.DEV];
if (!preConditions.every(Boolean)) return;
const buildTime = await getHtmlBuildTime();
if (buildTime === BUILD_TIME) {
return;
}
isShow = true;
const n = window.$notification?.create({
title: $t('system.updateTitle'),
content: $t('system.updateContent'),
action() {
return h('div', { style: { display: 'flex', justifyContent: 'end', gap: '12px', width: '325px' } }, [
h(
NButton,
{
onClick() {
n?.destroy();
}
},
() => $t('system.updateCancel')
),
h(
NButton,
{
type: 'primary',
onClick() {
location.reload();
}
},
() => $t('system.updateConfirm')
)
]);
},
onClose() {
isShow = false;
}
});
});
}
async function getHtmlBuildTime() {
const baseURL = import.meta.env.VITE_BASE_URL;
const res = await fetch(`${baseURL}index.html`);
const html = await res.text();
const match = html.match(/<meta name="buildTime" content="(.*)">/);
const buildTime = match?.[1] || '';
return buildTime;
}