fdb2 1.0.7 → 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 (234) 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 +764 -226
  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/server/backups/db_ai_breakout_2026-03-11T08-38-48-677Z.sql +0 -0
@@ -1,560 +1,560 @@
1
- <template>
2
- <div class="modal fade" :id="modalId" ref="modalContainer" tabindex="-1" aria-labelledby="modalLabel">
3
- <div class="modal-dialog modal-dialog-centered" :class="{'modal-fullscreen': isFullScreen}" :style="dynamicStyle">
4
- <div class="modal-content" :class="contentClass" style=" margin: auto;">
5
- <div class="modal-header" :class="headerClass" style="padding: 1rem 1.5rem;">
6
- <h5 class="modal-title d-flex align-items-center" id="modalLabel">
7
- <i v-if="typeIcon" :class="typeIcon" class="me-2"></i>
8
- {{dynamicTitle || props.title}}
9
- </h5>
10
- <button type="button" class="btn-close" aria-label="Close" @click="cancel"></button>
11
- </div>
12
- <div class="modal-body text-wrap" v-if="modalShow">
13
- <slot v-if="$slots.default"></slot>
14
- <div v-else>
15
- <div class="d-flex align-items-center mb-3">
16
- <i v-if="typeIcon" :class="typeIcon" class="me-3 fs-1"></i>
17
- <div class="flex-grow-1 text-wrap">{{dynamicContent}}</div>
18
- </div>
19
- <div v-if="shouldShowDetails()" class="error-details-toggle mt-2">
20
- <button class="btn btn-sm btn-outline-secondary" @click="toggleDetails">
21
- {{detailsExpanded ? '隐藏' : '详情'}}
22
- <i class="bi bi-chevron-{{detailsExpanded ? 'up' : 'down'}} ms-1"></i>
23
- </button>
24
- <div v-if="detailsExpanded" class="error-details-content mt-2">
25
- <pre class="error-json">{{formatErrorDetails()}}</pre>
26
- </div>
27
- </div>
28
- </div>
29
- </div>
30
- <div class="modal-footer">
31
- <slot name="footer" v-if="$slots.footer"></slot>
32
- <template v-else>
33
- <button type="button"
34
- v-if="dynamicShowCancel || props.closeButton.show"
35
- class="btn btn-secondary"
36
- @click="cancel">
37
- {{dynamicCancelText || props.closeButton.text}}
38
- </button>
39
- <button type="button"
40
- v-if="props.confirmButton.show"
41
- class="btn"
42
- :class="confirmButtonClass"
43
- @click="confirm">
44
- {{dynamicConfirmText || props.confirmButton.text}}
45
- </button>
46
- </template>
47
- </div>
48
- <Loading :isLoading="props.isLoading" :message="props.loadingMessage"></Loading>
49
- </div>
50
- </div>
51
-
52
- </div>
53
- </template>
54
-
55
- <script lang="ts" setup>
56
- import { ref, onMounted, onUnmounted, watch, computed, nextTick } from 'vue';
57
- import * as bootstrap from 'bootstrap';
58
- import Loading from '@/components/loading/index.vue';
59
-
60
- // 生成唯一ID,用于区分不同的modal实例
61
- const modalId = `modal-${Date.now()}-${Math.floor(Math.random() * 1000)}`;
62
-
63
- const props = defineProps({
64
- title: {
65
- type: String,
66
- default: ''
67
- },
68
- closeButton: {
69
- type: Object,
70
- default: {
71
- text: '关闭',
72
- show: false
73
- }
74
- },
75
- confirmButton: {
76
- type: Object,
77
- default: {
78
- text: '确定',
79
- show: true
80
- }
81
- },
82
- isLoading: {
83
- type: Boolean,
84
- default: false
85
- },
86
- loadingMessage: {
87
- type: String,
88
- default: '处理中...'
89
- },
90
- style: {
91
- type: Object,
92
- default: {}
93
- },
94
- visible: {
95
- type: Boolean,
96
- default: false,
97
- },
98
- isFullScreen: {
99
- type: Boolean,
100
- default: false
101
- },
102
- teleport: {
103
- type: [Boolean, String],
104
- default: true // true表示传送到body,也可传具体选择器如"#app"
105
- },
106
- });
107
-
108
- // 动态属性 - 用于全局modal服务
109
- const dynamicOptions = ref<any>({});
110
- const dynamicTitle = ref('');
111
- const dynamicContent = ref('');
112
- const dynamicType = ref<'success' | 'error' | 'warning' | 'info' | ''>('');
113
- const dynamicConfirmText = ref('');
114
- const dynamicCancelText = ref('');
115
- const dynamicShowCancel = ref(false);
116
- const detailsExpanded = ref(false);
117
- const dynamicErrorDetails = ref<any>(null);
118
- // 响应式最大宽度计算
119
- const isMobile = ref(false);
120
-
121
- // 检测屏幕宽度
122
- const checkScreenSize = () => {
123
- isMobile.value = window.innerWidth < 768; // 768px是Bootstrap的md断点
124
- };
125
-
126
- // 初始化检测
127
- checkScreenSize();
128
-
129
- // 监听窗口大小变化
130
- window.addEventListener('resize', checkScreenSize);
131
-
132
- // 组件卸载时移除事件监听
133
- onUnmounted(() => {
134
- window.removeEventListener('resize', checkScreenSize);
135
- });
136
-
137
- const dynamicStyle = computed(() => {
138
- return {
139
- maxWidth: isMobile.value ? '100vw' : '80vw!important',
140
- width: 'auto', // 移除固定宽度,使用自动宽度
141
- minWidth: '300px',
142
- wordWrap: 'break-word',
143
- overflowWrap: 'break-word',
144
- zIndex: 1060, // 设置一个比backdrop(1055)更高的z-index
145
- ...(Object.keys(props.style).length ? props.style : {}),
146
- ...(dynamicOptions.value?.style || {}),
147
- };
148
- });
149
-
150
- // 判断是否应该显示详情按钮
151
- const shouldShowDetails = () => {
152
- return dynamicType.value === 'error' && dynamicErrorDetails.value;
153
- };
154
-
155
- // 切换详情展开状态
156
- const toggleDetails = () => {
157
- detailsExpanded.value = !detailsExpanded.value;
158
- };
159
-
160
- // 格式化错误详情
161
- const formatErrorDetails = () => {
162
- if (!dynamicErrorDetails.value) return '';
163
- try {
164
- return JSON.stringify(dynamicErrorDetails.value, null, 2);
165
- } catch {
166
- return String(dynamicErrorDetails.value);
167
- }
168
- };
169
-
170
- // 类型相关的计算属性
171
- const typeIcon = computed(() => {
172
- const iconMap = {
173
- success: 'bi bi-check-circle-fill text-success',
174
- error: 'bi bi-x-circle-fill text-danger',
175
- warning: 'bi bi-exclamation-triangle-fill text-warning',
176
- info: 'bi bi-info-circle-fill text-info'
177
- };
178
- return iconMap[dynamicType.value as keyof typeof iconMap] || '';
179
- });
180
-
181
- const headerClass = computed(() => {
182
- const classMap = {
183
- success: 'bg-success text-white',
184
- error: 'bg-danger text-white',
185
- warning: 'bg-warning text-dark',
186
- info: 'bg-info text-white'
187
- };
188
- return classMap[dynamicType.value as keyof typeof classMap] || '';
189
- });
190
-
191
- const contentClass = computed(() => {
192
- if (!dynamicType.value) return '';
193
- return `modal-${dynamicType.value}`;
194
- });
195
-
196
- const confirmButtonClass = computed(() => {
197
- const classMap = {
198
- success: 'btn-success',
199
- error: 'btn-danger',
200
- warning: 'btn-warning',
201
- info: 'btn-info'
202
- };
203
- return classMap[dynamicType.value as keyof typeof classMap] || 'btn-primary';
204
- });
205
-
206
- const originalParent = ref<Node | null>(null); // 保存原始父节点
207
-
208
- // 计算传送目标容器
209
- const getTargetContainer = () => {
210
- if (!props.teleport) return null; // 不启用传送
211
-
212
- if (typeof props.teleport === 'string') {
213
- // 传送目标为指定选择器(如"#app")
214
- return document.querySelector<HTMLElement>(props.teleport) || null;
215
- } else {
216
- // 默认为body
217
- return document.body;
218
- }
219
- };
220
- // 核心:根据teleport属性传送模态框
221
- const teleportModal = () => {
222
- if (!modalContainer.value) return;
223
-
224
- // 获取目标容器
225
- const target = getTargetContainer();
226
- if (!target) return;
227
-
228
- // 保存原始父节点(仅第一次传送时保存)
229
- if (!originalParent.value) {
230
- originalParent.value = modalContainer.value.parentNode;
231
- }
232
-
233
- // 如果不在目标容器中,则移动过去
234
- if (modalContainer.value.parentNode !== target) {
235
- target.appendChild(modalContainer.value);
236
- }
237
- };
238
-
239
- // 恢复模态框到原始位置(组件卸载时)
240
- const restoreModal = () => {
241
- if (modalContainer.value && originalParent.value && props.teleport) {
242
- // 避免重复添加(如果已经在原始父节点则不操作)
243
- if (!originalParent.value.contains(modalContainer.value)) {
244
- originalParent.value.appendChild(modalContainer.value);
245
- }
246
- }
247
- };
248
-
249
- // 强制重置Bootstrap Modal状态
250
- const resetModalState = () => {
251
- if (modalContainer.value) {
252
- // 移除Bootstrap的类
253
- modalContainer.value.classList.remove('show', 'fade');
254
- const backdrop = document.querySelector('.modal-backdrop');
255
- if (backdrop) {
256
- backdrop.remove();
257
- }
258
- }
259
- };
260
-
261
- const emits = defineEmits(['onConfirm', 'onClose', 'onCancel', 'onHidden']);
262
-
263
- const modalShow = ref(false);
264
- const isShowing = ref(false); // 防止重复显示的标志
265
- const isHiding = ref(false); // 防止隐藏过程中的冲突
266
- const modalContainer = ref<HTMLElement>(null as any);
267
- let modal: bootstrap.Modal | null = null;
268
-
269
- // 初始化modal
270
- function getModal() {
271
- if(modal) return modal;
272
- if(!modalContainer.value) return null;
273
-
274
- // 使用更可靠的事件处理方式
275
- const handleModalHide = (e: any) => {
276
- // 确保事件源是当前modal元素,并且不是在隐藏过程中
277
- if (e.target === modalContainer.value && !isHiding.value) {
278
- console.log(`Modal ${modalId} hidden event triggered`);
279
- ModalHide();
280
- }
281
- };
282
-
283
- const handleModalShow = (e: any) => {
284
- if (e.target === modalContainer.value) {
285
- console.log(`Modal ${modalId} show event triggered`);
286
- ModalShow();
287
- }
288
- };
289
-
290
- // 使用Bootstrap Modal的实例方法来监听事件,而不是DOM事件
291
- const m = new bootstrap.Modal(modalContainer.value, {
292
- backdrop: 'static',
293
- keyboard: false,
294
- });
295
-
296
- // 直接绑定到Bootstrap Modal实例
297
- modalContainer.value.addEventListener('hidden.bs.modal', handleModalHide);
298
- modalContainer.value.addEventListener('show.bs.modal', handleModalShow);
299
-
300
- // 存储事件处理函数以便卸载时移除
301
- (modalContainer.value as any).handleModalHide = handleModalHide;
302
- (modalContainer.value as any).handleModalShow = handleModalShow;
303
-
304
- return m;
305
- }
306
-
307
- function ModalShow(){
308
- console.log(`Modal ${modalId} shown function called`);
309
- if (props.teleport) {
310
- teleportModal(); // 启用传送时才执行
311
- }
312
- modalShow.value = true;
313
- isShowing.value = true;
314
- isHiding.value = false;
315
-
316
- // 延迟一下,确保backdrop已经被添加到DOM中
317
- setTimeout(() => {
318
- const backdrop = document.querySelector('.modal-backdrop');
319
- if (backdrop && modalContainer.value) {
320
- // 将backdrop移动到与模态框相同的容器中
321
- const parentContainer = modalContainer.value.parentElement;
322
- if (parentContainer) {
323
- parentContainer.appendChild(backdrop);
324
- }
325
- // 设置backdrop的z-index为1050,比模态框的z-index(1060)低
326
- backdrop.style.zIndex = '1050';
327
- }
328
- }, 100);
329
- }
330
-
331
- function ModalHide(){
332
- console.log(`Modal ${modalId} hidden function called`);
333
- modalShow.value = false;
334
- isShowing.value = false;
335
- isHiding.value = false;
336
- emits('onHidden');
337
- }
338
-
339
- function show() {
340
- // 防止重复显示
341
- if (isShowing.value && !isHiding.value) {
342
- console.log('Modal already showing, skipping');
343
- return Promise.resolve();
344
- }
345
-
346
- console.log(`Attempting to show modal ${modalId}`);
347
-
348
- const modalInstance = getModal();
349
- if (modalInstance) {
350
- // 重置状态
351
- isHiding.value = false;
352
-
353
- return new Promise<void>((resolve) => {
354
- // 使用双重nextTick确保DOM完全更新
355
- nextTick(() => {
356
- nextTick(() => {
357
- modalInstance.show();
358
- resolve();
359
- });
360
- });
361
- });
362
- }
363
- return Promise.resolve();
364
- }
365
-
366
- function hide() {
367
- if (isHiding.value) {
368
- console.log('Modal already hiding, skipping');
369
- return Promise.resolve();
370
- }
371
-
372
- console.log(`Attempting to hide modal ${modalId}`);
373
- const modalInstance = getModal();
374
- if (modalInstance) {
375
- isHiding.value = true;
376
- isShowing.value = false;
377
-
378
- return new Promise<void>((resolve) => {
379
- // 监听实际隐藏完成
380
- const checkHidden = () => {
381
- if (!modalContainer.value?.classList.contains('show')) {
382
- resolve();
383
- } else {
384
- setTimeout(checkHidden, 50);
385
- }
386
- };
387
-
388
- modalInstance.hide();
389
- setTimeout(checkHidden, 100); // 给一些时间开始隐藏动画
390
- });
391
- }
392
- return Promise.resolve();
393
- }
394
-
395
- function confirm() {
396
- emits('onConfirm');
397
- dynamicOptions.value?.onConfirm?.();
398
- }
399
-
400
- function cancel() {
401
- hide();
402
- emits('onCancel');
403
- dynamicOptions.value?.onCancel?.();
404
- }
405
-
406
- watch(()=>props.visible, (visible) => {
407
- if(modalShow.value === visible) return;
408
- if(visible) {
409
- show();
410
- }
411
- else {
412
- hide();
413
- }
414
- });
415
-
416
- onMounted(()=>{
417
- modal = getModal();
418
- });
419
-
420
- onUnmounted(()=>{
421
- if (modalContainer.value) {
422
- // 移除对应的事件监听器
423
- modalContainer.value.removeEventListener('hidden.bs.modal',
424
- (modalContainer.value as any).handleModalHide);
425
- modalContainer.value.removeEventListener('show.bs.modal',
426
- (modalContainer.value as any).handleModalShow);
427
- }
428
- // 销毁modal实例
429
- if (modal) {
430
- modal.dispose();
431
- }
432
- restoreModal();
433
- });
434
-
435
- // 暴露方法供全局调用
436
- defineExpose({
437
- show,
438
- open: show,
439
- hide,
440
- close: hide,
441
- modalId,
442
- // 动态属性设置方法
443
- setTitle: (title: string) => dynamicTitle.value = title,
444
- setContent: (content: string) => dynamicContent.value = content,
445
- setType: (type: 'success' | 'error' | 'warning' | 'info') => dynamicType.value = type,
446
- setConfirmText: (text: string) => dynamicConfirmText.value = text,
447
- setCancelText: (text: string) => dynamicCancelText.value = text,
448
- setShowCancel: (show: boolean) => dynamicShowCancel.value = show,
449
- // 批量设置方法
450
- setOptions: (options: any) => {
451
- if (options.title) dynamicTitle.value = options.title;
452
- if (options.content) dynamicContent.value = options.content;
453
- if (options.type) dynamicType.value = options.type;
454
- if (options.confirmText) dynamicConfirmText.value = options.confirmText;
455
- if (options.cancelText) dynamicCancelText.value = options.cancelText;
456
- if (options.showCancel !== undefined) dynamicShowCancel.value = options.showCancel;
457
- if (options.details !== undefined) dynamicErrorDetails.value = options.details;
458
- dynamicOptions.value = options;
459
- }
460
- });
461
- </script>
462
-
463
- <style scoped>
464
- .modal-dialog {
465
- z-index: var(--bs-modal-zindex);
466
- max-width:none !important;
467
- }
468
-
469
- .modal-success .modal-header {
470
- background-color: var(--bs-success);
471
- color: white;
472
- }
473
-
474
- .modal-error .modal-header {
475
- background-color: var(--bs-danger);
476
- color: white;
477
- }
478
-
479
- .modal-warning .modal-header {
480
- background-color: var(--bs-warning);
481
- color: var(--bs-dark);
482
- }
483
-
484
- .modal-info .modal-header {
485
- background-color: var(--bs-info);
486
- color: white;
487
- }
488
-
489
- .modal-body {
490
- min-height: 80px;
491
- display: flex;
492
- flex-direction: column;
493
- align-items: stretch;
494
- }
495
-
496
- .error-details {
497
- width: 100%;
498
- margin-top: 1rem;
499
- }
500
-
501
- .error-content {
502
- background-color: #f8f9fa;
503
- border: 1px solid #e9ecef;
504
- border-radius: 0.375rem;
505
- padding: 1rem;
506
- margin: 0;
507
- max-height: 200px;
508
- overflow-y: auto;
509
- white-space: pre-wrap;
510
- word-break: break-word;
511
- font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
512
- font-size: 0.875rem;
513
- line-height: 1.5;
514
- }
515
-
516
- .error-details-toggle {
517
- width: 100%;
518
- }
519
-
520
- .error-details-content {
521
- background-color: #f8f9fa;
522
- border: 1px solid #e9ecef;
523
- border-radius: 0.375rem;
524
- padding: 1rem;
525
- margin-top: 0.5rem;
526
- }
527
-
528
- .error-json {
529
- background-color: #212529;
530
- color: #f8f9fa;
531
- border-radius: 0.25rem;
532
- padding: 0.75rem;
533
- font-size: 0.8rem;
534
- line-height: 1.4;
535
- max-height: 300px;
536
- overflow-y: auto;
537
- white-space: pre-wrap;
538
- word-break: break-word;
539
- }
540
-
541
- .error-meta {
542
- border-bottom: 1px solid #dee2e6;
543
- padding-bottom: 0.5rem;
544
- margin-bottom: 0.5rem;
545
- }
546
-
547
- .modal-body .fs-1 {
548
- font-size: 2.5rem;
549
- margin-bottom: 1rem;
550
- }
551
-
552
- /* 响应式调整 */
553
- @media (max-width: 576px) {
554
- .error-content,
555
- .error-json {
556
- font-size: 0.75rem;
557
- max-height: 150px;
558
- }
559
- }
560
- </style>
1
+ <template>
2
+ <div class="modal fade" :id="modalId" ref="modalContainer" tabindex="-1" aria-labelledby="modalLabel">
3
+ <div class="modal-dialog modal-dialog-centered" :class="{'modal-fullscreen': isFullScreen}" :style="dynamicStyle">
4
+ <div class="modal-content" :class="contentClass" style=" margin: auto;">
5
+ <div class="modal-header" :class="headerClass" style="padding: 1rem 1.5rem;">
6
+ <h5 class="modal-title d-flex align-items-center" id="modalLabel">
7
+ <i v-if="typeIcon" :class="typeIcon" class="me-2"></i>
8
+ {{dynamicTitle || props.title}}
9
+ </h5>
10
+ <button type="button" class="btn-close" aria-label="Close" @click="cancel"></button>
11
+ </div>
12
+ <div class="modal-body text-wrap" v-if="modalShow">
13
+ <slot v-if="$slots.default"></slot>
14
+ <div v-else>
15
+ <div class="d-flex align-items-center mb-3">
16
+ <i v-if="typeIcon" :class="typeIcon" class="me-3 fs-1"></i>
17
+ <div class="flex-grow-1 text-wrap">{{dynamicContent}}</div>
18
+ </div>
19
+ <div v-if="shouldShowDetails()" class="error-details-toggle mt-2">
20
+ <button class="btn btn-sm btn-outline-secondary" @click="toggleDetails">
21
+ {{detailsExpanded ? '隐藏' : '详情'}}
22
+ <i class="bi bi-chevron-{{detailsExpanded ? 'up' : 'down'}} ms-1"></i>
23
+ </button>
24
+ <div v-if="detailsExpanded" class="error-details-content mt-2">
25
+ <pre class="error-json">{{formatErrorDetails()}}</pre>
26
+ </div>
27
+ </div>
28
+ </div>
29
+ </div>
30
+ <div class="modal-footer">
31
+ <slot name="footer" v-if="$slots.footer"></slot>
32
+ <template v-else>
33
+ <button type="button"
34
+ v-if="dynamicShowCancel || props.closeButton.show"
35
+ class="btn btn-secondary"
36
+ @click="cancel">
37
+ {{dynamicCancelText || props.closeButton.text}}
38
+ </button>
39
+ <button type="button"
40
+ v-if="props.confirmButton.show"
41
+ class="btn"
42
+ :class="confirmButtonClass"
43
+ @click="confirm">
44
+ {{dynamicConfirmText || props.confirmButton.text}}
45
+ </button>
46
+ </template>
47
+ </div>
48
+ <Loading :isLoading="props.isLoading" :message="props.loadingMessage"></Loading>
49
+ </div>
50
+ </div>
51
+
52
+ </div>
53
+ </template>
54
+
55
+ <script lang="ts" setup>
56
+ import { ref, onMounted, onUnmounted, watch, computed, nextTick } from 'vue';
57
+ import * as bootstrap from 'bootstrap';
58
+ import Loading from '@/components/loading/index.vue';
59
+
60
+ // 生成唯一ID,用于区分不同的modal实例
61
+ const modalId = `modal-${Date.now()}-${Math.floor(Math.random() * 1000)}`;
62
+
63
+ const props = defineProps({
64
+ title: {
65
+ type: String,
66
+ default: ''
67
+ },
68
+ closeButton: {
69
+ type: Object,
70
+ default: {
71
+ text: '关闭',
72
+ show: false
73
+ }
74
+ },
75
+ confirmButton: {
76
+ type: Object,
77
+ default: {
78
+ text: '确定',
79
+ show: true
80
+ }
81
+ },
82
+ isLoading: {
83
+ type: Boolean,
84
+ default: false
85
+ },
86
+ loadingMessage: {
87
+ type: String,
88
+ default: '处理中...'
89
+ },
90
+ style: {
91
+ type: Object,
92
+ default: {}
93
+ },
94
+ visible: {
95
+ type: Boolean,
96
+ default: false,
97
+ },
98
+ isFullScreen: {
99
+ type: Boolean,
100
+ default: false
101
+ },
102
+ teleport: {
103
+ type: [Boolean, String],
104
+ default: true // true表示传送到body,也可传具体选择器如"#app"
105
+ },
106
+ });
107
+
108
+ // 动态属性 - 用于全局modal服务
109
+ const dynamicOptions = ref<any>({});
110
+ const dynamicTitle = ref('');
111
+ const dynamicContent = ref('');
112
+ const dynamicType = ref<'success' | 'error' | 'warning' | 'info' | ''>('');
113
+ const dynamicConfirmText = ref('');
114
+ const dynamicCancelText = ref('');
115
+ const dynamicShowCancel = ref(false);
116
+ const detailsExpanded = ref(false);
117
+ const dynamicErrorDetails = ref<any>(null);
118
+ // 响应式最大宽度计算
119
+ const isMobile = ref(false);
120
+
121
+ // 检测屏幕宽度
122
+ const checkScreenSize = () => {
123
+ isMobile.value = window.innerWidth < 768; // 768px是Bootstrap的md断点
124
+ };
125
+
126
+ // 初始化检测
127
+ checkScreenSize();
128
+
129
+ // 监听窗口大小变化
130
+ window.addEventListener('resize', checkScreenSize);
131
+
132
+ // 组件卸载时移除事件监听
133
+ onUnmounted(() => {
134
+ window.removeEventListener('resize', checkScreenSize);
135
+ });
136
+
137
+ const dynamicStyle = computed(() => {
138
+ return {
139
+ maxWidth: isMobile.value ? '100vw' : '80vw!important',
140
+ width: 'auto', // 移除固定宽度,使用自动宽度
141
+ minWidth: '300px',
142
+ wordWrap: 'break-word',
143
+ overflowWrap: 'break-word',
144
+ zIndex: 1060, // 设置一个比backdrop(1055)更高的z-index
145
+ ...(Object.keys(props.style).length ? props.style : {}),
146
+ ...(dynamicOptions.value?.style || {}),
147
+ };
148
+ });
149
+
150
+ // 判断是否应该显示详情按钮
151
+ const shouldShowDetails = () => {
152
+ return dynamicType.value === 'error' && dynamicErrorDetails.value;
153
+ };
154
+
155
+ // 切换详情展开状态
156
+ const toggleDetails = () => {
157
+ detailsExpanded.value = !detailsExpanded.value;
158
+ };
159
+
160
+ // 格式化错误详情
161
+ const formatErrorDetails = () => {
162
+ if (!dynamicErrorDetails.value) return '';
163
+ try {
164
+ return JSON.stringify(dynamicErrorDetails.value, null, 2);
165
+ } catch {
166
+ return String(dynamicErrorDetails.value);
167
+ }
168
+ };
169
+
170
+ // 类型相关的计算属性
171
+ const typeIcon = computed(() => {
172
+ const iconMap = {
173
+ success: 'bi bi-check-circle-fill text-success',
174
+ error: 'bi bi-x-circle-fill text-danger',
175
+ warning: 'bi bi-exclamation-triangle-fill text-warning',
176
+ info: 'bi bi-info-circle-fill text-info'
177
+ };
178
+ return iconMap[dynamicType.value as keyof typeof iconMap] || '';
179
+ });
180
+
181
+ const headerClass = computed(() => {
182
+ const classMap = {
183
+ success: 'bg-success text-white',
184
+ error: 'bg-danger text-white',
185
+ warning: 'bg-warning text-dark',
186
+ info: 'bg-info text-white'
187
+ };
188
+ return classMap[dynamicType.value as keyof typeof classMap] || '';
189
+ });
190
+
191
+ const contentClass = computed(() => {
192
+ if (!dynamicType.value) return '';
193
+ return `modal-${dynamicType.value}`;
194
+ });
195
+
196
+ const confirmButtonClass = computed(() => {
197
+ const classMap = {
198
+ success: 'btn-success',
199
+ error: 'btn-danger',
200
+ warning: 'btn-warning',
201
+ info: 'btn-info'
202
+ };
203
+ return classMap[dynamicType.value as keyof typeof classMap] || 'btn-primary';
204
+ });
205
+
206
+ const originalParent = ref<Node | null>(null); // 保存原始父节点
207
+
208
+ // 计算传送目标容器
209
+ const getTargetContainer = () => {
210
+ if (!props.teleport) return null; // 不启用传送
211
+
212
+ if (typeof props.teleport === 'string') {
213
+ // 传送目标为指定选择器(如"#app")
214
+ return document.querySelector<HTMLElement>(props.teleport) || null;
215
+ } else {
216
+ // 默认为body
217
+ return document.body;
218
+ }
219
+ };
220
+ // 核心:根据teleport属性传送模态框
221
+ const teleportModal = () => {
222
+ if (!modalContainer.value) return;
223
+
224
+ // 获取目标容器
225
+ const target = getTargetContainer();
226
+ if (!target) return;
227
+
228
+ // 保存原始父节点(仅第一次传送时保存)
229
+ if (!originalParent.value) {
230
+ originalParent.value = modalContainer.value.parentNode;
231
+ }
232
+
233
+ // 如果不在目标容器中,则移动过去
234
+ if (modalContainer.value.parentNode !== target) {
235
+ target.appendChild(modalContainer.value);
236
+ }
237
+ };
238
+
239
+ // 恢复模态框到原始位置(组件卸载时)
240
+ const restoreModal = () => {
241
+ if (modalContainer.value && originalParent.value && props.teleport) {
242
+ // 避免重复添加(如果已经在原始父节点则不操作)
243
+ if (!originalParent.value.contains(modalContainer.value)) {
244
+ originalParent.value.appendChild(modalContainer.value);
245
+ }
246
+ }
247
+ };
248
+
249
+ // 强制重置Bootstrap Modal状态
250
+ const resetModalState = () => {
251
+ if (modalContainer.value) {
252
+ // 移除Bootstrap的类
253
+ modalContainer.value.classList.remove('show', 'fade');
254
+ const backdrop = document.querySelector('.modal-backdrop');
255
+ if (backdrop) {
256
+ backdrop.remove();
257
+ }
258
+ }
259
+ };
260
+
261
+ const emits = defineEmits(['onConfirm', 'onClose', 'onCancel', 'onHidden']);
262
+
263
+ const modalShow = ref(false);
264
+ const isShowing = ref(false); // 防止重复显示的标志
265
+ const isHiding = ref(false); // 防止隐藏过程中的冲突
266
+ const modalContainer = ref<HTMLElement>(null as any);
267
+ let modal: bootstrap.Modal | null = null;
268
+
269
+ // 初始化modal
270
+ function getModal() {
271
+ if(modal) return modal;
272
+ if(!modalContainer.value) return null;
273
+
274
+ // 使用更可靠的事件处理方式
275
+ const handleModalHide = (e: any) => {
276
+ // 确保事件源是当前modal元素,并且不是在隐藏过程中
277
+ if (e.target === modalContainer.value && !isHiding.value) {
278
+ console.log(`Modal ${modalId} hidden event triggered`);
279
+ ModalHide();
280
+ }
281
+ };
282
+
283
+ const handleModalShow = (e: any) => {
284
+ if (e.target === modalContainer.value) {
285
+ console.log(`Modal ${modalId} show event triggered`);
286
+ ModalShow();
287
+ }
288
+ };
289
+
290
+ // 使用Bootstrap Modal的实例方法来监听事件,而不是DOM事件
291
+ const m = new bootstrap.Modal(modalContainer.value, {
292
+ backdrop: 'static',
293
+ keyboard: false,
294
+ });
295
+
296
+ // 直接绑定到Bootstrap Modal实例
297
+ modalContainer.value.addEventListener('hidden.bs.modal', handleModalHide);
298
+ modalContainer.value.addEventListener('show.bs.modal', handleModalShow);
299
+
300
+ // 存储事件处理函数以便卸载时移除
301
+ (modalContainer.value as any).handleModalHide = handleModalHide;
302
+ (modalContainer.value as any).handleModalShow = handleModalShow;
303
+
304
+ return m;
305
+ }
306
+
307
+ function ModalShow(){
308
+ console.log(`Modal ${modalId} shown function called`);
309
+ if (props.teleport) {
310
+ teleportModal(); // 启用传送时才执行
311
+ }
312
+ modalShow.value = true;
313
+ isShowing.value = true;
314
+ isHiding.value = false;
315
+
316
+ // 延迟一下,确保backdrop已经被添加到DOM中
317
+ setTimeout(() => {
318
+ const backdrop = document.querySelector('.modal-backdrop');
319
+ if (backdrop && modalContainer.value) {
320
+ // 将backdrop移动到与模态框相同的容器中
321
+ const parentContainer = modalContainer.value.parentElement;
322
+ if (parentContainer) {
323
+ parentContainer.appendChild(backdrop);
324
+ }
325
+ // 设置backdrop的z-index为1050,比模态框的z-index(1060)低
326
+ backdrop.style.zIndex = '1050';
327
+ }
328
+ }, 100);
329
+ }
330
+
331
+ function ModalHide(){
332
+ console.log(`Modal ${modalId} hidden function called`);
333
+ modalShow.value = false;
334
+ isShowing.value = false;
335
+ isHiding.value = false;
336
+ emits('onHidden');
337
+ }
338
+
339
+ function show() {
340
+ // 防止重复显示
341
+ if (isShowing.value && !isHiding.value) {
342
+ console.log('Modal already showing, skipping');
343
+ return Promise.resolve();
344
+ }
345
+
346
+ console.log(`Attempting to show modal ${modalId}`);
347
+
348
+ const modalInstance = getModal();
349
+ if (modalInstance) {
350
+ // 重置状态
351
+ isHiding.value = false;
352
+
353
+ return new Promise<void>((resolve) => {
354
+ // 使用双重nextTick确保DOM完全更新
355
+ nextTick(() => {
356
+ nextTick(() => {
357
+ modalInstance.show();
358
+ resolve();
359
+ });
360
+ });
361
+ });
362
+ }
363
+ return Promise.resolve();
364
+ }
365
+
366
+ function hide() {
367
+ if (isHiding.value) {
368
+ console.log('Modal already hiding, skipping');
369
+ return Promise.resolve();
370
+ }
371
+
372
+ console.log(`Attempting to hide modal ${modalId}`);
373
+ const modalInstance = getModal();
374
+ if (modalInstance) {
375
+ isHiding.value = true;
376
+ isShowing.value = false;
377
+
378
+ return new Promise<void>((resolve) => {
379
+ // 监听实际隐藏完成
380
+ const checkHidden = () => {
381
+ if (!modalContainer.value?.classList.contains('show')) {
382
+ resolve();
383
+ } else {
384
+ setTimeout(checkHidden, 50);
385
+ }
386
+ };
387
+
388
+ modalInstance.hide();
389
+ setTimeout(checkHidden, 100); // 给一些时间开始隐藏动画
390
+ });
391
+ }
392
+ return Promise.resolve();
393
+ }
394
+
395
+ function confirm() {
396
+ emits('onConfirm');
397
+ dynamicOptions.value?.onConfirm?.();
398
+ }
399
+
400
+ function cancel() {
401
+ hide();
402
+ emits('onCancel');
403
+ dynamicOptions.value?.onCancel?.();
404
+ }
405
+
406
+ watch(()=>props.visible, (visible) => {
407
+ if(modalShow.value === visible) return;
408
+ if(visible) {
409
+ show();
410
+ }
411
+ else {
412
+ hide();
413
+ }
414
+ });
415
+
416
+ onMounted(()=>{
417
+ modal = getModal();
418
+ });
419
+
420
+ onUnmounted(()=>{
421
+ if (modalContainer.value) {
422
+ // 移除对应的事件监听器
423
+ modalContainer.value.removeEventListener('hidden.bs.modal',
424
+ (modalContainer.value as any).handleModalHide);
425
+ modalContainer.value.removeEventListener('show.bs.modal',
426
+ (modalContainer.value as any).handleModalShow);
427
+ }
428
+ // 销毁modal实例
429
+ if (modal) {
430
+ modal.dispose();
431
+ }
432
+ restoreModal();
433
+ });
434
+
435
+ // 暴露方法供全局调用
436
+ defineExpose({
437
+ show,
438
+ open: show,
439
+ hide,
440
+ close: hide,
441
+ modalId,
442
+ // 动态属性设置方法
443
+ setTitle: (title: string) => dynamicTitle.value = title,
444
+ setContent: (content: string) => dynamicContent.value = content,
445
+ setType: (type: 'success' | 'error' | 'warning' | 'info') => dynamicType.value = type,
446
+ setConfirmText: (text: string) => dynamicConfirmText.value = text,
447
+ setCancelText: (text: string) => dynamicCancelText.value = text,
448
+ setShowCancel: (show: boolean) => dynamicShowCancel.value = show,
449
+ // 批量设置方法
450
+ setOptions: (options: any) => {
451
+ if (options.title) dynamicTitle.value = options.title;
452
+ if (options.content) dynamicContent.value = options.content;
453
+ if (options.type) dynamicType.value = options.type;
454
+ if (options.confirmText) dynamicConfirmText.value = options.confirmText;
455
+ if (options.cancelText) dynamicCancelText.value = options.cancelText;
456
+ if (options.showCancel !== undefined) dynamicShowCancel.value = options.showCancel;
457
+ if (options.details !== undefined) dynamicErrorDetails.value = options.details;
458
+ dynamicOptions.value = options;
459
+ }
460
+ });
461
+ </script>
462
+
463
+ <style scoped>
464
+ .modal-dialog {
465
+ z-index: var(--bs-modal-zindex);
466
+ max-width:none !important;
467
+ }
468
+
469
+ .modal-success .modal-header {
470
+ background-color: var(--bs-success);
471
+ color: white;
472
+ }
473
+
474
+ .modal-error .modal-header {
475
+ background-color: var(--bs-danger);
476
+ color: white;
477
+ }
478
+
479
+ .modal-warning .modal-header {
480
+ background-color: var(--bs-warning);
481
+ color: var(--bs-dark);
482
+ }
483
+
484
+ .modal-info .modal-header {
485
+ background-color: var(--bs-info);
486
+ color: white;
487
+ }
488
+
489
+ .modal-body {
490
+ min-height: 80px;
491
+ display: flex;
492
+ flex-direction: column;
493
+ align-items: stretch;
494
+ }
495
+
496
+ .error-details {
497
+ width: 100%;
498
+ margin-top: 1rem;
499
+ }
500
+
501
+ .error-content {
502
+ background-color: #f8f9fa;
503
+ border: 1px solid #e9ecef;
504
+ border-radius: 0.375rem;
505
+ padding: 1rem;
506
+ margin: 0;
507
+ max-height: 200px;
508
+ overflow-y: auto;
509
+ white-space: pre-wrap;
510
+ word-break: break-word;
511
+ font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
512
+ font-size: 0.875rem;
513
+ line-height: 1.5;
514
+ }
515
+
516
+ .error-details-toggle {
517
+ width: 100%;
518
+ }
519
+
520
+ .error-details-content {
521
+ background-color: #f8f9fa;
522
+ border: 1px solid #e9ecef;
523
+ border-radius: 0.375rem;
524
+ padding: 1rem;
525
+ margin-top: 0.5rem;
526
+ }
527
+
528
+ .error-json {
529
+ background-color: #212529;
530
+ color: #f8f9fa;
531
+ border-radius: 0.25rem;
532
+ padding: 0.75rem;
533
+ font-size: 0.8rem;
534
+ line-height: 1.4;
535
+ max-height: 300px;
536
+ overflow-y: auto;
537
+ white-space: pre-wrap;
538
+ word-break: break-word;
539
+ }
540
+
541
+ .error-meta {
542
+ border-bottom: 1px solid #dee2e6;
543
+ padding-bottom: 0.5rem;
544
+ margin-bottom: 0.5rem;
545
+ }
546
+
547
+ .modal-body .fs-1 {
548
+ font-size: 2.5rem;
549
+ margin-bottom: 1rem;
550
+ }
551
+
552
+ /* 响应式调整 */
553
+ @media (max-width: 576px) {
554
+ .error-content,
555
+ .error-json {
556
+ font-size: 0.75rem;
557
+ max-height: 150px;
558
+ }
559
+ }
560
+ </style>