af-mobile-client-vue3 1.3.51 → 1.3.53

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.
@@ -18,7 +18,7 @@ const showModifyPassword = ref(false)
18
18
  // 退出登录确认弹窗显示状态
19
19
  const showLogoutConfirm = ref(false)
20
20
  // 在setup函数中
21
- let intervalId = null
21
+ let intervalId: number | null = null
22
22
 
23
23
  // 定义一个变量来存储上一次的上传结果
24
24
  const lastUploadResult = ref(null)
@@ -51,102 +51,73 @@ interface UploadResult {
51
51
  }
52
52
 
53
53
  // 兼容 lastUploadResult 可能为字符串或对象
54
- const lastUploadResultObj = computed<UploadResult | null>(() => {
55
- if (!lastUploadResult.value)
56
- return null
57
- if (typeof lastUploadResult.value === 'string') {
58
- try {
59
- return JSON.parse(lastUploadResult.value)
60
- }
61
- catch {
62
- return null
63
- }
64
- }
65
- return lastUploadResult.value
66
- })
54
+ interface LocationStatusTag { text: string, color: 'red' | 'green' | 'yellow' }
55
+ interface LocationStatusInfo { uploadTime: string, latitude: number, longitude: number }
67
56
 
68
- const uploadDisplayInfo = computed(() => {
69
- const result = lastUploadResultObj.value
70
- if (!result)
71
- return { error: null, info: null }
72
- // response.code 不为 200
73
- if (result.response && result.response.code !== 200) {
74
- return { error: result.response.msg || '未知错误', info: null }
57
+ const locationStatus = computed(() => {
58
+ console.warn('上次定位信息:', lastUploadResult.value)
59
+ if (lastUploadResult.value === null) {
60
+ return { error: null, statusTag: { text: '正在获取上次上传定位信息', color: 'yellow' } }
61
+ }
62
+ if (lastUploadResult.value.status === 'error') {
63
+ console.warn('上次定位信息解析失败:', lastUploadResult.value)
64
+ return { error: null, statusTag: { text: lastUploadResult.value.msg, color: 'yellow' } }
75
65
  }
76
66
 
77
- // location.errorCode 存在且 isError 为 true
78
- if (result.location && result.location.isError && result.location.errorCode) {
79
- return { error: result.location.errorCode, info: null }
67
+ if (lastUploadResult.value.data.location && lastUploadResult.value.data.location.isError) {
68
+ const error = lastUploadResult.value.data.location.errorCode
69
+ return { error, info: null, statusTag: { text: '获取定位失败', color: 'red' } }
80
70
  }
81
71
 
82
- // 正常展示
83
- if (result.location) {
84
- return {
85
- error: null,
86
- info: {
87
- uploadTime: result.uploadTime,
88
- latitude: result.location.f_latitude,
89
- longitude: result.location.f_longitude,
90
- },
72
+ if (lastUploadResult.value.data.location) {
73
+ const info: LocationStatusInfo = {
74
+ uploadTime: lastUploadResult.value.data.uploadTime,
75
+ latitude: lastUploadResult.value.data.location.f_latitude,
76
+ longitude: lastUploadResult.value.data.location.f_longitude,
91
77
  }
78
+ return { error: null, info, statusTag: { text: '正在上传定位', color: 'green' } }
92
79
  }
93
80
 
94
- return { error: null, info: null }
81
+ return { error: null, info: null, statusTag: null }
95
82
  })
96
83
 
97
- const uploadStatusTag = computed(() => {
98
- const result = uploadDisplayInfo.value
99
- if (result.error) {
100
- return { text: '上传定位失败', color: 'red' }
84
+ // 安全获取上次实时上传结果(封装 try/catch,避免初始化失败)
85
+ function fetchLastRealtimeUploadResult(): void {
86
+ try {
87
+ mobileUtil.execute({
88
+ param: {},
89
+ funcName: 'getLastRealtimeUploadResult',
90
+ callbackFunc: (res: PhoneLocationStatus) => {
91
+ try {
92
+ console.warn('获取到的上次定位信息:', res)
93
+ if (res && res.status === 'success') {
94
+ lastUploadResult.value = res
95
+ }
96
+ else {
97
+ // 失败也不抛错,保留可能的返回内容用于显示错误状态
98
+ lastUploadResult.value = res ?? null
99
+ }
100
+ }
101
+ catch (err) {
102
+ console.error('处理定位回调异常:', err)
103
+ }
104
+ },
105
+ })
101
106
  }
102
- if (result.info) {
103
- return { text: '正在上传定位', color: 'green' }
107
+ catch (err) {
108
+ console.error('获取定位信息异常:', err)
104
109
  }
105
- return null
106
- })
110
+ }
107
111
 
108
112
  onMounted(() => {
109
113
  if (roleName?.includes('需要定位人员')) {
110
- try {
111
- mobileUtil.execute({
112
- param: {},
113
- funcName: 'getLastRealtimeUploadResult',
114
- callbackFunc: (result: PhoneLocationStatus) => {
115
- try {
116
- if (result.status === 'success') {
117
- lastUploadResult.value = result.data
118
-
119
- // 首次成功才启动定时器
120
- intervalId = setInterval(() => {
121
- try {
122
- mobileUtil.execute({
123
- param: {},
124
- funcName: 'getLastRealtimeUploadResult',
125
- callbackFunc: (res: PhoneLocationStatus) => {
126
- if (res.status === 'success') {
127
- lastUploadResult.value = res.data
128
- }
129
- },
130
- })
131
- }
132
- catch (err) {
133
- console.error('定时获取定位信息异常:', err)
134
- }
135
- }, 10000)
136
- }
137
- else {
138
- console.warn('首次定位获取失败,不启动定时器:', result)
139
- }
140
- }
141
- catch (err) {
142
- console.error('处理首次定位结果异常:', err)
143
- }
144
- },
145
- })
146
- }
147
- catch (err) {
148
- console.error('首次获取定位信息异常:', err)
149
- }
114
+ // 立即尝试获取一次(失败也不会阻断初始化)
115
+ fetchLastRealtimeUploadResult()
116
+
117
+ // 无论首次结果如何,都启动定时器持续获取
118
+ intervalId = window.setInterval(() => {
119
+ fetchLastRealtimeUploadResult()
120
+ }, 10000)
150
121
  }
151
122
  })
152
123
 
@@ -208,10 +179,10 @@ const webMobileConfig = useSettingStore().getSetting()
208
179
  <h2 class="username">
209
180
  {{ username }}
210
181
  <span
211
- v-if="uploadStatusTag"
212
- class="upload-status-tag" :class="[uploadStatusTag.color]"
182
+ v-if="locationStatus.statusTag"
183
+ class="upload-status-tag" :class="[locationStatus.statusTag.color]"
213
184
  >
214
- {{ uploadStatusTag.text }}
185
+ {{ locationStatus.statusTag.text }}
215
186
  </span>
216
187
  </h2>
217
188
  <p class="user-role">
@@ -403,6 +374,11 @@ const webMobileConfig = useSettingStore().getSetting()
403
374
  background: #fdeaea;
404
375
  border: 1px solid #ef4444;
405
376
  }
377
+ &.yellow {
378
+ color: #f59e0b;
379
+ background: #fffbeb;
380
+ border: 1px solid #f59e0b;
381
+ }
406
382
  }
407
383
 
408
384
  .user-role {
@@ -313,7 +313,7 @@ async function submitRegistration(): Promise<void> {
313
313
  if (response.success) {
314
314
  showSuccess.value = true
315
315
  showSuccessToast('注册成功')
316
- }
316
+ }
317
317
  else {
318
318
  showSuccessToast(`注册失败,${response.msg}!`)
319
319
  }
package/vite.config.ts CHANGED
@@ -1,114 +1,114 @@
1
- import type { ConfigEnv, UserConfig } from 'vite'
2
- import path from 'node:path'
3
- import process from 'node:process'
4
- import { loadEnv } from 'vite'
5
- import { createVitePlugins } from './build/vite'
6
- import { exclude, include } from './build/vite/optimize'
7
-
8
- export default ({ mode }: ConfigEnv): UserConfig => {
9
- const root = process.cwd()
10
- const env = loadEnv(mode, root)
11
-
12
- const appProxys = {}
13
-
14
- const v4Server = 'http://192.168.50.67:31567'
15
- const v3Server = 'http://192.168.50.67:31567'
16
- const OSSServerDev = 'http://192.168.50.67:30351'
17
- const geoserver = 'http://39.104.49.8:30372'
18
- const mockServer = 'http://127.0.0.1:8086'
19
- // const OSSServerProd = 'http://192.168.50.67:31351'
20
-
21
- return {
22
- base: env.VITE_APP_PUBLIC_PATH,
23
- plugins: createVitePlugins(mode),
24
-
25
- server: {
26
- host: true,
27
- port: 7190,
28
- allowedHosts: [
29
- 'www.aofengcloud.com',
30
- '.aofengcloud.com',
31
- ],
32
- proxy: Object.assign({
33
- '/api/af-system/user': {
34
- target: 'http://127.0.0.1:9002/',
35
- rewrite: (path: string) => path.replace(/^\/api\/af-system\//, '/'),
36
- ws: false,
37
- changeOrigin: true,
38
- },
39
- '/api/invoice': {
40
- target: 'http://219.153.176.6:8400/',
41
- rewrite: (path: string) => path.replace(/^\/api\//, '/'),
42
- ws: false,
43
- changeOrigin: true,
44
- },
45
- '/api/af-system/entity/t_files': {
46
- target: v3Server,
47
- ws: false,
48
- changeOrigin: true,
49
- },
50
- '/resource': {
51
- // pathRewrite: { '^/resource': '/' },
52
- target: v4Server,
53
- changeOrigin: true,
54
- },
55
- // '/api/af-auth/login': {
56
- // target: 'http://127.0.0.1:9200/',
57
- // rewrite: (path: string) => path.replace(/^\/api\/af-auth\//, '/'),
58
- // ws: false,
59
- // changeOrigin: true,
60
- // },
61
- // geoserver 转发
62
- '/linepatrol/geoserver': {
63
- target: geoserver,
64
- changeOrigin: true,
65
- rewrite: path => path.replace(/^\/linepatrol\/geoserver/, '/geoserver'),
66
- },
67
- '/api': {
68
- // v3用
69
- // rewrite: (path: string) => path.replace(/^\/api\/af-system\//, '/rs/'),
70
- target: v4Server,
71
- ws: false,
72
- changeOrigin: true,
73
- },
74
- '/oss': {
75
- target: OSSServerDev,
76
- rewrite: (path: string) => path.replace(/^\/oss\//, '/'),
77
- changeOrigin: true,
78
- },
79
- }, appProxys),
80
- },
81
-
82
- resolve: {
83
- alias: {
84
- '@': path.join(__dirname, './src'),
85
- '~': path.join(__dirname, './src/assets'),
86
- '~root': path.join(__dirname, '.'),
87
- '@af-mobile-client-vue3': path.join(__dirname, './src'),
88
- },
89
- },
90
-
91
- build: {
92
- cssCodeSplit: false,
93
- chunkSizeWarningLimit: 2048,
94
- outDir: `./dist/${env.VITE_APP_OUT_DIR}`,
95
- rollupOptions: {
96
- output: {
97
- // 打包时分割资源
98
- chunkFileNames: 'static/js/[name]-[hash].js',
99
- entryFileNames: 'static/js/[name]-[hash].js',
100
- assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
101
- manualChunks(id) {
102
- if (id.includes('node_modules'))
103
- return 'third' // 代码分割为第三方包
104
-
105
- if (id.includes('views'))
106
- return 'views' // 代码分割为业务视图
107
- },
108
- },
109
- },
110
- },
111
-
112
- optimizeDeps: { include, exclude },
113
- }
114
- }
1
+ import type { ConfigEnv, UserConfig } from 'vite'
2
+ import path from 'node:path'
3
+ import process from 'node:process'
4
+ import { loadEnv } from 'vite'
5
+ import { createVitePlugins } from './build/vite'
6
+ import { exclude, include } from './build/vite/optimize'
7
+
8
+ export default ({ mode }: ConfigEnv): UserConfig => {
9
+ const root = process.cwd()
10
+ const env = loadEnv(mode, root)
11
+
12
+ const appProxys = {}
13
+
14
+ const v4Server = 'http://192.168.50.67:31567'
15
+ const v3Server = 'http://192.168.50.67:31567'
16
+ const OSSServerDev = 'http://192.168.50.67:30351'
17
+ const geoserver = 'http://39.104.49.8:30372'
18
+ const mockServer = 'http://127.0.0.1:8086'
19
+ // const OSSServerProd = 'http://192.168.50.67:31351'
20
+
21
+ return {
22
+ base: env.VITE_APP_PUBLIC_PATH,
23
+ plugins: createVitePlugins(mode),
24
+
25
+ server: {
26
+ host: true,
27
+ port: 80,
28
+ allowedHosts: [
29
+ 'www.aofengcloud.com',
30
+ '.aofengcloud.com',
31
+ ],
32
+ proxy: Object.assign({
33
+ // '/api/af-system/user': {
34
+ // target: 'http://127.0.0.1:9002/',
35
+ // rewrite: (path: string) => path.replace(/^\/api\/af-system\//, '/'),
36
+ // ws: false,
37
+ // changeOrigin: true,
38
+ // },
39
+ '/api/invoice': {
40
+ target: 'http://219.153.176.6:8400/',
41
+ rewrite: (path: string) => path.replace(/^\/api\//, '/'),
42
+ ws: false,
43
+ changeOrigin: true,
44
+ },
45
+ '/api/af-system/entity/t_files': {
46
+ target: v3Server,
47
+ ws: false,
48
+ changeOrigin: true,
49
+ },
50
+ '/resource': {
51
+ // pathRewrite: { '^/resource': '/' },
52
+ target: v4Server,
53
+ changeOrigin: true,
54
+ },
55
+ // '/api/af-auth/login': {
56
+ // target: 'http://127.0.0.1:9200/',
57
+ // rewrite: (path: string) => path.replace(/^\/api\/af-auth\//, '/'),
58
+ // ws: false,
59
+ // changeOrigin: true,
60
+ // },
61
+ // geoserver 转发
62
+ '/linepatrol/geoserver': {
63
+ target: geoserver,
64
+ changeOrigin: true,
65
+ rewrite: path => path.replace(/^\/linepatrol\/geoserver/, '/geoserver'),
66
+ },
67
+ '/api': {
68
+ // v3用
69
+ // rewrite: (path: string) => path.replace(/^\/api\/af-system\//, '/rs/'),
70
+ target: v4Server,
71
+ ws: false,
72
+ changeOrigin: true,
73
+ },
74
+ '/oss': {
75
+ target: OSSServerDev,
76
+ rewrite: (path: string) => path.replace(/^\/oss\//, '/'),
77
+ changeOrigin: true,
78
+ },
79
+ }, appProxys),
80
+ },
81
+
82
+ resolve: {
83
+ alias: {
84
+ '@': path.join(__dirname, './src'),
85
+ '~': path.join(__dirname, './src/assets'),
86
+ '~root': path.join(__dirname, '.'),
87
+ '@af-mobile-client-vue3': path.join(__dirname, './src'),
88
+ },
89
+ },
90
+
91
+ build: {
92
+ cssCodeSplit: false,
93
+ chunkSizeWarningLimit: 2048,
94
+ outDir: `./dist/${env.VITE_APP_OUT_DIR}`,
95
+ rollupOptions: {
96
+ output: {
97
+ // 打包时分割资源
98
+ chunkFileNames: 'static/js/[name]-[hash].js',
99
+ entryFileNames: 'static/js/[name]-[hash].js',
100
+ assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
101
+ manualChunks(id) {
102
+ if (id.includes('node_modules'))
103
+ return 'third' // 代码分割为第三方包
104
+
105
+ if (id.includes('views'))
106
+ return 'views' // 代码分割为业务视图
107
+ },
108
+ },
109
+ },
110
+ },
111
+
112
+ optimizeDeps: { include, exclude },
113
+ }
114
+ }