af-mobile-client-vue3 1.0.94 → 1.0.96
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/.env +6 -6
- package/.env.development +4 -4
- package/.env.envoiceShow +6 -6
- package/.env.production +6 -6
- package/.husky/commit-msg +1 -1
- package/.husky/pre-commit +1 -1
- package/.vscode/settings.json +61 -61
- package/build/vite/index.ts +91 -91
- package/eslint.config.js +9 -1
- package/mock/modules/user.mock.ts +152 -152
- package/package.json +1 -1
- package/public/favicon.svg +4 -4
- package/public/safari-pinned-tab.svg +32 -32
- package/scripts/verifyCommit.js +19 -19
- package/src/App.vue +43 -43
- package/src/api/user/index.ts +40 -40
- package/src/bootstrap.ts +18 -18
- package/src/components/core/App/MicroAppView.vue +3 -3
- package/src/components/core/NavBar/index.vue +12 -12
- package/src/components/core/SvgIcon/index.vue +1 -1
- package/src/components/core/Tabbar/index.vue +38 -38
- package/src/components/core/Uploader/index.vue +1 -1
- package/src/components/core/XGridDropOption/index.vue +151 -151
- package/src/components/core/XMultiSelect/index.vue +183 -183
- package/src/components/data/XCellDetail/index.vue +106 -106
- package/src/components/data/XCellList/XCellList.md +28 -28
- package/src/components/data/XCellList/index.vue +50 -11
- package/src/components/data/XCellListFilter/QrScanner/index.vue +1 -1
- package/src/components/data/XCellListFilter/VpnRecognition/index.vue +3 -3
- package/src/components/data/XCellListFilter/index.vue +160 -62
- package/src/components/data/XForm/index.vue +2 -2
- package/src/components/data/XFormGroup/index.vue +3 -3
- package/src/components/data/XFormItem/index.vue +25 -26
- package/src/components/data/XOlMap/demo.vue +209 -0
- package/src/components/data/XOlMap/index.vue +644 -0
- package/src/components/data/XReportForm/XReportFormJsonRender.vue +220 -220
- package/src/components/data/XReportForm/index.vue +1079 -1079
- package/src/components/data/XReportGrid/XAddReport/XAddReport.vue +4 -7
- package/src/components/data/XReportGrid/XAddReport/index.md +3 -7
- package/src/components/data/XReportGrid/XAddReport/index.ts +2 -2
- package/src/components/data/XReportGrid/XReport.vue +25 -38
- package/src/components/data/XReportGrid/XReportDesign.vue +46 -46
- package/src/components/data/XReportGrid/XReportDrawer/XReportDrawer.vue +3 -3
- package/src/components/data/XReportGrid/XReportDrawer/index.ts +2 -2
- package/src/components/data/XReportGrid/XReportJsonRender.vue +20 -7
- package/src/components/data/XReportGrid/XReportTrGroup.vue +4 -4
- package/src/components/data/XReportGrid/index.md +4 -6
- package/src/components/data/XSignature/index.vue +285 -285
- package/src/components/data/XTag/index.vue +10 -10
- package/src/components/layout/NormalDataLayout/index.vue +70 -70
- package/src/components/layout/TabBarLayout/index.vue +40 -40
- package/src/components.d.ts +53 -53
- package/src/env.d.ts +16 -16
- package/src/font-style/font.css +3 -3
- package/src/hooks/useCommon.ts +9 -9
- package/src/layout/GridView/index.vue +1 -1
- package/src/layout/PageLayout.vue +5 -5
- package/src/layout/SingleLayout.vue +3 -3
- package/src/locales/en-US.json +25 -25
- package/src/locales/zh-CN.json +25 -25
- package/src/plugins/AppData.ts +38 -38
- package/src/plugins/index.ts +1 -1
- package/src/router/guards.ts +59 -59
- package/src/router/index.ts +61 -60
- package/src/router/invoiceRoutes.ts +33 -33
- package/src/router/routes.ts +20 -14
- package/src/services/api/common.ts +109 -109
- package/src/services/api/manage.ts +8 -8
- package/src/services/restTools.ts +52 -52
- package/src/services/v3Api.ts +46 -35
- package/src/stores/modules/cachedView.ts +1 -1
- package/src/stores/modules/setting.ts +52 -52
- package/src/stores/modules/user.ts +5 -5
- package/src/stores/mutation-type.ts +7 -7
- package/src/styles/app.less +6 -1
- package/src/utils/Storage.ts +1 -1
- package/src/utils/authority-utils.ts +84 -84
- package/src/utils/crypto.ts +39 -39
- package/src/utils/http/index.ts +6 -6
- package/src/utils/i18n.ts +41 -41
- package/src/utils/indexedDB.ts +180 -180
- package/src/utils/mobileUtil.ts +26 -26
- package/src/utils/routerUtil.ts +271 -271
- package/src/utils/runEvalFunction.ts +13 -13
- package/src/utils/validate.ts +1 -1
- package/src/utils/wechatUtil.ts +9 -9
- package/src/views/chat/index.vue +1 -1
- package/src/views/common/LoadError.vue +64 -64
- package/src/views/common/NotFound.vue +68 -68
- package/src/views/component/EvaluateRecordView/index.vue +40 -40
- package/src/views/component/XCellDetailView/index.vue +217 -216
- package/src/views/component/XCellListView/index.vue +1 -1
- package/src/views/component/XFormAppraiseView/index.vue +4 -4
- package/src/views/component/XFormGroupView/index.vue +1 -1
- package/src/views/component/XFormView/index.vue +6 -7
- package/src/views/component/XReportFormIframeView/index.vue +47 -47
- package/src/views/component/XReportFormView/index.vue +13 -13
- package/src/views/component/XReportGridView/index.vue +2 -3
- package/src/views/component/XSignatureView/index.vue +50 -50
- package/src/views/component/index.vue +4 -4
- package/src/views/component/menu.vue +117 -117
- package/src/views/component/notice.vue +46 -46
- package/src/views/component/topNav.vue +36 -36
- package/src/views/invoiceShow/index.vue +61 -62
- package/src/views/user/login/ForgetPasswordForm.vue +94 -93
- package/src/views/user/login/LoginForm.vue +8 -7
- package/src/views/user/login/LoginTitle.vue +68 -68
- package/src/views/user/login/index.vue +22 -22
- package/src/views/user/my/index.vue +230 -230
- package/src/vue-router.d.ts +9 -9
- package/tsconfig.json +43 -43
- package/uno.config.ts +1 -1
- package/vite.config.ts +123 -123
package/src/utils/crypto.ts
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import AesEncryptJS from 'crypto-js'
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
/**
|
|
5
|
-
* AES加密
|
|
6
|
-
*
|
|
7
|
-
* @param word
|
|
8
|
-
* @param encryKey
|
|
9
|
-
*/
|
|
10
|
-
AESEncrypt(word: string, encryKey: string): string {
|
|
11
|
-
const key = AesEncryptJS.enc.Utf8.parse(encryKey)
|
|
12
|
-
const srcs = AesEncryptJS.enc.Utf8.parse(word)
|
|
13
|
-
const encrypted = AesEncryptJS.AES.encrypt(srcs, key, {
|
|
14
|
-
mode: AesEncryptJS.mode.ECB,
|
|
15
|
-
padding: AesEncryptJS.pad.Pkcs7,
|
|
16
|
-
})
|
|
17
|
-
return encrypted.toString()
|
|
18
|
-
},
|
|
19
|
-
/**
|
|
20
|
-
* AES解密
|
|
21
|
-
*
|
|
22
|
-
* @param word
|
|
23
|
-
* @param encryKey
|
|
24
|
-
*/
|
|
25
|
-
AESDecrypt(word: string, encryKey: string): any {
|
|
26
|
-
const key = AesEncryptJS.enc.Utf8.parse(encryKey)
|
|
27
|
-
const decrypt = AesEncryptJS.AES.decrypt(word, key, {
|
|
28
|
-
mode: AesEncryptJS.mode.ECB,
|
|
29
|
-
padding: AesEncryptJS.pad.Pkcs7,
|
|
30
|
-
})
|
|
31
|
-
const ret = AesEncryptJS.enc.Utf8.stringify(decrypt).toString()
|
|
32
|
-
try {
|
|
33
|
-
return JSON.parse(ret)
|
|
34
|
-
}
|
|
35
|
-
catch
|
|
36
|
-
return ret
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
}
|
|
1
|
+
import AesEncryptJS from 'crypto-js'
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
/**
|
|
5
|
+
* AES加密
|
|
6
|
+
*
|
|
7
|
+
* @param word
|
|
8
|
+
* @param encryKey
|
|
9
|
+
*/
|
|
10
|
+
AESEncrypt(word: string, encryKey: string): string {
|
|
11
|
+
const key = AesEncryptJS.enc.Utf8.parse(encryKey)
|
|
12
|
+
const srcs = AesEncryptJS.enc.Utf8.parse(word)
|
|
13
|
+
const encrypted = AesEncryptJS.AES.encrypt(srcs, key, {
|
|
14
|
+
mode: AesEncryptJS.mode.ECB,
|
|
15
|
+
padding: AesEncryptJS.pad.Pkcs7,
|
|
16
|
+
})
|
|
17
|
+
return encrypted.toString()
|
|
18
|
+
},
|
|
19
|
+
/**
|
|
20
|
+
* AES解密
|
|
21
|
+
*
|
|
22
|
+
* @param word
|
|
23
|
+
* @param encryKey
|
|
24
|
+
*/
|
|
25
|
+
AESDecrypt(word: string, encryKey: string): any {
|
|
26
|
+
const key = AesEncryptJS.enc.Utf8.parse(encryKey)
|
|
27
|
+
const decrypt = AesEncryptJS.AES.decrypt(word, key, {
|
|
28
|
+
mode: AesEncryptJS.mode.ECB,
|
|
29
|
+
padding: AesEncryptJS.pad.Pkcs7,
|
|
30
|
+
})
|
|
31
|
+
const ret = AesEncryptJS.enc.Utf8.stringify(decrypt).toString()
|
|
32
|
+
try {
|
|
33
|
+
return JSON.parse(ret)
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return ret
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
}
|
package/src/utils/http/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { showToast } from 'vant'
|
|
1
|
+
import type { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'
|
|
3
2
|
import { ContentTypeEnum, ResultEnum } from '@af-mobile-client-vue3/enums/requestEnum'
|
|
4
|
-
import { ACCESS_TOKEN } from '@af-mobile-client-vue3/stores/mutation-type'
|
|
5
3
|
import { useUserStore } from '@af-mobile-client-vue3/stores/modules/user'
|
|
4
|
+
import { ACCESS_TOKEN } from '@af-mobile-client-vue3/stores/mutation-type'
|
|
6
5
|
import axios from 'axios'
|
|
6
|
+
import { showToast } from 'vant'
|
|
7
7
|
|
|
8
8
|
// 默认 axios 实例请求配置
|
|
9
9
|
const configDefault = {
|
|
@@ -160,7 +160,7 @@ const METHOD = {
|
|
|
160
160
|
GET: 'get',
|
|
161
161
|
POST: 'post',
|
|
162
162
|
PUT: 'put',
|
|
163
|
-
DELETE: 'delete'
|
|
163
|
+
DELETE: 'delete',
|
|
164
164
|
}
|
|
165
165
|
/**
|
|
166
166
|
* axios请求
|
|
@@ -170,7 +170,7 @@ const METHOD = {
|
|
|
170
170
|
* @param config
|
|
171
171
|
* @returns {Promise<AxiosResponse<T>>}
|
|
172
172
|
*/
|
|
173
|
-
async function request
|
|
173
|
+
async function request(url, method, params, config) {
|
|
174
174
|
switch (method) {
|
|
175
175
|
case METHOD.GET:
|
|
176
176
|
return axios.get(url, { params, ...config })
|
|
@@ -189,4 +189,4 @@ export const http = new Http(configDefault)
|
|
|
189
189
|
export {
|
|
190
190
|
METHOD,
|
|
191
191
|
request,
|
|
192
|
-
}
|
|
192
|
+
}
|
package/src/utils/i18n.ts
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
// // import { createI18n } from 'vue-i18n'
|
|
2
|
-
// import enUS from 'vant/es/locale/lang/en-US'
|
|
3
|
-
// import zhCN from 'vant/es/locale/lang/zh-CN'
|
|
4
|
-
//
|
|
5
|
-
// /**
|
|
6
|
-
// * All i18n resources specified in the plugin `include` option can be loaded
|
|
7
|
-
// * at once using the import syntax
|
|
8
|
-
// */
|
|
9
|
-
// // import messages from '@intlify/unplugin-vue-i18n/messages'
|
|
10
|
-
// import { Locale, type PickerColumn } from 'vant'
|
|
11
|
-
//
|
|
12
|
-
// // export const i18n = createI18n({
|
|
13
|
-
// // locale: localStorage.getItem('language') || navigator.language,
|
|
14
|
-
// // fallbackLocale: 'zhCN',
|
|
15
|
-
// // messages,
|
|
16
|
-
// // })
|
|
17
|
-
//
|
|
18
|
-
// /** 多语言 picker columns */
|
|
19
|
-
// export const languageColumns: PickerColumn = [
|
|
20
|
-
// { text: '简体中文', value: 'zh-CN' },
|
|
21
|
-
// { text: 'English', value: 'en-US' },
|
|
22
|
-
// ]
|
|
23
|
-
//
|
|
24
|
-
// /** 当前语言 */
|
|
25
|
-
// export const locale = computed({
|
|
26
|
-
// get() {
|
|
27
|
-
// return (i18n.global.locale as unknown as Ref<string>).value
|
|
28
|
-
// },
|
|
29
|
-
// set(language: string) {
|
|
30
|
-
// localStorage.setItem('language', language);
|
|
31
|
-
// (i18n.global.locale as unknown as Ref<string>).value = language
|
|
32
|
-
// Locale.use(language)
|
|
33
|
-
// },
|
|
34
|
-
// })
|
|
35
|
-
//
|
|
36
|
-
// // 载入 vant 语言包
|
|
37
|
-
// Locale.use('zh-CN', zhCN)
|
|
38
|
-
// Locale.use('en-US', enUS)
|
|
39
|
-
//
|
|
40
|
-
// // 根据当前语言切换 vant 语言包
|
|
41
|
-
// Locale.use(locale.value)
|
|
1
|
+
// // import { createI18n } from 'vue-i18n'
|
|
2
|
+
// import enUS from 'vant/es/locale/lang/en-US'
|
|
3
|
+
// import zhCN from 'vant/es/locale/lang/zh-CN'
|
|
4
|
+
//
|
|
5
|
+
// /**
|
|
6
|
+
// * All i18n resources specified in the plugin `include` option can be loaded
|
|
7
|
+
// * at once using the import syntax
|
|
8
|
+
// */
|
|
9
|
+
// // import messages from '@intlify/unplugin-vue-i18n/messages'
|
|
10
|
+
// import { Locale, type PickerColumn } from 'vant'
|
|
11
|
+
//
|
|
12
|
+
// // export const i18n = createI18n({
|
|
13
|
+
// // locale: localStorage.getItem('language') || navigator.language,
|
|
14
|
+
// // fallbackLocale: 'zhCN',
|
|
15
|
+
// // messages,
|
|
16
|
+
// // })
|
|
17
|
+
//
|
|
18
|
+
// /** 多语言 picker columns */
|
|
19
|
+
// export const languageColumns: PickerColumn = [
|
|
20
|
+
// { text: '简体中文', value: 'zh-CN' },
|
|
21
|
+
// { text: 'English', value: 'en-US' },
|
|
22
|
+
// ]
|
|
23
|
+
//
|
|
24
|
+
// /** 当前语言 */
|
|
25
|
+
// export const locale = computed({
|
|
26
|
+
// get() {
|
|
27
|
+
// return (i18n.global.locale as unknown as Ref<string>).value
|
|
28
|
+
// },
|
|
29
|
+
// set(language: string) {
|
|
30
|
+
// localStorage.setItem('language', language);
|
|
31
|
+
// (i18n.global.locale as unknown as Ref<string>).value = language
|
|
32
|
+
// Locale.use(language)
|
|
33
|
+
// },
|
|
34
|
+
// })
|
|
35
|
+
//
|
|
36
|
+
// // 载入 vant 语言包
|
|
37
|
+
// Locale.use('zh-CN', zhCN)
|
|
38
|
+
// Locale.use('en-US', enUS)
|
|
39
|
+
//
|
|
40
|
+
// // 根据当前语言切换 vant 语言包
|
|
41
|
+
// Locale.use(locale.value)
|
package/src/utils/indexedDB.ts
CHANGED
|
@@ -1,180 +1,180 @@
|
|
|
1
|
-
// indexDB 存储
|
|
2
|
-
import { post } from '@af-mobile-client-vue3/services/restTools'
|
|
3
|
-
|
|
4
|
-
// 避免重复请求相同配置key的锁
|
|
5
|
-
const locks: any = {}
|
|
6
|
-
|
|
7
|
-
export const indexedDB = {
|
|
8
|
-
db: undefined,
|
|
9
|
-
indexedDB: window.indexedDB,
|
|
10
|
-
IDBKeyRange: window.IDBKeyRange, // 键范围
|
|
11
|
-
openDB(callback: Function) {
|
|
12
|
-
// 建立或打开数据库,建立对象存储空间(ObjectStore)
|
|
13
|
-
if (this.db) {
|
|
14
|
-
callback(this.db)
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
const version = 1
|
|
18
|
-
const request = this.indexedDB.open('view', version)
|
|
19
|
-
|
|
20
|
-
request.onerror = function (e: any) {
|
|
21
|
-
console.error(`打开数据库失败:${e.currentTarget.error.message}`)
|
|
22
|
-
}
|
|
23
|
-
request.onsuccess = function (e: any) {
|
|
24
|
-
this.db = e.target.result
|
|
25
|
-
callback(this.db)
|
|
26
|
-
}
|
|
27
|
-
request.onupgradeneeded = function (e: any) {
|
|
28
|
-
const db = e.target.result
|
|
29
|
-
if (!db.objectStoreNames.contains('metaCache')) {
|
|
30
|
-
// 没有该对象空间时创建该对象空间
|
|
31
|
-
db.createObjectStore('metaCache', {
|
|
32
|
-
keyPath: 'key',
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
deleteDB(dbname: string) {
|
|
39
|
-
// 删除数据库
|
|
40
|
-
this.indexedDB.deleteDatabase(dbname)
|
|
41
|
-
},
|
|
42
|
-
closeDB() {
|
|
43
|
-
if (!this.db)
|
|
44
|
-
this.db.close()
|
|
45
|
-
},
|
|
46
|
-
add(key: string, data: any) {
|
|
47
|
-
// eslint-disable-next-line ts/no-this-alias
|
|
48
|
-
const self = this
|
|
49
|
-
self.openDB((res: IDBDatabase) => {
|
|
50
|
-
const request = res.transaction('metaCache', 'readwrite').objectStore('metaCache').add({
|
|
51
|
-
key,
|
|
52
|
-
data,
|
|
53
|
-
})
|
|
54
|
-
request.onerror = function () {
|
|
55
|
-
self.update(key, data)
|
|
56
|
-
}
|
|
57
|
-
request.onsuccess = function () {
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
},
|
|
61
|
-
update(key: string, data: any) {
|
|
62
|
-
this.openDB((res: IDBDatabase) => {
|
|
63
|
-
const request = res.transaction('metaCache', 'readwrite').objectStore('metaCache').put({
|
|
64
|
-
key,
|
|
65
|
-
data,
|
|
66
|
-
})
|
|
67
|
-
request.onerror = function () {
|
|
68
|
-
console.error('数据更新失败')
|
|
69
|
-
}
|
|
70
|
-
request.onsuccess = function () {
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
},
|
|
74
|
-
get(key: string, callback: Function) {
|
|
75
|
-
this.openDB((res: IDBDatabase) => {
|
|
76
|
-
// 根据存储空间的键找到对应数据
|
|
77
|
-
const store = res.transaction('metaCache', 'readwrite').objectStore('metaCache')
|
|
78
|
-
const request = store.get(key)
|
|
79
|
-
request.onerror = function () {
|
|
80
|
-
}
|
|
81
|
-
request.onsuccess = function (e: any) {
|
|
82
|
-
const result = e.target.result
|
|
83
|
-
if (typeof (callback) === 'function')
|
|
84
|
-
callback(result.data)
|
|
85
|
-
}
|
|
86
|
-
})
|
|
87
|
-
},
|
|
88
|
-
getByWeb(key: string, url: string, params: any, callback: Function, processFun: Function) {
|
|
89
|
-
// 如果这个键正在被使用,等待它完成
|
|
90
|
-
if (locks[key]) {
|
|
91
|
-
locks[key].then(() => {
|
|
92
|
-
this.getByWeb(key, url, params, callback, processFun)
|
|
93
|
-
})
|
|
94
|
-
return
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// 创建一个新的 Promise
|
|
98
|
-
locks[key] = new Promise<void>((resolve, reject) => {
|
|
99
|
-
// eslint-disable-next-line ts/no-this-alias
|
|
100
|
-
const self = this
|
|
101
|
-
self.openDB((res: IDBDatabase) => {
|
|
102
|
-
// 根据存储空间的键找到对应数据
|
|
103
|
-
const store = res.transaction('metaCache', 'readwrite').objectStore('metaCache')
|
|
104
|
-
const request = store.get(key)
|
|
105
|
-
request.onerror = function (e) {
|
|
106
|
-
reject(e)
|
|
107
|
-
}
|
|
108
|
-
request.onsuccess = function (e: any) {
|
|
109
|
-
const result = e.target.result
|
|
110
|
-
if (!result && url) {
|
|
111
|
-
post(url, params).then((res) => {
|
|
112
|
-
if (processFun)
|
|
113
|
-
res = processFun(res)
|
|
114
|
-
|
|
115
|
-
if (import.meta.env.NODE_ENV === 'production' || key !== 'webMobileConfig')
|
|
116
|
-
self.add(key, res)
|
|
117
|
-
|
|
118
|
-
try {
|
|
119
|
-
callback(res)
|
|
120
|
-
}
|
|
121
|
-
catch (e) {
|
|
122
|
-
console.error(e)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// 解锁这个键
|
|
126
|
-
resolve()
|
|
127
|
-
}).catch(() => {
|
|
128
|
-
if (import.meta.env.NODE_ENV === 'production' || key !== 'webMobileConfig')
|
|
129
|
-
self.add(key, null)
|
|
130
|
-
callback(null)
|
|
131
|
-
|
|
132
|
-
// 解锁这个键
|
|
133
|
-
resolve()
|
|
134
|
-
})
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
callback(result.data)
|
|
138
|
-
|
|
139
|
-
// 解锁这个键
|
|
140
|
-
resolve()
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
})
|
|
144
|
-
}).finally(() => {
|
|
145
|
-
// 移除这个键的锁
|
|
146
|
-
delete locks[key]
|
|
147
|
-
})
|
|
148
|
-
},
|
|
149
|
-
delete(key: string) {
|
|
150
|
-
this.openDB((res: IDBDatabase) => {
|
|
151
|
-
// 删除某一条记录
|
|
152
|
-
const request = res.transaction('metaCache', 'readwrite').objectStore('metaCache').delete(key)
|
|
153
|
-
|
|
154
|
-
request.onerror = function () {
|
|
155
|
-
console.error('数据删除失败')
|
|
156
|
-
}
|
|
157
|
-
request.onsuccess = function () {
|
|
158
|
-
}
|
|
159
|
-
})
|
|
160
|
-
},
|
|
161
|
-
clear(callback?: Function) {
|
|
162
|
-
this.openDB((res: IDBDatabase) => {
|
|
163
|
-
// 删除存储空间全部记录
|
|
164
|
-
const request = res.transaction('metaCache', 'readwrite').objectStore('metaCache').clear()
|
|
165
|
-
|
|
166
|
-
request.onerror = function () {
|
|
167
|
-
console.error('数据删除失败')
|
|
168
|
-
}
|
|
169
|
-
request.onsuccess = function () {
|
|
170
|
-
if (typeof callback === 'function')
|
|
171
|
-
callback()
|
|
172
|
-
}
|
|
173
|
-
})
|
|
174
|
-
},
|
|
175
|
-
clearCache() {
|
|
176
|
-
indexedDB.clear(() => {
|
|
177
|
-
location.reload()
|
|
178
|
-
})
|
|
179
|
-
},
|
|
180
|
-
}
|
|
1
|
+
// indexDB 存储
|
|
2
|
+
import { post } from '@af-mobile-client-vue3/services/restTools'
|
|
3
|
+
|
|
4
|
+
// 避免重复请求相同配置key的锁
|
|
5
|
+
const locks: any = {}
|
|
6
|
+
|
|
7
|
+
export const indexedDB = {
|
|
8
|
+
db: undefined,
|
|
9
|
+
indexedDB: window.indexedDB,
|
|
10
|
+
IDBKeyRange: window.IDBKeyRange, // 键范围
|
|
11
|
+
openDB(callback: Function) {
|
|
12
|
+
// 建立或打开数据库,建立对象存储空间(ObjectStore)
|
|
13
|
+
if (this.db) {
|
|
14
|
+
callback(this.db)
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const version = 1
|
|
18
|
+
const request = this.indexedDB.open('view', version)
|
|
19
|
+
|
|
20
|
+
request.onerror = function (e: any) {
|
|
21
|
+
console.error(`打开数据库失败:${e.currentTarget.error.message}`)
|
|
22
|
+
}
|
|
23
|
+
request.onsuccess = function (e: any) {
|
|
24
|
+
this.db = e.target.result
|
|
25
|
+
callback(this.db)
|
|
26
|
+
}
|
|
27
|
+
request.onupgradeneeded = function (e: any) {
|
|
28
|
+
const db = e.target.result
|
|
29
|
+
if (!db.objectStoreNames.contains('metaCache')) {
|
|
30
|
+
// 没有该对象空间时创建该对象空间
|
|
31
|
+
db.createObjectStore('metaCache', {
|
|
32
|
+
keyPath: 'key',
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
deleteDB(dbname: string) {
|
|
39
|
+
// 删除数据库
|
|
40
|
+
this.indexedDB.deleteDatabase(dbname)
|
|
41
|
+
},
|
|
42
|
+
closeDB() {
|
|
43
|
+
if (!this.db)
|
|
44
|
+
this.db.close()
|
|
45
|
+
},
|
|
46
|
+
add(key: string, data: any) {
|
|
47
|
+
// eslint-disable-next-line ts/no-this-alias
|
|
48
|
+
const self = this
|
|
49
|
+
self.openDB((res: IDBDatabase) => {
|
|
50
|
+
const request = res.transaction('metaCache', 'readwrite').objectStore('metaCache').add({
|
|
51
|
+
key,
|
|
52
|
+
data,
|
|
53
|
+
})
|
|
54
|
+
request.onerror = function () {
|
|
55
|
+
self.update(key, data)
|
|
56
|
+
}
|
|
57
|
+
request.onsuccess = function () {
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
},
|
|
61
|
+
update(key: string, data: any) {
|
|
62
|
+
this.openDB((res: IDBDatabase) => {
|
|
63
|
+
const request = res.transaction('metaCache', 'readwrite').objectStore('metaCache').put({
|
|
64
|
+
key,
|
|
65
|
+
data,
|
|
66
|
+
})
|
|
67
|
+
request.onerror = function () {
|
|
68
|
+
console.error('数据更新失败')
|
|
69
|
+
}
|
|
70
|
+
request.onsuccess = function () {
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
},
|
|
74
|
+
get(key: string, callback: Function) {
|
|
75
|
+
this.openDB((res: IDBDatabase) => {
|
|
76
|
+
// 根据存储空间的键找到对应数据
|
|
77
|
+
const store = res.transaction('metaCache', 'readwrite').objectStore('metaCache')
|
|
78
|
+
const request = store.get(key)
|
|
79
|
+
request.onerror = function () {
|
|
80
|
+
}
|
|
81
|
+
request.onsuccess = function (e: any) {
|
|
82
|
+
const result = e.target.result
|
|
83
|
+
if (typeof (callback) === 'function')
|
|
84
|
+
callback(result.data)
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
},
|
|
88
|
+
getByWeb(key: string, url: string, params: any, callback: Function, processFun: Function) {
|
|
89
|
+
// 如果这个键正在被使用,等待它完成
|
|
90
|
+
if (locks[key]) {
|
|
91
|
+
locks[key].then(() => {
|
|
92
|
+
this.getByWeb(key, url, params, callback, processFun)
|
|
93
|
+
})
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 创建一个新的 Promise
|
|
98
|
+
locks[key] = new Promise<void>((resolve, reject) => {
|
|
99
|
+
// eslint-disable-next-line ts/no-this-alias
|
|
100
|
+
const self = this
|
|
101
|
+
self.openDB((res: IDBDatabase) => {
|
|
102
|
+
// 根据存储空间的键找到对应数据
|
|
103
|
+
const store = res.transaction('metaCache', 'readwrite').objectStore('metaCache')
|
|
104
|
+
const request = store.get(key)
|
|
105
|
+
request.onerror = function (e) {
|
|
106
|
+
reject(e)
|
|
107
|
+
}
|
|
108
|
+
request.onsuccess = function (e: any) {
|
|
109
|
+
const result = e.target.result
|
|
110
|
+
if (!result && url) {
|
|
111
|
+
post(url, params).then((res) => {
|
|
112
|
+
if (processFun)
|
|
113
|
+
res = processFun(res)
|
|
114
|
+
|
|
115
|
+
if (import.meta.env.NODE_ENV === 'production' || key !== 'webMobileConfig')
|
|
116
|
+
self.add(key, res)
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
callback(res)
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
console.error(e)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 解锁这个键
|
|
126
|
+
resolve()
|
|
127
|
+
}).catch(() => {
|
|
128
|
+
if (import.meta.env.NODE_ENV === 'production' || key !== 'webMobileConfig')
|
|
129
|
+
self.add(key, null)
|
|
130
|
+
callback(null)
|
|
131
|
+
|
|
132
|
+
// 解锁这个键
|
|
133
|
+
resolve()
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
callback(result.data)
|
|
138
|
+
|
|
139
|
+
// 解锁这个键
|
|
140
|
+
resolve()
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
}).finally(() => {
|
|
145
|
+
// 移除这个键的锁
|
|
146
|
+
delete locks[key]
|
|
147
|
+
})
|
|
148
|
+
},
|
|
149
|
+
delete(key: string) {
|
|
150
|
+
this.openDB((res: IDBDatabase) => {
|
|
151
|
+
// 删除某一条记录
|
|
152
|
+
const request = res.transaction('metaCache', 'readwrite').objectStore('metaCache').delete(key)
|
|
153
|
+
|
|
154
|
+
request.onerror = function () {
|
|
155
|
+
console.error('数据删除失败')
|
|
156
|
+
}
|
|
157
|
+
request.onsuccess = function () {
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
},
|
|
161
|
+
clear(callback?: Function) {
|
|
162
|
+
this.openDB((res: IDBDatabase) => {
|
|
163
|
+
// 删除存储空间全部记录
|
|
164
|
+
const request = res.transaction('metaCache', 'readwrite').objectStore('metaCache').clear()
|
|
165
|
+
|
|
166
|
+
request.onerror = function () {
|
|
167
|
+
console.error('数据删除失败')
|
|
168
|
+
}
|
|
169
|
+
request.onsuccess = function () {
|
|
170
|
+
if (typeof callback === 'function')
|
|
171
|
+
callback()
|
|
172
|
+
}
|
|
173
|
+
})
|
|
174
|
+
},
|
|
175
|
+
clearCache() {
|
|
176
|
+
indexedDB.clear(() => {
|
|
177
|
+
location.reload()
|
|
178
|
+
})
|
|
179
|
+
},
|
|
180
|
+
}
|
package/src/utils/mobileUtil.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
interface Param {
|
|
2
|
-
funcName: string// 注册列表中的对应函数的key
|
|
3
|
-
param:
|
|
4
|
-
callbackFunc:
|
|
5
|
-
callBackMethodName?: string// 随机回调函数名字-不用传
|
|
6
|
-
}
|
|
7
|
-
// js端调用flutter中工具函数
|
|
8
|
-
/*
|
|
9
|
-
* 例:mobileUtil.execute({
|
|
10
|
-
funcName:'getLocationResult',
|
|
11
|
-
param: {a: 1},
|
|
12
|
-
callbackFunc: (result) => {
|
|
13
|
-
console.log('回调了test111', JSON.stringify(result))
|
|
14
|
-
message.value = JSON.stringify(result)
|
|
15
|
-
return 222
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
* */
|
|
19
|
-
export class mobileUtil {
|
|
20
|
-
// 执行flutter端函数
|
|
21
|
-
static execute(locationParam: Param): any {
|
|
22
|
-
locationParam.callBackMethodName = `mobile_func_${Math.random().toString(36).substring(7)}`
|
|
23
|
-
window[locationParam.callBackMethodName] = locationParam.callbackFunc
|
|
24
|
-
window[locationParam.funcName].postMessage(JSON.stringify(locationParam))
|
|
25
|
-
}
|
|
26
|
-
}
|
|
1
|
+
interface Param {
|
|
2
|
+
funcName: string // 注册列表中的对应函数的key
|
|
3
|
+
param: Record<string, unknown> // 入参json格式
|
|
4
|
+
callbackFunc: (result: unknown) => unknown // 回调函数
|
|
5
|
+
callBackMethodName?: string // 随机回调函数名字-不用传
|
|
6
|
+
}
|
|
7
|
+
// js端调用flutter中工具函数
|
|
8
|
+
/*
|
|
9
|
+
* 例:mobileUtil.execute({
|
|
10
|
+
funcName:'getLocationResult',
|
|
11
|
+
param: {a: 1},
|
|
12
|
+
callbackFunc: (result) => {
|
|
13
|
+
console.log('回调了test111', JSON.stringify(result))
|
|
14
|
+
message.value = JSON.stringify(result)
|
|
15
|
+
return 222
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
* */
|
|
19
|
+
export class mobileUtil {
|
|
20
|
+
// 执行flutter端函数
|
|
21
|
+
static execute(locationParam: Param): any {
|
|
22
|
+
locationParam.callBackMethodName = `mobile_func_${Math.random().toString(36).substring(7)}`
|
|
23
|
+
window[locationParam.callBackMethodName] = locationParam.callbackFunc
|
|
24
|
+
window[locationParam.funcName].postMessage(JSON.stringify(locationParam))
|
|
25
|
+
}
|
|
26
|
+
}
|