mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat(projects): support system new version update notification. close #420
This commit is contained in:
53
src/plugins/app.ts
Normal file
53
src/plugins/app.ts
Normal file
@ -0,0 +1,53 @@
|
||||
import { h } from 'vue';
|
||||
import { NButton } from 'naive-ui';
|
||||
import { $t } from '../locales';
|
||||
|
||||
export function setupAppVersionNotification() {
|
||||
document.addEventListener('visibilitychange', async () => {
|
||||
const buildTime = await getHtmlBuildTime();
|
||||
|
||||
if (buildTime !== BUILD_TIME && document.visibilityState === 'visible') {
|
||||
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')
|
||||
)
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
Reference in New Issue
Block a user