vue2server7 7.0.100 → 7.0.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/test/111 +39 -0
package/package.json
CHANGED
package/test/111
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/utils/configWatcher.js
|
|
2
|
+
|
|
3
|
+
const CONFIG_VERSION_KEY = 'APP_CONFIG_VERSION'
|
|
4
|
+
|
|
5
|
+
function getConfigVersionFromText(text) {
|
|
6
|
+
const match = text.match(/VERSION:\s*['"](.+?)['"]/)
|
|
7
|
+
return match?.[1]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function startConfigWatcher(interval = 10000) {
|
|
11
|
+
setInterval(async () => {
|
|
12
|
+
try {
|
|
13
|
+
const res = await fetch(`/config.js?t=${Date.now()}`, {
|
|
14
|
+
cache: 'no-store'
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const text = await res.text()
|
|
18
|
+
const latestVersion = getConfigVersionFromText(text)
|
|
19
|
+
|
|
20
|
+
if (!latestVersion) return
|
|
21
|
+
|
|
22
|
+
const localVersion = localStorage.getItem(CONFIG_VERSION_KEY)
|
|
23
|
+
|
|
24
|
+
// 第一次没有版本号,先存起来
|
|
25
|
+
if (!localVersion) {
|
|
26
|
+
localStorage.setItem(CONFIG_VERSION_KEY, latestVersion)
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 版本不一致,更新本地版本并刷新页面
|
|
31
|
+
if (latestVersion !== localVersion) {
|
|
32
|
+
localStorage.setItem(CONFIG_VERSION_KEY, latestVersion)
|
|
33
|
+
window.location.reload()
|
|
34
|
+
}
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.error('配置版本检查失败:', err)
|
|
37
|
+
}
|
|
38
|
+
}, interval)
|
|
39
|
+
}
|