vue2-client 1.22.2 → 1.22.3
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/.claude/settings.local.json +30 -30
- package/.env.his +19 -19
- package/.eslintrc.js +74 -74
- package/.history/.eslintrc_20260521171150.js +74 -0
- package/.history/.eslintrc_20260521171213.js +74 -0
- package/.history/src/base-client/components/common/HIS/HAddNativeForm/HAddNativeForm_20260601154443.vue +726 -0
- package/.history/src/base-client/components/common/HIS/HAddNativeForm/HAddNativeForm_20260601154700.vue +478 -0
- package/.history/src/base-client/components/common/HIS/HButtons/HButtons_20260512175435.vue +706 -0
- package/.history/src/base-client/components/common/HIS/HButtons/HButtons_20260512175450.vue +694 -0
- package/.history/src/base-client/components/common/HIS/HButtons/HButtons_20260611152602.vue +755 -0
- package/.history/src/base-client/components/common/HIS/HForm/HForm_20260513145941.vue +524 -0
- package/.history/src/base-client/components/common/HIS/HForm/HForm_20260513153133.vue +731 -0
- package/.history/src/base-client/components/common/HIS/HForm/HForm_20260513160316.vue +525 -0
- package/.history/src/base-client/components/common/HIS/HForm/HForm_20260601144150.vue +1046 -0
- package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260310142713.vue +512 -0
- package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260310145118.vue +511 -0
- package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260311094834.vue +696 -0
- package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260320143028.vue +693 -0
- package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260409101450.vue +677 -0
- package/.history/src/base-client/components/common/HIS/HTab/HTab_20260508164645.vue +758 -0
- package/.history/src/base-client/components/common/HIS/HTab/HTab_20260508164714.vue +693 -0
- package/.history/src/base-client/components/common/HIS/HTab/HTab_20260508171651.vue +716 -0
- package/.history/src/base-client/components/common/HIS/HTab/HTab_20260509133717.vue +695 -0
- package/.history/src/base-client/components/common/HIS/HTab/HTab_20260509171115.vue +664 -0
- package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513140637.vue +1455 -0
- package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513140935.vue +1441 -0
- package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513150818.vue +1441 -0
- package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513153119.vue +1442 -0
- package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513153126.vue +1486 -0
- package/.history/src/base-client/components/common/XForm/XFormItem_20260513140854.vue +1607 -0
- package/.history/src/base-client/components/common/XMarkdownViewer/XMarkdownViewer_20260519140403.vue +643 -0
- package/.history/src/base-client/components/common/XMarkdownViewer/XMarkdownViewer_20260519140829.vue +628 -0
- package/.history/src/base-client/components/common/XMarkdownViewer/demo_20260519142824.vue +104 -0
- package/.history/src/base-client/components/common/XMarkdownViewer/demo_20260519143155.vue +102 -0
- package/.history/src/base-client/components/common/XReportGrid/XReport_20260309171231.vue +1241 -0
- package/.history/src/base-client/components/common/XReportGrid/XReport_20260309171441.vue +1223 -0
- package/.history/src/base-client/components/his/HAi/HAi_20260612174826.vue +472 -0
- package/.history/src/base-client/components/his/HAi/HAi_20260612175839.vue +538 -0
- package/.history/src/base-client/components/his/HAi/HAi_20260615103331.vue +650 -0
- package/.history/src/base-client/components/his/XHDescriptions/XHDescriptions_20260424134504.vue +1469 -0
- package/.history/src/base-client/components/his/XSidebar/XSidebar_20260610171133.vue +788 -0
- package/.history/src/base-client/components/his/XSidebar/XSidebar_20260610171151.vue +780 -0
- package/.history/src/base-client/components/his/XTransfer/XTransfer_20260511170841.vue +585 -0
- package/.history/src/base-client/components/his/XTransfer/XTransfer_20260511171138.vue +787 -0
- package/.history/src/base-client/components/his/XTransfer/XTransfer_20260512141830.vue +739 -0
- package/.history/src/components/STable/index_20260409155138.js +806 -0
- package/.history/src/components/STable/index_20260409155218.js +814 -0
- package/.history/src/expression/core/Expression_20260305164427.js +1371 -0
- package/.history/src/expression/core/Expression_20260305170258.js +1358 -0
- package/.history/src/expression/core/Program_20260305111830.js +944 -0
- package/.history/src/expression/core/Program_20260305112041.js +931 -0
- package/.history/src/logic/LogicRunner_20260304154306.js +170 -0
- package/.history/src/logic/LogicRunner_20260304155553.js +112 -0
- package/.history/src/logic/LogicRunner_20260305105834.js +112 -0
- package/.history/src/logic/LogicRunner_20260305112718.js +129 -0
- package/.history/src/logic/LogicRunner_20260305182436.js +133 -0
- package/.history/src/logic/LogicRunner_20260306151301.js +213 -0
- package/.history/src/logic/LogicRunner_20260306152419.js +213 -0
- package/.history/src/logic/plugins/common/DateTools_20260305154159.js +61 -0
- package/.history/src/logic/plugins/common/DateTools_20260305154217.js +44 -0
- package/.history/src/logic/plugins/common/DateTools_20260305161014.js +44 -0
- package/.history/src/logic/plugins/common/HttpTools_20260305164352.js +80 -0
- package/.history/src/logic/plugins/common/HttpTools_20260305170258.js +75 -0
- package/.history/src/logic/plugins/common/HttpTools_20260305171634.js +75 -0
- package/.history/src/logic/plugins/common/HttpTools_20260306152419.js +72 -0
- package/.history/src/services/api/restTools_20260427142149.js +245 -0
- package/.history/src/services/api/restTools_20260427142853.js +230 -0
- package/.history/src/services/api/restTools_20260519135558.js +230 -0
- package/.history/src/services/api/restTools_20260519140825.js +230 -0
- package/.history/src/services/api/restTools_20260519151223.js +230 -0
- package/.history/src/utils/indexedDB_20260306150918.js +593 -0
- package/.history/src/utils/indexedDB_20260306151301.js +586 -0
- package/.idea/af-vue2-client.iml +9 -0
- package/.idea/codeStyles/Project.xml +62 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +1 -1
- package/Components.md +60 -60
- package/index.js +31 -31
- package/jest-transform-stub.js +8 -8
- package/jest.setup.js +7 -7
- package/package.json +1 -1
- package/preview-input-box.html +180 -0
- package/src/assets/img/querySlotDemo.svg +15 -15
- package/src/base-client/components/common/AmapMarker/AmapPointRendering.vue +120 -120
- package/src/base-client/components/common/CitySelect/index.js +3 -3
- package/src/base-client/components/common/CitySelect/index.md +109 -109
- package/src/base-client/components/common/FormGroupEdit/index.js +3 -3
- package/src/base-client/components/common/FormGroupEdit/index.md +43 -43
- package/src/base-client/components/common/HIS/HButtons/HButtons.vue +55 -1
- package/src/base-client/components/common/HIS/HForm/HForm.vue +1186 -1186
- package/src/base-client/components/common/HIS/HTab/HTab.vue +88 -1
- package/src/base-client/components/common/JSONToTree/jsontotree.vue +271 -271
- package/src/base-client/components/common/PersonSetting/index.js +3 -3
- package/src/base-client/components/common/Tree/index.js +2 -2
- package/src/base-client/components/common/Upload/index.js +3 -3
- package/src/base-client/components/common/XAddNativeForm/index.md +146 -146
- package/src/base-client/components/common/XAddReport/XAddReport.vue +16 -1
- package/src/base-client/components/common/XCard/XCard.vue +64 -64
- package/src/base-client/components/common/XDataDrawer/XDataDrawer.vue +180 -180
- package/src/base-client/components/common/XDataDrawer/index.js +3 -3
- package/src/base-client/components/common/XDataDrawer/index.md +41 -41
- package/src/base-client/components/common/XDescriptions/index.js +3 -3
- package/src/base-client/components/common/XDescriptions/index.md +382 -382
- package/src/base-client/components/common/XForm/index.md +178 -178
- package/src/base-client/components/common/XInput/XInput.vue +32 -1
- package/src/base-client/components/common/XInspectionDetailDrawer/index.vue +1 -1
- package/src/base-client/components/common/XMarkdownViewer/demo.vue +102 -102
- package/src/base-client/components/common/XStepView/XStepView.vue +252 -252
- package/src/base-client/components/common/XStepView/index.js +3 -3
- package/src/base-client/components/common/XStepView/index.md +31 -31
- package/src/base-client/components/common/XTable/index.md +255 -255
- package/src/base-client/components/his/HAi/HAi.vue +1177 -436
- package/src/base-client/components/his/XList/XList.vue +337 -58
- package/src/base-client/components/his/XSidebar/XSidebar.vue +36 -12
- package/src/base-client/components/his/XTransfer/index.md +327 -327
- package/src/base-client/components/system/DictionaryDetailsView/DictionaryDetailsView.vue +232 -232
- package/src/base-client/plugins/Config.js +19 -19
- package/src/base-client/plugins/tabs-page-plugin.js +39 -39
- package/src/components/Charts/Bar.vue +62 -62
- package/src/components/Charts/ChartCard.vue +134 -134
- package/src/components/Charts/Liquid.vue +67 -67
- package/src/components/Charts/MiniArea.vue +39 -39
- package/src/components/Charts/MiniBar.vue +39 -39
- package/src/components/Charts/MiniProgress.vue +75 -75
- package/src/components/Charts/MiniSmoothArea.vue +40 -40
- package/src/components/Charts/Radar.vue +68 -68
- package/src/components/Charts/RankList.vue +77 -77
- package/src/components/Charts/TagCloud.vue +113 -113
- package/src/components/Charts/TransferBar.vue +64 -64
- package/src/components/Charts/Trend.vue +82 -82
- package/src/components/Charts/chart.less +12 -12
- package/src/components/Charts/smooth.area.less +13 -13
- package/src/components/NumberInfo/NumberInfo.vue +54 -54
- package/src/components/NumberInfo/index.js +3 -3
- package/src/components/NumberInfo/index.less +54 -54
- package/src/components/NumberInfo/index.md +43 -43
- package/src/components/STable/index.js +953 -953
- package/src/components/card/ChartCard.vue +79 -79
- package/src/components/chart/Bar.vue +60 -60
- package/src/components/chart/MiniArea.vue +67 -67
- package/src/components/chart/MiniBar.vue +59 -59
- package/src/components/chart/MiniProgress.vue +57 -57
- package/src/components/chart/Radar.vue +80 -80
- package/src/components/chart/RankingList.vue +60 -60
- package/src/components/chart/Trend.vue +79 -79
- package/src/components/chart/index.less +9 -9
- package/src/components/checkbox/ColorCheckbox.vue +157 -157
- package/src/components/input/IInput.vue +66 -66
- package/src/components/menu/SideMenu.vue +75 -75
- package/src/components/menu/menu.js +273 -273
- package/src/components/tool/AStepItem.vue +60 -60
- package/src/layouts/CommonLayout.vue +56 -56
- package/src/lib.js +1 -1
- package/src/mock/extend/index.js +84 -84
- package/src/mock/goods/index.js +108 -108
- package/src/pages/dashboard/workplace/WorkPlace.vue +141 -141
- package/src/pages/system/dictionary/index.vue +44 -44
- package/src/pages/system/monitor/loginInfor/index.vue +37 -37
- package/src/pages/system/monitor/operLog/index.vue +37 -37
- package/src/services/api/cas.js +79 -79
- package/src/store/modules/setting.js +119 -119
- package/src/utils/errorCode.js +6 -6
- package//350/277/201/347/247/273/346/227/245/345/277/227.md +15 -15
- package/.idea/MarsCodeWorkspaceAppSettings.xml +0 -7
- package/.idea/google-java-format.xml +0 -6
- package/.idea/inspectionProfiles/Project_Default.xml +0 -24
- package/.idea/jsLinters/eslint.xml +0 -6
- package/.idea/vue2-client.iml +0 -12
- package/.vscode/settings.json +0 -28
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
import { post } from '@vue2-client/services/api'
|
|
2
|
+
|
|
3
|
+
// 内存缓存作为IndexedDB的备用方案,防止数据库损坏时应用崩溃
|
|
4
|
+
const MEMORY_CACHE = new Map()
|
|
5
|
+
const USE_MEMORY_CACHE = true // 是否启用内存缓存
|
|
6
|
+
|
|
7
|
+
const DB_CONFIG = {
|
|
8
|
+
NAME: window.__MICRO_APP_NAME__ ? `view_${window.__MICRO_APP_NAME__}` : 'view',
|
|
9
|
+
STORE_NAME: 'metaCache',
|
|
10
|
+
VERSION: 1,
|
|
11
|
+
CURRENT_VERSION: 1
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// 数据库健康状态标记,用于在数据库异常时切换到备用方案
|
|
15
|
+
let IS_DB_HEALTHY = true
|
|
16
|
+
|
|
17
|
+
const LIULI_WEB_DB_NAME = 'view_liuli_web'
|
|
18
|
+
|
|
19
|
+
export class IndexedDBManager {
|
|
20
|
+
constructor () {
|
|
21
|
+
this.db = undefined
|
|
22
|
+
this.locks = new Map()
|
|
23
|
+
this.requestTimeout = 10000
|
|
24
|
+
this.isInMicroApp = !!window.__MICRO_APP_NAME__
|
|
25
|
+
this.microAppName = window.__MICRO_APP_NAME__ || ''
|
|
26
|
+
this.indexedDB = window?.rawWindow?.indexedDB || window.indexedDB || window.webkitindexedDB
|
|
27
|
+
this.IDBKeyRange = window?.rawWindow?.IDBKeyRange || window.IDBKeyRange || window.webkitIDBKeyRange
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async openDatabase () {
|
|
31
|
+
try {
|
|
32
|
+
return await new Promise((resolve, reject) => {
|
|
33
|
+
// 添加超时机制,防止请求永久挂起
|
|
34
|
+
const timeout = setTimeout(() => {
|
|
35
|
+
console.error('[openDatabase] 请求超时,将尝试重建数据库')
|
|
36
|
+
reject(new Error('IndexedDB open timeout'))
|
|
37
|
+
}, 5000) // 5秒超时
|
|
38
|
+
|
|
39
|
+
const checkRequest = this.indexedDB.open(DB_CONFIG.NAME)
|
|
40
|
+
|
|
41
|
+
checkRequest.onsuccess = (e) => {
|
|
42
|
+
clearTimeout(timeout) // 清除超时
|
|
43
|
+
const db = e.target.result
|
|
44
|
+
const currentVersion = db.version
|
|
45
|
+
db.close()
|
|
46
|
+
|
|
47
|
+
DB_CONFIG.CURRENT_VERSION = Math.max(currentVersion, DB_CONFIG.VERSION)
|
|
48
|
+
const request = this.indexedDB.open(DB_CONFIG.NAME, DB_CONFIG.CURRENT_VERSION)
|
|
49
|
+
|
|
50
|
+
// 为第二次打开也添加超时
|
|
51
|
+
const openTimeout = setTimeout(() => {
|
|
52
|
+
console.error('[openDatabase] 二次打开请求超时')
|
|
53
|
+
reject(new Error('IndexedDB second open timeout'))
|
|
54
|
+
}, 5000)
|
|
55
|
+
|
|
56
|
+
request.onerror = (e) => {
|
|
57
|
+
clearTimeout(openTimeout)
|
|
58
|
+
reject(e.currentTarget.error)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
request.onsuccess = (e) => {
|
|
62
|
+
clearTimeout(openTimeout)
|
|
63
|
+
const db = e.target.result
|
|
64
|
+
if (!db.objectStoreNames.contains(DB_CONFIG.STORE_NAME)) {
|
|
65
|
+
db.close()
|
|
66
|
+
DB_CONFIG.CURRENT_VERSION++
|
|
67
|
+
this.upgradeDatabase(resolve, reject)
|
|
68
|
+
} else {
|
|
69
|
+
resolve(db)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
request.onupgradeneeded = (e) => {
|
|
74
|
+
clearTimeout(openTimeout)
|
|
75
|
+
const db = e.target.result
|
|
76
|
+
if (!db.objectStoreNames.contains(DB_CONFIG.STORE_NAME)) {
|
|
77
|
+
db.createObjectStore(DB_CONFIG.STORE_NAME, { keyPath: 'key' })
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
checkRequest.onerror = (e) => {
|
|
83
|
+
clearTimeout(timeout)
|
|
84
|
+
reject(e.currentTarget.error)
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error('[openDatabase] 打开数据库失败:', error)
|
|
89
|
+
|
|
90
|
+
// 如果是超时错误或版本错误,尝试自动重建数据库
|
|
91
|
+
if (error.message?.includes('timeout') || error.message?.includes('version')) {
|
|
92
|
+
await this.forceRecreateDatabase()
|
|
93
|
+
return this.openDatabase() // 递归调用,重新尝试打开
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
throw error
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async upgradeDatabase (resolve, reject) {
|
|
101
|
+
console.warn('[upgradeDatabase] 升级数据库到版本:', DB_CONFIG.CURRENT_VERSION)
|
|
102
|
+
const request = this.indexedDB.open(DB_CONFIG.NAME, DB_CONFIG.CURRENT_VERSION)
|
|
103
|
+
|
|
104
|
+
request.onupgradeneeded = (e) => {
|
|
105
|
+
const db = e.target.result
|
|
106
|
+
if (!db.objectStoreNames.contains(DB_CONFIG.STORE_NAME)) {
|
|
107
|
+
db.createObjectStore(DB_CONFIG.STORE_NAME, { keyPath: 'key' })
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
request.onsuccess = (e) => {
|
|
112
|
+
resolve(e.target.result)
|
|
113
|
+
}
|
|
114
|
+
request.onerror = (e) => {
|
|
115
|
+
reject(e.currentTarget.error)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async openDB (callback) {
|
|
120
|
+
// 如果数据库不健康,直接调用回调并返回
|
|
121
|
+
if (!IS_DB_HEALTHY) {
|
|
122
|
+
console.warn('[openDB] 数据库不健康,跳过数据库操作')
|
|
123
|
+
setTimeout(() => {
|
|
124
|
+
try {
|
|
125
|
+
callback(null)
|
|
126
|
+
} catch (e) {
|
|
127
|
+
console.error('[openDB] 回调执行错误:', e)
|
|
128
|
+
}
|
|
129
|
+
}, 0)
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
if (this.db) {
|
|
135
|
+
const isAlive = await this.checkConnection()
|
|
136
|
+
if (isAlive) {
|
|
137
|
+
callback(this.db)
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// 添加超时机制,防止卡死
|
|
143
|
+
const openDbPromise = this.openDatabase()
|
|
144
|
+
const timeoutPromise = new Promise((resolve, reject) => {
|
|
145
|
+
setTimeout(() => reject(new Error('openDB timeout')), 5000)
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
this.db = await Promise.race([openDbPromise, timeoutPromise])
|
|
150
|
+
callback(this.db)
|
|
151
|
+
} catch (error) {
|
|
152
|
+
console.error('[openDB] 打开数据库连接超时或失败', error)
|
|
153
|
+
// 标记数据库为不健康状态,后续操作使用备用方案
|
|
154
|
+
IS_DB_HEALTHY = false
|
|
155
|
+
try {
|
|
156
|
+
callback(null)
|
|
157
|
+
} catch (callbackError) {
|
|
158
|
+
console.error('[openDB] 回调执行错误:', callbackError)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
} catch (error) {
|
|
162
|
+
console.error('[openDB] 数据库操作失败:', error)
|
|
163
|
+
|
|
164
|
+
// 版本错误时尝试重建数据库
|
|
165
|
+
if (error.message?.includes('version')) {
|
|
166
|
+
try {
|
|
167
|
+
await this.recreateDatabase()
|
|
168
|
+
callback(this.db)
|
|
169
|
+
} catch (rebuildError) {
|
|
170
|
+
console.error('[openDB] 重建失败,标记数据库为不健康状态', rebuildError)
|
|
171
|
+
IS_DB_HEALTHY = false
|
|
172
|
+
try {
|
|
173
|
+
callback(null)
|
|
174
|
+
} catch (callbackError) {
|
|
175
|
+
console.error('[openDB] 回调执行错误:', callbackError)
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
// 其他错误,标记为不健康并使用备用方案
|
|
180
|
+
IS_DB_HEALTHY = false
|
|
181
|
+
console.error('[openDB] 不可恢复的错误,标记数据库为不健康状态')
|
|
182
|
+
try {
|
|
183
|
+
callback(null)
|
|
184
|
+
} catch (callbackError) {
|
|
185
|
+
console.error('[openDB] 回调执行错误:', callbackError)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async checkConnection () {
|
|
192
|
+
try {
|
|
193
|
+
const transaction = this.db.transaction([DB_CONFIG.STORE_NAME], 'readwrite')
|
|
194
|
+
const store = transaction.objectStore(DB_CONFIG.STORE_NAME)
|
|
195
|
+
await this.promisifyRequest(store.add({ key: 'alive', data: true }))
|
|
196
|
+
return true
|
|
197
|
+
} catch (error) {
|
|
198
|
+
return false
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
promisifyRequest (request) {
|
|
203
|
+
return new Promise((resolve, reject) => {
|
|
204
|
+
request.onsuccess = () => {
|
|
205
|
+
resolve(request.result)
|
|
206
|
+
}
|
|
207
|
+
request.onerror = () => {
|
|
208
|
+
reject(request.error)
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async getByWeb (key, url, params, callback, processFun) {
|
|
214
|
+
// 数据库不健康时使用备用方案
|
|
215
|
+
if (!IS_DB_HEALTHY) {
|
|
216
|
+
console.warn(`[getByWeb] 数据库不健康,使用内存缓存或直接API调用`)
|
|
217
|
+
return this.getByWebWithoutDB(key, url, params, callback, processFun)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// 锁机制:防止同一键的并发请求
|
|
221
|
+
if (this.locks.has(key)) {
|
|
222
|
+
const timeoutPromise = new Promise((resolve, reject) => {
|
|
223
|
+
setTimeout(() => {
|
|
224
|
+
reject(new Error(`请求超时: ${key}`))
|
|
225
|
+
}, this.requestTimeout)
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
try {
|
|
229
|
+
await Promise.race([this.locks.get(key), timeoutPromise])
|
|
230
|
+
return this.getByWeb(key, url, params, callback, processFun)
|
|
231
|
+
} catch (error) {
|
|
232
|
+
console.error(`[getByWeb] 等待锁期间出错或超时: ${error.message}`)
|
|
233
|
+
this.locks.delete(key)
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const lockPromise = (async () => {
|
|
238
|
+
try {
|
|
239
|
+
// 首先检查内存缓存
|
|
240
|
+
if (USE_MEMORY_CACHE && MEMORY_CACHE.has(key)) {
|
|
241
|
+
const cachedData = MEMORY_CACHE.get(key)
|
|
242
|
+
callback(cachedData)
|
|
243
|
+
return
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// 再检查IndexedDB缓存
|
|
247
|
+
const data = DB_CONFIG.NAME === LIULI_WEB_DB_NAME ? undefined : await this.getData(key)
|
|
248
|
+
|
|
249
|
+
if (data && data.ERROR) {
|
|
250
|
+
console.error(`获取配置失败:` + data.ERROR)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (!data && url) {
|
|
254
|
+
// 缓存未命中,请求网络数据
|
|
255
|
+
// 获取当前 Logic 的 abortSignal,支持 cancel 模式(使用动态导入避免循环依赖)
|
|
256
|
+
let abortSignal = null
|
|
257
|
+
let abortControllerInfo = 'none'
|
|
258
|
+
try {
|
|
259
|
+
const LogicRunner = (await import('../logic/LogicRunner')).default
|
|
260
|
+
abortSignal = LogicRunner.getCurrentAbortSignal()
|
|
261
|
+
abortControllerInfo = abortSignal ? `aborted: ${abortSignal.aborted}, reason: ${abortSignal.reason}` : 'null'
|
|
262
|
+
} catch (e) {
|
|
263
|
+
console.log('[indexedDB.getByWeb] 获取 abortSignal 失败:', e.message)
|
|
264
|
+
}
|
|
265
|
+
console.log('[indexedDB.getByWeb] 发起请求,signal 状态:', abortControllerInfo)
|
|
266
|
+
|
|
267
|
+
let res
|
|
268
|
+
try {
|
|
269
|
+
res = await post(url, params, { signal: abortSignal })
|
|
270
|
+
} catch (e) {
|
|
271
|
+
// 重新抛出 AbortError,让上层可以正确处理取消逻辑
|
|
272
|
+
// 而不是把错误当作正常结果返回
|
|
273
|
+
// axios 取消请求时会抛出 CanceledError 或 AbortError
|
|
274
|
+
const errorName = e.name || ''
|
|
275
|
+
const errorCode = e.code || ''
|
|
276
|
+
if (errorName === 'CanceledError' || errorName === 'AbortError' || errorCode === 'ERR_CANCELED') {
|
|
277
|
+
console.log('[indexedDB.getByWeb] 请求被取消,抛出错误')
|
|
278
|
+
throw e
|
|
279
|
+
}
|
|
280
|
+
res = {
|
|
281
|
+
ERROR: e
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const processedData = processFun ? processFun(res) : res
|
|
285
|
+
|
|
286
|
+
// 同时保存到内存缓存
|
|
287
|
+
if (USE_MEMORY_CACHE) {
|
|
288
|
+
MEMORY_CACHE.set(key, processedData)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// 生产环境或非移动配置时保存到IndexedDB
|
|
292
|
+
if (process.env.NODE_ENV === 'production' || key !== 'webMobileConfig') {
|
|
293
|
+
await this.add(key, processedData)
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
callback(processedData)
|
|
297
|
+
} else {
|
|
298
|
+
// 使用缓存数据
|
|
299
|
+
if (USE_MEMORY_CACHE && data) {
|
|
300
|
+
MEMORY_CACHE.set(key, data)
|
|
301
|
+
}
|
|
302
|
+
callback(data)
|
|
303
|
+
}
|
|
304
|
+
} catch (error) {
|
|
305
|
+
console.error(`[getByWeb] 获取数据失败`, error)
|
|
306
|
+
|
|
307
|
+
// IndexedDB操作失败时切换到备用方案
|
|
308
|
+
if (error.name === 'InvalidStateError' || error.message?.includes('database') || error.message?.includes('transaction')) {
|
|
309
|
+
console.error(`[getByWeb] 数据库操作失败,标记为不健康`)
|
|
310
|
+
IS_DB_HEALTHY = false
|
|
311
|
+
|
|
312
|
+
// 使用备用方案获取数据
|
|
313
|
+
return this.getByWebWithoutDB(key, url, params, callback, processFun)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (process.env.NODE_ENV === 'production' && key !== 'webMobileConfig') {
|
|
317
|
+
await this.add(key, null)
|
|
318
|
+
}
|
|
319
|
+
callback(null)
|
|
320
|
+
}
|
|
321
|
+
})()
|
|
322
|
+
|
|
323
|
+
this.locks.set(key, lockPromise)
|
|
324
|
+
|
|
325
|
+
try {
|
|
326
|
+
const timeoutPromise = new Promise((resolve, reject) => {
|
|
327
|
+
setTimeout(() => {
|
|
328
|
+
reject(new Error(`操作超时: ${key}`))
|
|
329
|
+
}, this.requestTimeout)
|
|
330
|
+
})
|
|
331
|
+
|
|
332
|
+
await Promise.race([this.locks.get(key), timeoutPromise])
|
|
333
|
+
} catch (error) {
|
|
334
|
+
console.error(`[getByWeb] 执行期间出错或超时: ${error.message}`)
|
|
335
|
+
} finally {
|
|
336
|
+
this.locks.delete(key)
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// 备用方法:不使用IndexedDB,直接使用内存缓存和API
|
|
341
|
+
async getByWebWithoutDB (key, url, params, callback, processFun) {
|
|
342
|
+
// 首先检查内存缓存
|
|
343
|
+
if (USE_MEMORY_CACHE && MEMORY_CACHE.has(key)) {
|
|
344
|
+
const cachedData = MEMORY_CACHE.get(key)
|
|
345
|
+
callback(cachedData)
|
|
346
|
+
return
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// 无URL则无法获取数据
|
|
350
|
+
if (!url) {
|
|
351
|
+
callback(null)
|
|
352
|
+
return
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// 获取当前 Logic 的 abortSignal,支持 cancel 模式(使用动态导入避免循环依赖)
|
|
356
|
+
let abortSignal = null
|
|
357
|
+
try {
|
|
358
|
+
const LogicRunner = (await import('../logic/LogicRunner')).default
|
|
359
|
+
abortSignal = LogicRunner.getCurrentAbortSignal()
|
|
360
|
+
} catch (e) {
|
|
361
|
+
// 如果导入失败,使用 null
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// 直接通过API获取数据
|
|
365
|
+
try {
|
|
366
|
+
const res = await post(url, params, { signal: abortSignal })
|
|
367
|
+
const processedData = processFun ? processFun(res) : res
|
|
368
|
+
|
|
369
|
+
// 保存到内存缓存
|
|
370
|
+
if (USE_MEMORY_CACHE) {
|
|
371
|
+
MEMORY_CACHE.set(key, processedData)
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
callback(processedData)
|
|
375
|
+
} catch (error) {
|
|
376
|
+
// 重新抛出 AbortError,让上层可以正确处理取消逻辑
|
|
377
|
+
const errorName = error.name || ''
|
|
378
|
+
const errorCode = error.code || ''
|
|
379
|
+
if (errorName === 'CanceledError' || errorName === 'AbortError' || errorCode === 'ERR_CANCELED') {
|
|
380
|
+
console.log('[getByWebWithoutDB] 请求被取消,抛出错误')
|
|
381
|
+
throw error
|
|
382
|
+
}
|
|
383
|
+
console.error(`[getByWebWithoutDB] 获取数据失败: ${error.message}`)
|
|
384
|
+
callback(null)
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
async getData (key) {
|
|
389
|
+
return new Promise((resolve) => {
|
|
390
|
+
this.openDB((db) => {
|
|
391
|
+
if (!db) {
|
|
392
|
+
resolve(null)
|
|
393
|
+
return
|
|
394
|
+
}
|
|
395
|
+
const store = db.transaction(DB_CONFIG.STORE_NAME, 'readwrite').objectStore(DB_CONFIG.STORE_NAME)
|
|
396
|
+
const request = store.get(key)
|
|
397
|
+
|
|
398
|
+
request.onsuccess = (e) => {
|
|
399
|
+
resolve(e.target.result?.data)
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
request.onerror = () => {
|
|
403
|
+
resolve(null)
|
|
404
|
+
}
|
|
405
|
+
})
|
|
406
|
+
})
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
async add (key, data) {
|
|
410
|
+
this.openDB((db) => {
|
|
411
|
+
if (!db) return
|
|
412
|
+
|
|
413
|
+
const store = db.transaction(DB_CONFIG.STORE_NAME, 'readwrite').objectStore(DB_CONFIG.STORE_NAME)
|
|
414
|
+
const request = store.add({ key, data })
|
|
415
|
+
|
|
416
|
+
request.onerror = () => {
|
|
417
|
+
// 添加失败时尝试更新
|
|
418
|
+
this.update(key, data)
|
|
419
|
+
}
|
|
420
|
+
})
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
async update (key, data) {
|
|
424
|
+
this.openDB((db) => {
|
|
425
|
+
if (!db) return
|
|
426
|
+
|
|
427
|
+
const store = db.transaction(DB_CONFIG.STORE_NAME, 'readwrite').objectStore(DB_CONFIG.STORE_NAME)
|
|
428
|
+
store.put({ key, data })
|
|
429
|
+
})
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
async delete (key) {
|
|
433
|
+
this.openDB((db) => {
|
|
434
|
+
if (!db) return
|
|
435
|
+
|
|
436
|
+
const store = db.transaction(DB_CONFIG.STORE_NAME, 'readwrite').objectStore(DB_CONFIG.STORE_NAME)
|
|
437
|
+
store.delete(key)
|
|
438
|
+
})
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
async clear (callback) {
|
|
442
|
+
this.openDB((db) => {
|
|
443
|
+
if (!db) {
|
|
444
|
+
if (typeof callback === 'function') callback()
|
|
445
|
+
return
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
const store = db.transaction(DB_CONFIG.STORE_NAME, 'readwrite').objectStore(DB_CONFIG.STORE_NAME)
|
|
449
|
+
const request = store.clear()
|
|
450
|
+
|
|
451
|
+
request.onerror = () => {
|
|
452
|
+
if (typeof callback === 'function') callback()
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
request.onsuccess = () => {
|
|
456
|
+
if (typeof callback === 'function') callback()
|
|
457
|
+
}
|
|
458
|
+
})
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
clearCache () {
|
|
462
|
+
// 清除缓存并刷新页面
|
|
463
|
+
if (this.indexedDB) {
|
|
464
|
+
this.clear(() => {
|
|
465
|
+
location.reload()
|
|
466
|
+
})
|
|
467
|
+
} else {
|
|
468
|
+
location.reload()
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
async getAll () {
|
|
473
|
+
return new Promise((resolve, reject) => {
|
|
474
|
+
this.openDB((db) => {
|
|
475
|
+
if (!db) {
|
|
476
|
+
resolve([])
|
|
477
|
+
return
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
const store = db.transaction(DB_CONFIG.STORE_NAME, 'readonly').objectStore(DB_CONFIG.STORE_NAME)
|
|
481
|
+
const request = store.getAll()
|
|
482
|
+
|
|
483
|
+
request.onsuccess = (e) => {
|
|
484
|
+
resolve(e.target.result)
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
request.onerror = (e) => {
|
|
488
|
+
reject(e.target.error)
|
|
489
|
+
}
|
|
490
|
+
})
|
|
491
|
+
})
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
getAllLegacy (callback) {
|
|
495
|
+
this.openDB((res) => {
|
|
496
|
+
if (!res) {
|
|
497
|
+
callback(null, new Error('打开数据库失败'))
|
|
498
|
+
return
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
const store = res.transaction(DB_CONFIG.STORE_NAME, 'readonly').objectStore(DB_CONFIG.STORE_NAME)
|
|
502
|
+
const request = store.getAll()
|
|
503
|
+
|
|
504
|
+
request.onerror = (e) => {
|
|
505
|
+
callback(null, e.target.error)
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
request.onsuccess = (e) => {
|
|
509
|
+
callback(e.target.result)
|
|
510
|
+
}
|
|
511
|
+
})
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
async recreateDatabase () {
|
|
515
|
+
try {
|
|
516
|
+
if (this.db) {
|
|
517
|
+
this.db.close()
|
|
518
|
+
this.db = undefined
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
await new Promise((resolve, reject) => {
|
|
522
|
+
const deleteRequest = this.indexedDB.deleteDatabase(DB_CONFIG.NAME)
|
|
523
|
+
|
|
524
|
+
deleteRequest.onsuccess = () => {
|
|
525
|
+
resolve()
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
deleteRequest.onerror = (e) => {
|
|
529
|
+
reject(e.target.error)
|
|
530
|
+
}
|
|
531
|
+
})
|
|
532
|
+
|
|
533
|
+
DB_CONFIG.CURRENT_VERSION = DB_CONFIG.VERSION
|
|
534
|
+
this.db = await this.openDatabase()
|
|
535
|
+
return this.db
|
|
536
|
+
} catch (error) {
|
|
537
|
+
console.error('重新创建数据库失败:', error)
|
|
538
|
+
throw error
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// 强制重建数据库的方法,带有超时保护
|
|
543
|
+
async forceRecreateDatabase () {
|
|
544
|
+
console.warn('[forceRecreateDatabase] 开始强制重建数据库')
|
|
545
|
+
try {
|
|
546
|
+
// 确保关闭所有连接
|
|
547
|
+
if (this.db) {
|
|
548
|
+
try {
|
|
549
|
+
this.db.close()
|
|
550
|
+
} catch (e) {
|
|
551
|
+
console.warn('[forceRecreateDatabase] 关闭现有连接出错')
|
|
552
|
+
}
|
|
553
|
+
this.db = undefined
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// 清空锁防止死锁
|
|
557
|
+
this.locks.clear()
|
|
558
|
+
|
|
559
|
+
// 强制删除数据库,带超时保护
|
|
560
|
+
await new Promise((resolve) => {
|
|
561
|
+
const deleteRequest = this.indexedDB.deleteDatabase(DB_CONFIG.NAME)
|
|
562
|
+
|
|
563
|
+
const timeout = setTimeout(() => {
|
|
564
|
+
resolve() // 即使超时也继续执行
|
|
565
|
+
}, 3000)
|
|
566
|
+
|
|
567
|
+
deleteRequest.onsuccess = () => {
|
|
568
|
+
clearTimeout(timeout)
|
|
569
|
+
resolve()
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
deleteRequest.onerror = () => {
|
|
573
|
+
clearTimeout(timeout)
|
|
574
|
+
resolve() // 即使出错也继续执行
|
|
575
|
+
}
|
|
576
|
+
})
|
|
577
|
+
|
|
578
|
+
// 重置版本
|
|
579
|
+
DB_CONFIG.CURRENT_VERSION = DB_CONFIG.VERSION
|
|
580
|
+
} catch (error) {
|
|
581
|
+
console.error('[forceRecreateDatabase] 强制重建过程中出错:', error)
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
export const indexedDB = new IndexedDBManager()
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="JAVA_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
+
<exclude-output />
|
|
5
|
+
<content url="file://$MODULE_DIR$" />
|
|
6
|
+
<orderEntry type="inheritedJdk" />
|
|
7
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
8
|
+
</component>
|
|
9
|
+
</module>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<component name="ProjectCodeStyleConfiguration">
|
|
2
|
+
<code_scheme name="Project" version="173">
|
|
3
|
+
<option name="LINE_SEPARATOR" value=" " />
|
|
4
|
+
<HTMLCodeStyleSettings>
|
|
5
|
+
<option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
|
|
6
|
+
</HTMLCodeStyleSettings>
|
|
7
|
+
<JSCodeStyleSettings version="0">
|
|
8
|
+
<option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
|
|
9
|
+
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
10
|
+
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
|
11
|
+
<option name="USE_DOUBLE_QUOTES" value="false" />
|
|
12
|
+
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
13
|
+
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
|
|
14
|
+
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
|
15
|
+
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
|
16
|
+
</JSCodeStyleSettings>
|
|
17
|
+
<TypeScriptCodeStyleSettings version="0">
|
|
18
|
+
<option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
|
|
19
|
+
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
20
|
+
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
|
21
|
+
<option name="USE_DOUBLE_QUOTES" value="false" />
|
|
22
|
+
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
23
|
+
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
|
|
24
|
+
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
|
25
|
+
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
|
26
|
+
</TypeScriptCodeStyleSettings>
|
|
27
|
+
<VueCodeStyleSettings>
|
|
28
|
+
<option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
|
|
29
|
+
<option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
|
|
30
|
+
</VueCodeStyleSettings>
|
|
31
|
+
<codeStyleSettings language="HTML">
|
|
32
|
+
<option name="SOFT_MARGINS" value="120" />
|
|
33
|
+
<indentOptions>
|
|
34
|
+
<option name="INDENT_SIZE" value="2" />
|
|
35
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
36
|
+
<option name="TAB_SIZE" value="2" />
|
|
37
|
+
</indentOptions>
|
|
38
|
+
</codeStyleSettings>
|
|
39
|
+
<codeStyleSettings language="JavaScript">
|
|
40
|
+
<option name="SOFT_MARGINS" value="120" />
|
|
41
|
+
<indentOptions>
|
|
42
|
+
<option name="INDENT_SIZE" value="2" />
|
|
43
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
44
|
+
<option name="TAB_SIZE" value="2" />
|
|
45
|
+
</indentOptions>
|
|
46
|
+
</codeStyleSettings>
|
|
47
|
+
<codeStyleSettings language="TypeScript">
|
|
48
|
+
<option name="SOFT_MARGINS" value="120" />
|
|
49
|
+
<indentOptions>
|
|
50
|
+
<option name="INDENT_SIZE" value="2" />
|
|
51
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
52
|
+
<option name="TAB_SIZE" value="2" />
|
|
53
|
+
</indentOptions>
|
|
54
|
+
</codeStyleSettings>
|
|
55
|
+
<codeStyleSettings language="Vue">
|
|
56
|
+
<option name="SOFT_MARGINS" value="120" />
|
|
57
|
+
<indentOptions>
|
|
58
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
59
|
+
</indentOptions>
|
|
60
|
+
</codeStyleSettings>
|
|
61
|
+
</code_scheme>
|
|
62
|
+
</component>
|
package/.idea/misc.xml
ADDED
package/.idea/modules.xml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<project version="4">
|
|
3
3
|
<component name="ProjectModuleManager">
|
|
4
4
|
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/vue2-client.iml" filepath="$PROJECT_DIR$/.idea/vue2-client.iml" />
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/af-vue2-client.iml" filepath="$PROJECT_DIR$/.idea/af-vue2-client.iml" />
|
|
6
6
|
</modules>
|
|
7
7
|
</component>
|
|
8
8
|
</project>
|