fdb2 1.0.8 → 1.0.9

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 (235) hide show
  1. package/.dockerignore +21 -21
  2. package/.editorconfig +11 -11
  3. package/.eslintrc.cjs +14 -14
  4. package/.eslintrc.json +7 -7
  5. package/.prettierrc.js +3 -3
  6. package/.tpl.env +21 -21
  7. package/.vscodeignore +45 -45
  8. package/README.md +312 -312
  9. package/bin/build.sh +28 -28
  10. package/bin/deploy.sh +8 -8
  11. package/bin/dev.sh +10 -10
  12. package/bin/docker/dev-docker-compose.yml +43 -43
  13. package/bin/docker/dev.Dockerfile +24 -24
  14. package/bin/docker/prod-docker-compose.yml +17 -17
  15. package/bin/docker/prod.Dockerfile +29 -29
  16. package/bin/fdb2.js +220 -220
  17. package/dist/package.json +29 -29
  18. package/dist/pnpm-lock.yaml +1042 -354
  19. package/dist/public/explorer.css +1464 -1437
  20. package/dist/public/explorer.js +759 -223
  21. package/dist/public/index.css +1026 -1026
  22. package/dist/public/index.js +15 -9
  23. package/dist/public/layout.css +221 -221
  24. package/dist/public/layout.js +1 -1
  25. package/dist/public/vue.js +8 -2
  26. package/dist/scripts/preinstall.js +112 -112
  27. package/dist/server/index.d.ts.map +1 -1
  28. package/dist/server/index.js +8 -0
  29. package/dist/server/index.js.map +1 -1
  30. package/dist/server/index.ts +680 -671
  31. package/dist/server/model/connection.entity.ts +65 -65
  32. package/dist/server/model/database.entity.ts +245 -245
  33. package/dist/server/service/connection.service.d.ts +6 -1
  34. package/dist/server/service/connection.service.d.ts.map +1 -1
  35. package/dist/server/service/connection.service.js +15 -0
  36. package/dist/server/service/connection.service.js.map +1 -1
  37. package/dist/server/service/connection.service.ts +356 -341
  38. package/dist/server/service/database/base.service.d.ts +27 -0
  39. package/dist/server/service/database/base.service.d.ts.map +1 -1
  40. package/dist/server/service/database/base.service.js +17 -0
  41. package/dist/server/service/database/base.service.js.map +1 -1
  42. package/dist/server/service/database/base.service.ts +406 -367
  43. package/dist/server/service/database/cockroachdb.service.d.ts +16 -0
  44. package/dist/server/service/database/cockroachdb.service.d.ts.map +1 -1
  45. package/dist/server/service/database/cockroachdb.service.js +220 -154
  46. package/dist/server/service/database/cockroachdb.service.js.map +1 -1
  47. package/dist/server/service/database/cockroachdb.service.ts +871 -782
  48. package/dist/server/service/database/database.service.d.ts +4 -0
  49. package/dist/server/service/database/database.service.d.ts.map +1 -1
  50. package/dist/server/service/database/database.service.js +123 -0
  51. package/dist/server/service/database/database.service.js.map +1 -1
  52. package/dist/server/service/database/database.service.ts +775 -638
  53. package/dist/server/service/database/index.ts +6 -6
  54. package/dist/server/service/database/mongodb.service.d.ts +16 -0
  55. package/dist/server/service/database/mongodb.service.d.ts.map +1 -1
  56. package/dist/server/service/database/mongodb.service.js +35 -0
  57. package/dist/server/service/database/mongodb.service.js.map +1 -1
  58. package/dist/server/service/database/mongodb.service.ts +39 -1
  59. package/dist/server/service/database/mssql.service.d.ts +16 -0
  60. package/dist/server/service/database/mssql.service.d.ts.map +1 -1
  61. package/dist/server/service/database/mssql.service.js +168 -96
  62. package/dist/server/service/database/mssql.service.js.map +1 -1
  63. package/dist/server/service/database/mssql.service.ts +931 -840
  64. package/dist/server/service/database/mysql.service.d.ts +16 -0
  65. package/dist/server/service/database/mysql.service.d.ts.map +1 -1
  66. package/dist/server/service/database/mysql.service.js +189 -80
  67. package/dist/server/service/database/mysql.service.js.map +1 -1
  68. package/dist/server/service/database/mysql.service.ts +1025 -890
  69. package/dist/server/service/database/oracle.service.d.ts +16 -0
  70. package/dist/server/service/database/oracle.service.d.ts.map +1 -1
  71. package/dist/server/service/database/oracle.service.js +182 -120
  72. package/dist/server/service/database/oracle.service.js.map +1 -1
  73. package/dist/server/service/database/oracle.service.ts +1035 -959
  74. package/dist/server/service/database/postgres.service.d.ts +16 -0
  75. package/dist/server/service/database/postgres.service.d.ts.map +1 -1
  76. package/dist/server/service/database/postgres.service.js +154 -88
  77. package/dist/server/service/database/postgres.service.js.map +1 -1
  78. package/dist/server/service/database/postgres.service.ts +960 -871
  79. package/dist/server/service/database/sap.service.d.ts +16 -0
  80. package/dist/server/service/database/sap.service.d.ts.map +1 -1
  81. package/dist/server/service/database/sap.service.js +66 -0
  82. package/dist/server/service/database/sap.service.js.map +1 -1
  83. package/dist/server/service/database/sap.service.ts +89 -0
  84. package/dist/server/service/database/sqlite.service.d.ts +16 -0
  85. package/dist/server/service/database/sqlite.service.d.ts.map +1 -1
  86. package/dist/server/service/database/sqlite.service.js +77 -18
  87. package/dist/server/service/database/sqlite.service.js.map +1 -1
  88. package/dist/server/service/database/sqlite.service.ts +787 -708
  89. package/dist/server/service/session.service.ts +158 -158
  90. package/dist/view/index.html +38 -38
  91. package/env.d.ts +1 -1
  92. package/package.json +1 -1
  93. package/packages/vscode/.vscodeignore +44 -44
  94. package/packages/vscode/README.md +62 -62
  95. package/packages/vscode/out/database-services/cockroachdb.service.js +154 -154
  96. package/packages/vscode/out/database-services/mssql.service.js +96 -96
  97. package/packages/vscode/out/database-services/mysql.service.js +80 -80
  98. package/packages/vscode/out/database-services/oracle.service.js +120 -120
  99. package/packages/vscode/out/database-services/postgres.service.js +88 -88
  100. package/packages/vscode/out/database-services/sqlite.service.js +18 -18
  101. package/packages/vscode/out/provider/WebViewProvider.js +32 -32
  102. package/packages/vscode/package.json +142 -142
  103. package/packages/vscode/resources/icon.svg +5 -5
  104. package/packages/vscode/resources/webview/connection.css +41 -41
  105. package/packages/vscode/resources/webview/database.css +163 -163
  106. package/packages/vscode/resources/webview/index.html +9 -9
  107. package/packages/vscode/resources/webview/modules/header.tpl +13 -13
  108. package/packages/vscode/resources/webview/modules/initial_state.tpl +54 -54
  109. package/packages/vscode/resources/webview/query.css +104 -104
  110. package/packages/vscode/src/database-services/base.service.ts +362 -362
  111. package/packages/vscode/src/database-services/cockroachdb.service.ts +659 -659
  112. package/packages/vscode/src/database-services/connection.service.ts +340 -340
  113. package/packages/vscode/src/database-services/database.service.ts +629 -629
  114. package/packages/vscode/src/database-services/index.ts +6 -6
  115. package/packages/vscode/src/database-services/model/connection.entity.ts +65 -65
  116. package/packages/vscode/src/database-services/model/database.entity.ts +245 -245
  117. package/packages/vscode/src/database-services/mssql.service.ts +722 -722
  118. package/packages/vscode/src/database-services/mysql.service.ts +760 -760
  119. package/packages/vscode/src/database-services/oracle.service.ts +831 -831
  120. package/packages/vscode/src/database-services/postgres.service.ts +740 -740
  121. package/packages/vscode/src/database-services/sqlite.service.ts +558 -558
  122. package/packages/vscode/src/extension.ts +76 -76
  123. package/packages/vscode/src/provider/DatabaseTreeProvider.ts +167 -167
  124. package/packages/vscode/src/provider/WebViewProvider.ts +277 -277
  125. package/packages/vscode/src/service/DatabaseServiceBridge.ts +414 -414
  126. package/packages/vscode/src/typings/connection.ts +90 -90
  127. package/packages/vscode/tsconfig.json +21 -21
  128. package/public/index.html +9 -9
  129. package/public/modules/header.tpl +13 -13
  130. package/public/modules/initial_state.tpl +54 -54
  131. package/scripts/preinstall.js +112 -112
  132. package/server/index.ts +680 -671
  133. package/server/model/connection.entity.ts +65 -65
  134. package/server/model/database.entity.ts +245 -245
  135. package/server/service/connection.service.ts +356 -341
  136. package/server/service/database/base.service.ts +406 -367
  137. package/server/service/database/cockroachdb.service.ts +871 -782
  138. package/server/service/database/database.service.ts +775 -638
  139. package/server/service/database/index.ts +6 -6
  140. package/server/service/database/mongodb.service.ts +39 -1
  141. package/server/service/database/mssql.service.ts +931 -840
  142. package/server/service/database/mysql.service.ts +1025 -890
  143. package/server/service/database/oracle.service.ts +1035 -959
  144. package/server/service/database/postgres.service.ts +960 -871
  145. package/server/service/database/sap.service.ts +89 -0
  146. package/server/service/database/sqlite.service.ts +787 -708
  147. package/server/service/session.service.ts +158 -158
  148. package/server/tsconfig.json +20 -20
  149. package/server.js +149 -149
  150. package/server.pid +1 -0
  151. package/src/adapter/ajax.ts +135 -135
  152. package/src/assets/base.css +1 -1
  153. package/src/assets/database.css +949 -949
  154. package/src/assets/images/svg/illustrations/illustration-1.svg +1 -1
  155. package/src/assets/images/svg/illustrations/illustration-2.svg +2 -2
  156. package/src/assets/images/svg/illustrations/illustration-3.svg +50 -50
  157. package/src/assets/images/svg/illustrations/illustration-4.svg +1 -1
  158. package/src/assets/images/svg/illustrations/illustration-5.svg +73 -73
  159. package/src/assets/images/svg/illustrations/illustration-6.svg +89 -89
  160. package/src/assets/images/svg/illustrations/illustration-7.svg +39 -39
  161. package/src/assets/images/svg/separators/curve-2.svg +3 -3
  162. package/src/assets/images/svg/separators/curve.svg +3 -3
  163. package/src/assets/images/svg/separators/line.svg +3 -3
  164. package/src/assets/logo.svg +73 -73
  165. package/src/assets/main.css +1 -1
  166. package/src/base/config.ts +20 -20
  167. package/src/base/detect.ts +134 -134
  168. package/src/base/entity.ts +92 -92
  169. package/src/base/eventBus.ts +36 -36
  170. package/src/components/connection-editor/index.vue +588 -588
  171. package/src/components/dataGrid/index.vue +104 -104
  172. package/src/components/dataGrid/pagination.vue +105 -105
  173. package/src/components/loading/index.vue +42 -42
  174. package/src/components/modal/index.ts +180 -180
  175. package/src/components/modal/index.vue +560 -560
  176. package/src/components/toast/index.ts +43 -43
  177. package/src/components/toast/toast.vue +57 -57
  178. package/src/components/user/name.vue +103 -103
  179. package/src/components/user/selector.vue +416 -416
  180. package/src/domain/SysConfig.ts +74 -74
  181. package/src/platform/App.vue +7 -7
  182. package/src/platform/database/components/connection-detail.vue +1153 -1154
  183. package/src/platform/database/components/data-editor.vue +477 -477
  184. package/src/platform/database/components/database-detail.vue +1173 -1172
  185. package/src/platform/database/components/database-monitor.vue +1085 -1085
  186. package/src/platform/database/components/db-tools.vue +1264 -816
  187. package/src/platform/database/components/query-history.vue +1348 -1348
  188. package/src/platform/database/components/sql-executor.vue +737 -737
  189. package/src/platform/database/components/sql-query-editor.vue +1045 -1045
  190. package/src/platform/database/components/table-detail.vue +1375 -1376
  191. package/src/platform/database/components/table-editor.vue +916 -916
  192. package/src/platform/database/explorer.vue +1839 -1839
  193. package/src/platform/database/index.vue +1192 -1192
  194. package/src/platform/database/layout.vue +366 -366
  195. package/src/platform/database/router.ts +36 -36
  196. package/src/platform/database/styles/common.scss +601 -601
  197. package/src/platform/database/types/common.ts +444 -444
  198. package/src/platform/database/utils/export.ts +231 -231
  199. package/src/platform/database/utils/helpers.ts +436 -436
  200. package/src/platform/index.ts +32 -32
  201. package/src/platform/router.ts +40 -40
  202. package/src/platform/vscode/bridge.ts +121 -121
  203. package/src/platform/vscode/components/ConnectionPanel.vue +272 -272
  204. package/src/platform/vscode/components/DatabasePanel.vue +532 -532
  205. package/src/platform/vscode/components/QueryPanel.vue +371 -371
  206. package/src/platform/vscode/entry/connection.ts +13 -13
  207. package/src/platform/vscode/entry/database.ts +13 -13
  208. package/src/platform/vscode/entry/query.ts +13 -13
  209. package/src/platform/vscode/index.ts +5 -5
  210. package/src/service/base.ts +133 -127
  211. package/src/service/database.ts +505 -495
  212. package/src/service/login.ts +120 -120
  213. package/src/shims-vue.d.ts +6 -6
  214. package/src/stores/connection.ts +266 -266
  215. package/src/stores/session.ts +87 -87
  216. package/src/typings/database-types.ts +412 -412
  217. package/src/typings/database.ts +363 -363
  218. package/src/typings/global.d.ts +58 -58
  219. package/src/typings/pinia.d.ts +7 -7
  220. package/src/utils/clipboard.ts +29 -29
  221. package/src/utils/database-types.ts +242 -242
  222. package/src/utils/modal.ts +123 -123
  223. package/src/utils/request.ts +55 -55
  224. package/src/utils/sleep.ts +3 -3
  225. package/src/utils/toast.ts +73 -73
  226. package/src/utils/util.ts +171 -171
  227. package/src/utils/xlsx.ts +228 -228
  228. package/tsconfig.json +33 -33
  229. package/view/index.html +9 -9
  230. package/view/modules/header.tpl +13 -13
  231. package/view/modules/initial_state.tpl +19 -19
  232. package/vite.config.ts +424 -424
  233. package/vite.config.vscode.ts +47 -47
  234. package/fdb2.server.pid +0 -1
  235. package/server/backups/db_ai_breakout_2026-03-11T08-38-48-677Z.sql +0 -0
@@ -1,181 +1,181 @@
1
- import { createApp, getCurrentInstance, nextTick } from 'vue';
2
- import BootstrapModal from './index.vue';
3
-
4
- export type ModalType = {
5
- show: () => void,
6
- hide: () => void,
7
- open: () => void,
8
- close: () => void,
9
- };
10
-
11
- // modal方法类型定义
12
- const modalMethods = {
13
- alert: {} as (options: ModalOptions | string) => Promise<boolean>,
14
- confirm: {} as (options: ModalOptions | string) => Promise<boolean>,
15
- success: {} as (content: string) => Promise<boolean>,
16
- error: {} as (content: string, details?: any) => Promise<boolean>,
17
- warning: {} as (content: string) => Promise<boolean>,
18
- info: {} as (content: string) => Promise<boolean>,
19
- showModal: {} as (options: ModalOptions) => Promise<boolean>
20
- };
21
-
22
- export type ModalTypeWithMethods = ModalType & typeof modalMethods;
23
-
24
- export type ModalOptions = {
25
- title?: string;
26
- content?: string;
27
- type?: 'success' | 'error' | 'warning' | 'info';
28
- confirmText?: string;
29
- cancelText?: string;
30
- showCancel?: boolean;
31
- details?: any;
32
- onConfirm?: () => void;
33
- onCancel?: () => void;
34
- };
35
-
36
- // 全局modal实例
37
- let globalModalInstance: any = null;
38
- let modalInstance: ModalTypeWithMethods;
39
-
40
- export default {
41
- install(app: any) {
42
- // 挂载到DOM
43
- const mount = document.createElement('div');
44
- document.body.appendChild(mount);
45
-
46
- // 创建实例
47
- const modalApp = createApp(BootstrapModal);
48
- globalModalInstance = modalApp.mount(mount) as any;
49
-
50
- // 添加事件监听,确保模态框完全隐藏后重置 isModalActive
51
- if (globalModalInstance && globalModalInstance.$el) {
52
- const modalElement = globalModalInstance.$el;
53
- modalElement.addEventListener('hidden.bs.modal', () => {
54
- isModalActive = false;
55
- console.log('Modal hidden, isModalActive reset to false');
56
-
57
- // 处理待显示的modal
58
- if (pendingModalOptions) {
59
- const pending = pendingModalOptions;
60
- pendingModalOptions = null;
61
- showModal(pending);
62
- }
63
- });
64
- }
65
-
66
- // 全局注入
67
- app.config.globalProperties.$modal = modalInstance = {
68
- show: () => globalModalInstance.show(),
69
- hide: () => globalModalInstance.hide(),
70
- open: () => globalModalInstance.show(),
71
- close: () => globalModalInstance.hide(),
72
- // 新增方法
73
- alert(options: ModalOptions | string) {
74
- const opts = typeof options === 'string'
75
- ? { content: options, type: 'info' as const, showCancel: false }
76
- : { ...options, showCancel: false };
77
- return showModal(opts);
78
- },
79
- confirm(options: ModalOptions | string) {
80
- const opts = typeof options === 'string'
81
- ? { content: options, type: 'warning' as const }
82
- : { ...options, showCancel: true };
83
- return showModal(opts);
84
- },
85
- success(content: string) {
86
- return this.alert({ content, type: 'success' as const, confirmText: '确定' });
87
- },
88
- error(content: string, details?: any) {
89
- return this.alert({ content, type: 'error' as const, confirmText: '确定', details });
90
- },
91
- warning(content: string) {
92
- return this.alert({ content, type: 'warning' as const, confirmText: '确定' });
93
- },
94
- info(content: string) {
95
- return this.alert({ content, type: 'info' as const, confirmText: '确定' });
96
- },
97
- } as ModalTypeWithMethods;
98
- },
99
- get() {
100
- const instance = getCurrentInstance();
101
- if(!instance ) return null;
102
- // @ts-ignore
103
- const modal = instance.appContext.config?.globalProperties?.$modal as ModalTypeWithMethods;
104
- return modal;
105
- }
106
- };
107
-
108
- export const getModalInstance = (): ModalTypeWithMethods => {
109
- return modalInstance;
110
- }
111
-
112
- // 全局modal状态管理
113
- let isModalActive = false;
114
- let pendingModalOptions: ModalOptions | null = null;
115
-
116
- // 导出便捷函数供非Vue环境使用
117
- export const showModal = (options: ModalOptions) => {
118
- if (!globalModalInstance) return Promise.resolve(false);
119
-
120
- return new Promise<boolean>((resolve) => {
121
- const finalOptions = {
122
- title: '提示',
123
- confirmText: '确定',
124
- cancelText: '取消',
125
- showCancel: false,
126
- type: 'info',
127
- ...options,
128
- onConfirm: () => {
129
- options.onConfirm?.();
130
- globalModalInstance.hide();
131
- nextTick(() => {
132
- resolve(true);
133
- });
134
- },
135
- onCancel: () => {
136
- options.onCancel?.();
137
- globalModalInstance.hide();
138
- nextTick(() => {
139
- resolve(false);
140
- });
141
- }
142
- };
143
-
144
- // 如果当前有modal正在显示,将新的请求加入队列
145
- if (isModalActive) {
146
- console.log('Modal busy, queuing new modal');
147
- pendingModalOptions = options;
148
- return;
149
- }
150
-
151
- // 显示新的modal
152
- const showModalInstance = () => {
153
- globalModalInstance.setOptions?.(finalOptions);
154
- isModalActive = true;
155
-
156
- // 使用Promise链确保正确的执行顺序
157
- return globalModalInstance.show?.() || Promise.resolve();
158
- };
159
-
160
- showModalInstance();
161
- });
162
- };
163
-
164
- export const showAlert = (content: string, type: 'success' | 'error' | 'warning' | 'info' = 'info', details?: any) => {
165
- return showModal({
166
- content,
167
- type,
168
- showCancel: false,
169
- details
170
- });
171
- };
172
-
173
- export const showConfirm = (content: string, options?: Omit<ModalOptions, 'content' | 'showCancel'>) => {
174
- return showModal({
175
- title: '确认',
176
- content,
177
- type: 'warning',
178
- showCancel: true,
179
- ...options
180
- });
1
+ import { createApp, getCurrentInstance, nextTick } from 'vue';
2
+ import BootstrapModal from './index.vue';
3
+
4
+ export type ModalType = {
5
+ show: () => void,
6
+ hide: () => void,
7
+ open: () => void,
8
+ close: () => void,
9
+ };
10
+
11
+ // modal方法类型定义
12
+ const modalMethods = {
13
+ alert: {} as (options: ModalOptions | string) => Promise<boolean>,
14
+ confirm: {} as (options: ModalOptions | string) => Promise<boolean>,
15
+ success: {} as (content: string) => Promise<boolean>,
16
+ error: {} as (content: string, details?: any) => Promise<boolean>,
17
+ warning: {} as (content: string) => Promise<boolean>,
18
+ info: {} as (content: string) => Promise<boolean>,
19
+ showModal: {} as (options: ModalOptions) => Promise<boolean>
20
+ };
21
+
22
+ export type ModalTypeWithMethods = ModalType & typeof modalMethods;
23
+
24
+ export type ModalOptions = {
25
+ title?: string;
26
+ content?: string;
27
+ type?: 'success' | 'error' | 'warning' | 'info';
28
+ confirmText?: string;
29
+ cancelText?: string;
30
+ showCancel?: boolean;
31
+ details?: any;
32
+ onConfirm?: () => void;
33
+ onCancel?: () => void;
34
+ };
35
+
36
+ // 全局modal实例
37
+ let globalModalInstance: any = null;
38
+ let modalInstance: ModalTypeWithMethods;
39
+
40
+ export default {
41
+ install(app: any) {
42
+ // 挂载到DOM
43
+ const mount = document.createElement('div');
44
+ document.body.appendChild(mount);
45
+
46
+ // 创建实例
47
+ const modalApp = createApp(BootstrapModal);
48
+ globalModalInstance = modalApp.mount(mount) as any;
49
+
50
+ // 添加事件监听,确保模态框完全隐藏后重置 isModalActive
51
+ if (globalModalInstance && globalModalInstance.$el) {
52
+ const modalElement = globalModalInstance.$el;
53
+ modalElement.addEventListener('hidden.bs.modal', () => {
54
+ isModalActive = false;
55
+ console.log('Modal hidden, isModalActive reset to false');
56
+
57
+ // 处理待显示的modal
58
+ if (pendingModalOptions) {
59
+ const pending = pendingModalOptions;
60
+ pendingModalOptions = null;
61
+ showModal(pending);
62
+ }
63
+ });
64
+ }
65
+
66
+ // 全局注入
67
+ app.config.globalProperties.$modal = modalInstance = {
68
+ show: () => globalModalInstance.show(),
69
+ hide: () => globalModalInstance.hide(),
70
+ open: () => globalModalInstance.show(),
71
+ close: () => globalModalInstance.hide(),
72
+ // 新增方法
73
+ alert(options: ModalOptions | string) {
74
+ const opts = typeof options === 'string'
75
+ ? { content: options, type: 'info' as const, showCancel: false }
76
+ : { ...options, showCancel: false };
77
+ return showModal(opts);
78
+ },
79
+ confirm(options: ModalOptions | string) {
80
+ const opts = typeof options === 'string'
81
+ ? { content: options, type: 'warning' as const }
82
+ : { ...options, showCancel: true };
83
+ return showModal(opts);
84
+ },
85
+ success(content: string) {
86
+ return this.alert({ content, type: 'success' as const, confirmText: '确定' });
87
+ },
88
+ error(content: string, details?: any) {
89
+ return this.alert({ content, type: 'error' as const, confirmText: '确定', details });
90
+ },
91
+ warning(content: string) {
92
+ return this.alert({ content, type: 'warning' as const, confirmText: '确定' });
93
+ },
94
+ info(content: string) {
95
+ return this.alert({ content, type: 'info' as const, confirmText: '确定' });
96
+ },
97
+ } as ModalTypeWithMethods;
98
+ },
99
+ get() {
100
+ const instance = getCurrentInstance();
101
+ if(!instance ) return null;
102
+ // @ts-ignore
103
+ const modal = instance.appContext.config?.globalProperties?.$modal as ModalTypeWithMethods;
104
+ return modal;
105
+ }
106
+ };
107
+
108
+ export const getModalInstance = (): ModalTypeWithMethods => {
109
+ return modalInstance;
110
+ }
111
+
112
+ // 全局modal状态管理
113
+ let isModalActive = false;
114
+ let pendingModalOptions: ModalOptions | null = null;
115
+
116
+ // 导出便捷函数供非Vue环境使用
117
+ export const showModal = (options: ModalOptions) => {
118
+ if (!globalModalInstance) return Promise.resolve(false);
119
+
120
+ return new Promise<boolean>((resolve) => {
121
+ const finalOptions = {
122
+ title: '提示',
123
+ confirmText: '确定',
124
+ cancelText: '取消',
125
+ showCancel: false,
126
+ type: 'info',
127
+ ...options,
128
+ onConfirm: () => {
129
+ options.onConfirm?.();
130
+ globalModalInstance.hide();
131
+ nextTick(() => {
132
+ resolve(true);
133
+ });
134
+ },
135
+ onCancel: () => {
136
+ options.onCancel?.();
137
+ globalModalInstance.hide();
138
+ nextTick(() => {
139
+ resolve(false);
140
+ });
141
+ }
142
+ };
143
+
144
+ // 如果当前有modal正在显示,将新的请求加入队列
145
+ if (isModalActive) {
146
+ console.log('Modal busy, queuing new modal');
147
+ pendingModalOptions = options;
148
+ return;
149
+ }
150
+
151
+ // 显示新的modal
152
+ const showModalInstance = () => {
153
+ globalModalInstance.setOptions?.(finalOptions);
154
+ isModalActive = true;
155
+
156
+ // 使用Promise链确保正确的执行顺序
157
+ return globalModalInstance.show?.() || Promise.resolve();
158
+ };
159
+
160
+ showModalInstance();
161
+ });
162
+ };
163
+
164
+ export const showAlert = (content: string, type: 'success' | 'error' | 'warning' | 'info' = 'info', details?: any) => {
165
+ return showModal({
166
+ content,
167
+ type,
168
+ showCancel: false,
169
+ details
170
+ });
171
+ };
172
+
173
+ export const showConfirm = (content: string, options?: Omit<ModalOptions, 'content' | 'showCancel'>) => {
174
+ return showModal({
175
+ title: '确认',
176
+ content,
177
+ type: 'warning',
178
+ showCancel: true,
179
+ ...options
180
+ });
181
181
  };