vue2server7 7.0.100 → 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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/test/111 +39 -0
  3. package/test/1112 +69 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue2server7",
3
- "version": "7.0.100",
3
+ "version": "7.0.102",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "dev": "nodemon --watch src --ext ts --exec \"ts-node src/app.ts\"",
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
+ }
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
+ }