vue2server7 7.0.101 → 7.0.102
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/1112 +69 -0
package/package.json
CHANGED
package/test/1112
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// public/config-worker.js
|
|
2
|
+
|
|
3
|
+
let timer = null
|
|
4
|
+
const KEY = 'APP_CONFIG_VERSION'
|
|
5
|
+
|
|
6
|
+
function getVersion(text) {
|
|
7
|
+
const match = text.match(/VERSION:\s*['"](.+?)['"]/)
|
|
8
|
+
return match?.[1]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function checkConfig() {
|
|
12
|
+
const res = await fetch(`/config.js?t=${Date.now()}`, {
|
|
13
|
+
cache: 'no-store'
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const text = await res.text()
|
|
17
|
+
const latestVersion = getVersion(text)
|
|
18
|
+
|
|
19
|
+
if (!latestVersion) return
|
|
20
|
+
|
|
21
|
+
postMessage({
|
|
22
|
+
type: 'CONFIG_VERSION',
|
|
23
|
+
version: latestVersion
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
self.onmessage = (event) => {
|
|
28
|
+
if (event.data?.type === 'START') {
|
|
29
|
+
if (timer) return
|
|
30
|
+
|
|
31
|
+
checkConfig()
|
|
32
|
+
|
|
33
|
+
timer = setInterval(() => {
|
|
34
|
+
checkConfig()
|
|
35
|
+
}, event.data.interval || 10000)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
// src/utils/configWatcher.js
|
|
41
|
+
|
|
42
|
+
const KEY = 'APP_CONFIG_VERSION'
|
|
43
|
+
|
|
44
|
+
export function startConfigWatcher() {
|
|
45
|
+
const worker = new Worker('/config-worker.js')
|
|
46
|
+
|
|
47
|
+
worker.postMessage({
|
|
48
|
+
type: 'START',
|
|
49
|
+
interval: 10000
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
worker.onmessage = (event) => {
|
|
53
|
+
const { type, version } = event.data || {}
|
|
54
|
+
|
|
55
|
+
if (type !== 'CONFIG_VERSION' || !version) return
|
|
56
|
+
|
|
57
|
+
const localVersion = localStorage.getItem(KEY)
|
|
58
|
+
|
|
59
|
+
if (!localVersion) {
|
|
60
|
+
localStorage.setItem(KEY, version)
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (version !== localVersion) {
|
|
65
|
+
localStorage.setItem(KEY, version)
|
|
66
|
+
window.location.reload()
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|