vue2server7 7.0.102 → 7.0.104

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/11231231 +137 -0
  3. package/test/1312312 +164 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue2server7",
3
- "version": "7.0.102",
3
+ "version": "7.0.104",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "dev": "nodemon --watch src --ext ts --exec \"ts-node src/app.ts\"",
package/test/11231231 ADDED
@@ -0,0 +1,137 @@
1
+ <template>
2
+ <el-dialog
3
+ v-model="visible"
4
+ title="切换机构"
5
+ width="420px"
6
+ :close-on-click-modal="false"
7
+ >
8
+ <el-form label-width="80px">
9
+ <el-form-item label="机构">
10
+ <el-select
11
+ v-model="selectedOrgId"
12
+ placeholder="请选择机构"
13
+ style="width: 100%"
14
+ filterable
15
+ >
16
+ <el-option
17
+ v-for="item in orgList"
18
+ :key="item.id"
19
+ :label="item.name"
20
+ :value="item.id"
21
+ />
22
+ </el-select>
23
+ </el-form-item>
24
+ </el-form>
25
+
26
+ <template #footer>
27
+ <el-button @click="handleCancel">取消</el-button>
28
+ <el-button type="primary" @click="handleConfirm">
29
+ 确定切换
30
+ </el-button>
31
+ </template>
32
+ </el-dialog>
33
+ </template>
34
+
35
+ <script setup>
36
+ import { ref, watch } from 'vue'
37
+ import { ElMessage } from 'element-plus'
38
+
39
+ const props = defineProps({
40
+ modelValue: {
41
+ type: Boolean,
42
+ default: false
43
+ },
44
+ orgList: {
45
+ type: Array,
46
+ default: () => []
47
+ },
48
+ currentOrgId: {
49
+ type: [String, Number],
50
+ default: ''
51
+ }
52
+ })
53
+
54
+ const emit = defineEmits([
55
+ 'update:modelValue',
56
+ 'confirm'
57
+ ])
58
+
59
+ const visible = ref(false)
60
+ const selectedOrgId = ref('')
61
+
62
+ watch(
63
+ () => props.modelValue,
64
+ val => {
65
+ visible.value = val
66
+ if (val) {
67
+ selectedOrgId.value = props.currentOrgId
68
+ }
69
+ }
70
+ )
71
+
72
+ watch(visible, val => {
73
+ emit('update:modelValue', val)
74
+ })
75
+
76
+ const handleCancel = () => {
77
+ visible.value = false
78
+ }
79
+
80
+ const handleConfirm = () => {
81
+ if (!selectedOrgId.value) {
82
+ ElMessage.warning('请选择机构')
83
+ return
84
+ }
85
+
86
+ emit('confirm', selectedOrgId.value)
87
+ visible.value = false
88
+ }
89
+ </script>
90
+ 、、、<template>
91
+ <el-button type="primary" @click="showOrgDialog = true">
92
+ 切换机构
93
+ </el-button>
94
+
95
+ <OrgSwitchDialog
96
+ v-model="showOrgDialog"
97
+ :org-list="orgList"
98
+ :current-org-id="currentOrgId"
99
+ @confirm="handleSwitchOrg"
100
+ />
101
+ </template>
102
+
103
+ <script setup>
104
+ import { ref } from 'vue'
105
+ import { ElMessage } from 'element-plus'
106
+ import OrgSwitchDialog from '@/components/OrgSwitchDialog.vue'
107
+
108
+ const showOrgDialog = ref(false)
109
+
110
+ const currentOrgId = ref(1)
111
+
112
+ const orgList = ref([
113
+ {
114
+ id: 1,
115
+ name: '总部机构'
116
+ },
117
+ {
118
+ id: 2,
119
+ name: '上海分公司'
120
+ },
121
+ {
122
+ id: 3,
123
+ name: '北京分公司'
124
+ }
125
+ ])
126
+
127
+ const handleSwitchOrg = orgId => {
128
+ currentOrgId.value = orgId
129
+
130
+ const org = orgList.value.find(item => item.id === orgId)
131
+
132
+ ElMessage.success(`已切换到:${org?.name || ''}`)
133
+
134
+ // 这里可以调用接口
135
+ // await switchOrgApi(orgId)
136
+ }
137
+ </script>
package/test/1312312 ADDED
@@ -0,0 +1,164 @@
1
+ type WorkerMessage =
2
+ | {
3
+ type: 'START'
4
+ interval?: number
5
+ }
6
+ | {
7
+ type: 'CHECK_NOW'
8
+ }
9
+ | {
10
+ type: 'STOP'
11
+ }
12
+
13
+ type WorkerResponse =
14
+ | {
15
+ type: 'CONFIG_VERSION'
16
+ version: string
17
+ }
18
+ | {
19
+ type: 'CONFIG_ERROR'
20
+ message: string
21
+ }
22
+
23
+ let timer: ReturnType<typeof setInterval> | null = null
24
+
25
+ function getVersion(text: string): string | null {
26
+ const match = text.match(/VERSION:\s*['"](.+?)['"]/)
27
+ return match?.[1] || null
28
+ }
29
+
30
+ async function checkConfig(): Promise<void> {
31
+ try {
32
+ const res = await fetch(`/config.js?t=${Date.now()}`, {
33
+ cache: 'no-store'
34
+ })
35
+
36
+ const text = await res.text()
37
+ const latestVersion = getVersion(text)
38
+
39
+ if (!latestVersion) return
40
+
41
+ const message: WorkerResponse = {
42
+ type: 'CONFIG_VERSION',
43
+ version: latestVersion
44
+ }
45
+
46
+ self.postMessage(message)
47
+ } catch (err) {
48
+ const message: WorkerResponse = {
49
+ type: 'CONFIG_ERROR',
50
+ message: err instanceof Error ? err.message : '配置检查失败'
51
+ }
52
+
53
+ self.postMessage(message)
54
+ }
55
+ }
56
+
57
+ self.onmessage = (event: MessageEvent<WorkerMessage>) => {
58
+ const data = event.data
59
+
60
+ if (data.type === 'START') {
61
+ if (timer) return
62
+
63
+ checkConfig()
64
+
65
+ timer = setInterval(() => {
66
+ checkConfig()
67
+ }, data.interval || 10000)
68
+ }
69
+
70
+ if (data.type === 'CHECK_NOW') {
71
+ checkConfig()
72
+ }
73
+
74
+ if (data.type === 'STOP') {
75
+ if (timer) {
76
+ clearInterval(timer)
77
+ timer = null
78
+ }
79
+ }
80
+ }
81
+
82
+ export {}
83
+
84
+
85
+
86
+ type WorkerResponse =
87
+ | {
88
+ type: 'CONFIG_VERSION'
89
+ version: string
90
+ }
91
+ | {
92
+ type: 'CONFIG_ERROR'
93
+ message: string
94
+ }
95
+
96
+ const CONFIG_VERSION_KEY = 'APP_CONFIG_VERSION'
97
+
98
+ let worker: Worker | null = null
99
+
100
+ function handleVersionChange(version: string): void {
101
+ const localVersion = localStorage.getItem(CONFIG_VERSION_KEY)
102
+
103
+ if (!localVersion) {
104
+ localStorage.setItem(CONFIG_VERSION_KEY, version)
105
+ return
106
+ }
107
+
108
+ if (version !== localVersion) {
109
+ localStorage.setItem(CONFIG_VERSION_KEY, version)
110
+ window.location.reload()
111
+ }
112
+ }
113
+
114
+ export function startConfigWatcher(interval = 10000): void {
115
+ if (worker) return
116
+
117
+ worker = new Worker(new URL('../workers/config.worker.ts', import.meta.url), {
118
+ type: 'module'
119
+ })
120
+
121
+ worker.postMessage({
122
+ type: 'START',
123
+ interval
124
+ })
125
+
126
+ worker.onmessage = (event: MessageEvent<WorkerResponse>) => {
127
+ const data = event.data
128
+
129
+ if (data.type === 'CONFIG_VERSION') {
130
+ handleVersionChange(data.version)
131
+ }
132
+
133
+ if (data.type === 'CONFIG_ERROR') {
134
+ console.error('配置版本检查失败:', data.message)
135
+ }
136
+ }
137
+
138
+ document.addEventListener('visibilitychange', () => {
139
+ if (!document.hidden) {
140
+ worker?.postMessage({
141
+ type: 'CHECK_NOW'
142
+ })
143
+ }
144
+ })
145
+
146
+ window.addEventListener('focus', () => {
147
+ worker?.postMessage({
148
+ type: 'CHECK_NOW'
149
+ })
150
+ })
151
+ }
152
+
153
+ export function stopConfigWatcher(): void {
154
+ if (!worker) return
155
+
156
+ worker.postMessage({
157
+ type: 'STOP'
158
+ })
159
+
160
+ worker.terminate()
161
+ worker = null
162
+ }
163
+
164
+