feat(web-admin): force a refresh when a newer build is deployed.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
a1c00847e5
commit
020fbe1b0e
4 files changed
+61
-2
No files matched your search
Vendored
+1
@@ -63,3 +63,4 @@ declare module 'qrcode.vue' {
|
||||
|
||||
// 全局变量声明
|
||||
declare const __APP_VERSION__: string // 版本号
|
||||
declare const __APP_BUILD_ID__: string // 构建指纹:短 git hash + 构建时间戳
|
||||
@@ -16,6 +16,7 @@ import '@styles/index.scss' // 样式
|
||||
import '@utils/sys/console.ts' // 控制台输出内容
|
||||
import { setupGlobDirectives } from './directives'
|
||||
import { setupErrorHandle } from './utils/sys/error-handle'
|
||||
import { startAppUpdateCheck } from './utils/check-app-update'
|
||||
|
||||
function maskSecret(value?: string) {
|
||||
if (!value) return '(empty)'
|
||||
@@ -62,4 +63,5 @@ setupGlobDirectives(app)
|
||||
setupErrorHandle(app)
|
||||
|
||||
app.use(language)
|
||||
app.mount('#app')
|
||||
app.mount('#app')
|
||||
startAppUpdateCheck()
|
||||
@@ -0,0 +1,40 @@
|
||||
// web-admin/src/utils/check-app-update.ts
|
||||
import { startAppUpdateChecker } from './app-update'
|
||||
|
||||
/** 生产环境检查 dist/version.json,发现新 buildId 后强制刷新。 */
|
||||
export function startAppUpdateCheck(): () => void {
|
||||
return startAppUpdateChecker({
|
||||
isProd: import.meta.env.PROD,
|
||||
localBuildId: __APP_BUILD_ID__,
|
||||
localVersion: __APP_VERSION__,
|
||||
baseUrl: import.meta.env.BASE_URL,
|
||||
now: () => Date.now(),
|
||||
fetchRemote: async (url) => {
|
||||
const res = await fetch(url, { cache: 'no-store' })
|
||||
if (!res.ok) throw new Error(String(res.status))
|
||||
return res.json()
|
||||
},
|
||||
onReload: () => {
|
||||
location.reload()
|
||||
},
|
||||
alertUpdate: async (message) => {
|
||||
await ElMessageBox.alert(message, '发现新版本', {
|
||||
confirmButtonText: '立即刷新',
|
||||
showClose: false,
|
||||
closeOnClickModal: false,
|
||||
closeOnPressEscape: false,
|
||||
showCancelButton: false,
|
||||
dangerouslyUseHTMLString: true
|
||||
})
|
||||
},
|
||||
setInterval: (fn, ms) => window.setInterval(fn, ms),
|
||||
clearInterval: (id) => window.clearInterval(id),
|
||||
subscribeVisible: (handler) => {
|
||||
const listener = () => {
|
||||
if (document.visibilityState === 'visible') handler()
|
||||
}
|
||||
document.addEventListener('visibilitychange', listener)
|
||||
return () => document.removeEventListener('visibilitychange', listener)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user