fdb2 1.0.0

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 (125) hide show
  1. package/.dockerignore +21 -0
  2. package/.editorconfig +11 -0
  3. package/.eslintrc.cjs +14 -0
  4. package/.eslintrc.json +7 -0
  5. package/.prettierrc.js +3 -0
  6. package/.tpl.env +22 -0
  7. package/README.md +260 -0
  8. package/bin/build.sh +28 -0
  9. package/bin/deploy.sh +8 -0
  10. package/bin/dev.sh +10 -0
  11. package/bin/docker/.env +4 -0
  12. package/bin/docker/dev-docker-compose.yml +43 -0
  13. package/bin/docker/dev.Dockerfile +24 -0
  14. package/bin/docker/prod-docker-compose.yml +17 -0
  15. package/bin/docker/prod.Dockerfile +29 -0
  16. package/bin/fdb2.js +142 -0
  17. package/data/connections.demo.json +32 -0
  18. package/env.d.ts +1 -0
  19. package/nw-build.js +120 -0
  20. package/nw-dev.js +65 -0
  21. package/package.json +114 -0
  22. package/public/favicon.ico +0 -0
  23. package/public/index.html +9 -0
  24. package/public/modules/header.tpl +14 -0
  25. package/public/modules/initial_state.tpl +55 -0
  26. package/server/index.ts +677 -0
  27. package/server/model/connection.entity.ts +66 -0
  28. package/server/model/database.entity.ts +246 -0
  29. package/server/service/connection.service.ts +334 -0
  30. package/server/service/database/base.service.ts +363 -0
  31. package/server/service/database/database.service.ts +510 -0
  32. package/server/service/database/index.ts +7 -0
  33. package/server/service/database/mssql.service.ts +723 -0
  34. package/server/service/database/mysql.service.ts +761 -0
  35. package/server/service/database/oracle.service.ts +839 -0
  36. package/server/service/database/postgres.service.ts +744 -0
  37. package/server/service/database/sqlite.service.ts +559 -0
  38. package/server/service/session.service.ts +158 -0
  39. package/server.js +128 -0
  40. package/src/adapter/ajax.ts +135 -0
  41. package/src/assets/base.css +1 -0
  42. package/src/assets/database.css +950 -0
  43. package/src/assets/images/collapse.png +0 -0
  44. package/src/assets/images/no-login.png +0 -0
  45. package/src/assets/images/svg/illustrations/illustration-1.svg +1 -0
  46. package/src/assets/images/svg/illustrations/illustration-2.svg +2 -0
  47. package/src/assets/images/svg/illustrations/illustration-3.svg +50 -0
  48. package/src/assets/images/svg/illustrations/illustration-4.svg +1 -0
  49. package/src/assets/images/svg/illustrations/illustration-5.svg +73 -0
  50. package/src/assets/images/svg/illustrations/illustration-6.svg +89 -0
  51. package/src/assets/images/svg/illustrations/illustration-7.svg +39 -0
  52. package/src/assets/images/svg/illustrations/illustration-8.svg +1 -0
  53. package/src/assets/images/svg/separators/curve-2.svg +3 -0
  54. package/src/assets/images/svg/separators/curve.svg +3 -0
  55. package/src/assets/images/svg/separators/line.svg +3 -0
  56. package/src/assets/images/theme/light/screen-1-1000x800.jpg +0 -0
  57. package/src/assets/images/theme/light/screen-2-1000x800.jpg +0 -0
  58. package/src/assets/login/bg.jpg +0 -0
  59. package/src/assets/login/bg.png +0 -0
  60. package/src/assets/login/left.jpg +0 -0
  61. package/src/assets/logo.svg +73 -0
  62. package/src/assets/logo.webp +0 -0
  63. package/src/assets/main.css +1 -0
  64. package/src/base/config.ts +20 -0
  65. package/src/base/detect.ts +134 -0
  66. package/src/base/entity.ts +92 -0
  67. package/src/base/eventBus.ts +37 -0
  68. package/src/base//345/237/272/347/241/200/345/261/202.md +7 -0
  69. package/src/components/connection-editor/index.vue +590 -0
  70. package/src/components/dataGrid/index.vue +105 -0
  71. package/src/components/dataGrid/pagination.vue +106 -0
  72. package/src/components/loading/index.vue +43 -0
  73. package/src/components/modal/index.ts +181 -0
  74. package/src/components/modal/index.vue +560 -0
  75. package/src/components/toast/index.ts +44 -0
  76. package/src/components/toast/toast.vue +58 -0
  77. package/src/components/user/name.vue +104 -0
  78. package/src/components/user/selector.vue +416 -0
  79. package/src/domain/SysConfig.ts +74 -0
  80. package/src/platform/App.vue +8 -0
  81. package/src/platform/database/components/connection-detail.vue +1154 -0
  82. package/src/platform/database/components/data-editor.vue +478 -0
  83. package/src/platform/database/components/data-import-export.vue +1602 -0
  84. package/src/platform/database/components/database-detail.vue +1173 -0
  85. package/src/platform/database/components/database-monitor.vue +1086 -0
  86. package/src/platform/database/components/db-tools.vue +577 -0
  87. package/src/platform/database/components/query-history.vue +1349 -0
  88. package/src/platform/database/components/sql-executor.vue +738 -0
  89. package/src/platform/database/components/sql-query-editor.vue +1046 -0
  90. package/src/platform/database/components/table-detail.vue +1376 -0
  91. package/src/platform/database/components/table-editor.vue +690 -0
  92. package/src/platform/database/explorer.vue +1840 -0
  93. package/src/platform/database/index.vue +1193 -0
  94. package/src/platform/database/layout.vue +367 -0
  95. package/src/platform/database/router.ts +37 -0
  96. package/src/platform/database/styles/common.scss +602 -0
  97. package/src/platform/database/types/common.ts +445 -0
  98. package/src/platform/database/utils/export.ts +232 -0
  99. package/src/platform/database/utils/helpers.ts +437 -0
  100. package/src/platform/index.ts +33 -0
  101. package/src/platform/router.ts +41 -0
  102. package/src/service/base.ts +128 -0
  103. package/src/service/database.ts +500 -0
  104. package/src/service/login.ts +121 -0
  105. package/src/shims-vue.d.ts +7 -0
  106. package/src/stores/connection.ts +266 -0
  107. package/src/stores/session.ts +87 -0
  108. package/src/typings/database-types.ts +413 -0
  109. package/src/typings/database.ts +364 -0
  110. package/src/typings/global.d.ts +58 -0
  111. package/src/typings/pinia.d.ts +8 -0
  112. package/src/utils/clipboard.ts +30 -0
  113. package/src/utils/database-types.ts +243 -0
  114. package/src/utils/modal.ts +124 -0
  115. package/src/utils/request.ts +55 -0
  116. package/src/utils/sleep.ts +4 -0
  117. package/src/utils/toast.ts +73 -0
  118. package/src/utils/util.ts +171 -0
  119. package/src/utils/xlsx.ts +228 -0
  120. package/tsconfig.json +33 -0
  121. package/tsconfig.server.json +19 -0
  122. package/view/index.html +9 -0
  123. package/view/modules/header.tpl +14 -0
  124. package/view/modules/initial_state.tpl +20 -0
  125. package/vite.config.ts +384 -0
@@ -0,0 +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>
@@ -0,0 +1,44 @@
1
+ import { createApp, getCurrentInstance } from 'vue';
2
+ import BootstrapToast from './toast.vue';
3
+ import { setGlobalToast } from '@/utils/toast';
4
+
5
+ export type ToastType = {
6
+ show: (message: string, title: string, type: string, duration?: number) => void,
7
+ success: (msg: string, title?: string, duration?: number) => void,
8
+ error: (msg: string, title?: string, duration?: number) => void,
9
+ warning: (msg: string, title?: string, duration?: number) => void,
10
+ info: (msg: string, title?: string, duration?: number) => void
11
+ };
12
+
13
+ export default {
14
+ install(app: any) {
15
+ // 挂载到DOM
16
+ const toastMount = document.createElement('div');
17
+ document.body.appendChild(toastMount);
18
+
19
+ // 创建Toast实例
20
+ const toastApp = createApp(BootstrapToast);
21
+ const toastInstance = toastApp.mount(toastMount) as any;
22
+
23
+ const toastMethods = {
24
+ show: (message: string, title: string, type: string, duration = 3000) => toastInstance.addToast(title, message, type, duration),
25
+ success: (msg: string, title?: string, duration = 3000) => toastInstance.addToast(title, msg, 'success', duration),
26
+ error: (msg: string, title?: string, duration = 3000) => toastInstance.addToast(title, msg, 'danger', duration),
27
+ warning: (msg: string, title?: string, duration = 3000) => toastInstance.addToast(title, msg, 'warning', duration),
28
+ info: (msg: string, title?: string, duration = 3000) => toastInstance.addToast(title, msg, 'info', duration)
29
+ } as ToastType;
30
+
31
+ // 设置全局toast实例
32
+ setGlobalToast(toastMethods);
33
+
34
+ // 全局注入
35
+ app.config.globalProperties.$toast = toastMethods;
36
+ },
37
+ getToast() {
38
+ const instance = getCurrentInstance();
39
+ if(!instance ) return null;
40
+ // @ts-ignore
41
+ const toast = instance.appContext.config?.globalProperties?.$toast as ToastType;
42
+ return toast;
43
+ }
44
+ };
@@ -0,0 +1,58 @@
1
+ <template>
2
+ <div class="toast-container position-fixed top-0 start-50 translate-middle-x p-3">
3
+ <div
4
+ :class="`toast show bg-${toast.type==='error'?'danger': toast.type}-subtle ${toast.removed? 'fade-out': ''}`"
5
+ role="alert"
6
+ v-for="(toast, index) in toasts"
7
+ :key="index"
8
+ >
9
+ <div class="toast-header" v-if="toast.title">
10
+ <strong class="me-auto">{{ toast.title }}</strong>
11
+ <button
12
+ type="button"
13
+ class="btn-close"
14
+ @click="removeToast(index)"
15
+ ></button>
16
+ </div>
17
+ <div class="toast-body">{{ toast.message }}</div>
18
+ </div>
19
+ </div>
20
+ </template>
21
+
22
+ <script lang="ts" setup>
23
+ import { reactive } from 'vue';
24
+
25
+ const toasts = reactive<Array<any>>([]);
26
+ const addToast = (title: string, message: string, type: string = 'success', duration = 3000) => {
27
+ const toast = { title, message, type, removed: false };
28
+ toasts.push(toast);
29
+ setTimeout(() => removeToast(toast), duration);
30
+ };
31
+ const removeToast = (toast: any) => {
32
+ const index = toasts.indexOf(toast);
33
+ if(index < 0) return;
34
+ toasts[index].removed = true;
35
+ //console.log('remove toast', toast);
36
+ setTimeout(()=>{
37
+ toasts.splice(index, 1);
38
+ }, 1000);
39
+ };
40
+
41
+ // 暴露方法供全局调用
42
+ defineExpose({ addToast });
43
+ </script>
44
+
45
+ <style scoped>
46
+ /* 覆盖Bootstrap默认样式 */
47
+ .toast-container {
48
+ z-index: 1100;
49
+ }
50
+
51
+ .fade-out {
52
+ animation: fadeOut 1s forwards;
53
+ }
54
+ @keyframes fadeOut {
55
+ 0% { opacity: 1; transform: translateY(0); }
56
+ 100% { opacity: 0; transform: translateY(-120%);}
57
+ }
58
+ </style>