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,1086 @@
1
+ <template>
2
+ <div class="database-monitor">
3
+ <div class="monitor-header">
4
+ <div class="monitor-title">
5
+ <i class="bi bi-activity"></i>
6
+ <span>数据库监控</span>
7
+ </div>
8
+ <div class="monitor-controls">
9
+ <select v-model="selectedConnection" class="connection-select" @change="loadMonitorData">
10
+ <option value="">选择数据库连接</option>
11
+ <option v-for="connection in connections" :key="connection.id" :value="connection.id">
12
+ {{ connection.name }}
13
+ </option>
14
+ </select>
15
+ <button class="btn-refresh" @click="refreshData" :disabled="!selectedConnection">
16
+ <i class="bi bi-arrow-clockwise" :class="{ 'spin': isRefreshing }"></i>
17
+ <span>刷新</span>
18
+ </button>
19
+ <div class="auto-refresh">
20
+ <input type="checkbox" id="autoRefresh" v-model="autoRefresh" @change="toggleAutoRefresh">
21
+ <label for="autoRefresh">自动刷新</label>
22
+ <select v-model="refreshInterval" @change="updateRefreshInterval">
23
+ <option value="5000">5秒</option>
24
+ <option value="10000">10秒</option>
25
+ <option value="30000">30秒</option>
26
+ <option value="60000">1分钟</option>
27
+ </select>
28
+ </div>
29
+ </div>
30
+ </div>
31
+
32
+ <div class="monitor-content" v-if="selectedConnection">
33
+ <!-- 状态概览 -->
34
+ <div class="status-overview">
35
+ <div class="status-card status-connection">
36
+ <div class="status-icon" :class="connectionStatus?.status">
37
+ <i :class="getStatusIcon(connectionStatus?.status)"></i>
38
+ </div>
39
+ <div class="status-info">
40
+ <div class="status-title">连接状态</div>
41
+ <div class="status-value">{{ getStatusText(connectionStatus?.status) }}</div>
42
+ <div class="status-detail">{{ connectionStatus?.uptime || '-' }}</div>
43
+ </div>
44
+ </div>
45
+
46
+ <div class="status-card status-performance">
47
+ <div class="status-icon">
48
+ <i class="bi bi-speedometer2"></i>
49
+ </div>
50
+ <div class="status-info">
51
+ <div class="status-title">响应时间</div>
52
+ <div class="status-value">{{ connectionStatus?.responseTime || '-' }}ms</div>
53
+ <div class="status-detail">{{ getPerformanceLevel(connectionStatus?.responseTime) }}</div>
54
+ </div>
55
+ </div>
56
+
57
+ <div class="status-card status-queries">
58
+ <div class="status-icon">
59
+ <i class="bi bi-graph-up"></i>
60
+ </div>
61
+ <div class="status-info">
62
+ <div class="status-title">活跃查询</div>
63
+ <div class="status-value">{{ connectionStatus?.activeQueries || 0 }}</div>
64
+ <div class="status-detail">{{ connectionStatus?.totalQueries || 0 }} 总查询</div>
65
+ </div>
66
+ </div>
67
+
68
+ <div class="status-card status-storage">
69
+ <div class="status-icon">
70
+ <i class="bi bi-hdd"></i>
71
+ </div>
72
+ <div class="status-info">
73
+ <div class="status-title">存储使用</div>
74
+ <div class="status-value">{{ formatBytes(connectionStatus?.storageUsed) }}</div>
75
+ <div class="status-detail">{{ formatBytes(connectionStatus?.storageTotal) }} 总容量</div>
76
+ </div>
77
+ </div>
78
+ </div>
79
+
80
+ <!-- 性能图表 -->
81
+ <div class="charts-section">
82
+ <div class="chart-container">
83
+ <div class="chart-header">
84
+ <h3>查询性能趋势</h3>
85
+ <div class="chart-controls">
86
+ <button
87
+ v-for="range in timeRanges"
88
+ :key="range.value"
89
+ class="range-btn"
90
+ :class="{ active: selectedTimeRange === range.value }"
91
+ @click="selectedTimeRange = range.value"
92
+ >
93
+ {{ range.label }}
94
+ </button>
95
+ </div>
96
+ </div>
97
+ <div class="chart-content">
98
+ <div ref="performanceChart" class="echart-container"></div>
99
+ </div>
100
+ </div>
101
+
102
+ <div class="chart-container">
103
+ <div class="chart-header">
104
+ <h3>连接数变化</h3>
105
+ </div>
106
+ <div class="chart-content">
107
+ <div ref="connectionsChart" class="echart-container"></div>
108
+ </div>
109
+ </div>
110
+ </div>
111
+
112
+ <!-- 慢查询列表 -->
113
+ <div class="slow-queries-section">
114
+ <div class="section-header">
115
+ <h3>慢查询分析</h3>
116
+ <button class="btn-clear" @click="clearSlowQueries" v-if="slowQueries.length > 0">
117
+ <i class="bi bi-trash"></i>
118
+ <span>清除记录</span>
119
+ </button>
120
+ </div>
121
+
122
+ <div class="queries-table-wrapper">
123
+ <table class="queries-table" v-if="slowQueries.length > 0">
124
+ <thead>
125
+ <tr>
126
+ <th>时间</th>
127
+ <th>执行时间</th>
128
+ <th>查询类型</th>
129
+ <th>查询语句</th>
130
+ <th>操作</th>
131
+ </tr>
132
+ </thead>
133
+ <tbody>
134
+ <tr v-for="query in slowQueries" :key="query.id">
135
+ <td>{{ formatTime(query.timestamp) }}</td>
136
+ <td>
137
+ <span class="execution-time" :class="getExecutionTimeClass(query.executionTime)">
138
+ {{ query.executionTime }}ms
139
+ </span>
140
+ </td>
141
+ <td>
142
+ <span class="query-type" :class="query.type.toLowerCase()">
143
+ {{ query.type }}
144
+ </span>
145
+ </td>
146
+ <td class="query-sql" :title="query.sql">
147
+ {{ truncateSql(query.sql) }}
148
+ </td>
149
+ <td>
150
+ <button class="btn-analyze" @click="analyzeQuery(query)">
151
+ <i class="bi bi-search"></i>
152
+ 分析
153
+ </button>
154
+ </td>
155
+ </tr>
156
+ </tbody>
157
+ </table>
158
+
159
+ <div class="empty-state" v-else>
160
+ <i class="bi bi-check-circle"></i>
161
+ <p>暂无慢查询记录</p>
162
+ <small>所有查询都在正常执行时间内完成</small>
163
+ </div>
164
+ </div>
165
+ </div>
166
+
167
+ <!-- 资源使用详情 -->
168
+ <div class="resources-section">
169
+ <div class="section-header">
170
+ <h3>资源使用详情</h3>
171
+ </div>
172
+
173
+ <div class="resources-grid">
174
+ <div class="resource-item">
175
+ <div class="resource-label">CPU使用率</div>
176
+ <div class="resource-value">
177
+ <div class="resource-bar">
178
+ <div class="resource-fill cpu" :style="{ width: resources.cpu + '%' }"></div>
179
+ </div>
180
+ <span>{{ resources.cpu }}%</span>
181
+ </div>
182
+ </div>
183
+
184
+ <div class="resource-item">
185
+ <div class="resource-label">内存使用率</div>
186
+ <div class="resource-value">
187
+ <div class="resource-bar">
188
+ <div class="resource-fill memory" :style="{ width: resources.memory + '%' }"></div>
189
+ </div>
190
+ <span>{{ resources.memory }}%</span>
191
+ </div>
192
+ </div>
193
+
194
+ <div class="resource-item">
195
+ <div class="resource-label">磁盘I/O</div>
196
+ <div class="resource-value">
197
+ <div class="resource-bar">
198
+ <div class="resource-fill disk" :style="{ width: resources.disk + '%' }"></div>
199
+ </div>
200
+ <span>{{ resources.disk }}%</span>
201
+ </div>
202
+ </div>
203
+
204
+ <div class="resource-item">
205
+ <div class="resource-label">网络带宽</div>
206
+ <div class="resource-value">
207
+ <div class="resource-bar">
208
+ <div class="resource-fill network" :style="{ width: resources.network + '%' }"></div>
209
+ </div>
210
+ <span>{{ resources.network }}%</span>
211
+ </div>
212
+ </div>
213
+ </div>
214
+ </div>
215
+ </div>
216
+
217
+ <!-- 空状态 -->
218
+ <div class="empty-state" v-else>
219
+ <i class="bi bi-diagram-3"></i>
220
+ <h3>选择数据库连接开始监控</h3>
221
+ <p>从上方选择一个数据库连接以查看实时监控数据</p>
222
+ </div>
223
+ </div>
224
+ </template>
225
+
226
+ <script lang="ts" setup>
227
+ import { ref, onMounted, onUnmounted, nextTick } from 'vue';
228
+ import { ConnectionService } from '@/service/database';
229
+ import type { ConnectionEntity } from '@/typings/database';
230
+ import * as echarts from 'echarts';
231
+
232
+ const connectionService = new ConnectionService();
233
+
234
+ // 响应式数据
235
+ const selectedConnection = ref('');
236
+ const connections = ref<ConnectionEntity[]>([]);
237
+ const connectionStatus = ref<any>(null);
238
+ const slowQueries = ref<any[]>([]);
239
+ const resources = ref({
240
+ cpu: 0,
241
+ memory: 0,
242
+ disk: 0,
243
+ network: 0
244
+ });
245
+
246
+ const isRefreshing = ref(false);
247
+ const autoRefresh = ref(true);
248
+ const refreshInterval = ref(10000);
249
+ const selectedTimeRange = ref('1h');
250
+ const refreshTimer = ref<any>(null);
251
+
252
+ // 图表相关
253
+ const performanceChart = ref<HTMLDivElement>();
254
+ const connectionsChart = ref<HTMLDivElement>();
255
+ const performanceChartInstance = ref<echarts.ECharts | null>(null);
256
+ const connectionsChartInstance = ref<echarts.ECharts | null>(null);
257
+
258
+ const timeRanges = [
259
+ { label: '1小时', value: '1h' },
260
+ { label: '6小时', value: '6h' },
261
+ { label: '24小时', value: '24h' },
262
+ { label: '7天', value: '7d' }
263
+ ];
264
+
265
+ // 方法
266
+ async function loadConnections() {
267
+ try {
268
+ const response = await connectionService.getAllConnections();
269
+ connections.value = response || [];
270
+ } catch (error) {
271
+ console.error('加载连接列表失败:', error);
272
+ }
273
+ }
274
+
275
+ async function loadMonitorData() {
276
+ if (!selectedConnection.value) return;
277
+
278
+ isRefreshing.value = true;
279
+
280
+ try {
281
+ // 模拟数据加载
282
+ await new Promise(resolve => setTimeout(resolve, 500));
283
+
284
+ // 模拟连接状态
285
+ connectionStatus.value = {
286
+ status: 'online',
287
+ uptime: '15天 3小时',
288
+ responseTime: Math.floor(Math.random() * 50) + 10,
289
+ activeQueries: Math.floor(Math.random() * 20) + 1,
290
+ totalQueries: 15420,
291
+ storageUsed: 1258291200,
292
+ storageTotal: 10737418240
293
+ };
294
+
295
+ // 模拟慢查询
296
+ slowQueries.value = [
297
+ {
298
+ id: 1,
299
+ timestamp: new Date(Date.now() - 5 * 60000),
300
+ executionTime: 2450,
301
+ type: 'SELECT',
302
+ sql: 'SELECT * FROM orders o JOIN customers c ON o.customer_id = c.id WHERE o.status = "pending" AND c.created_at > "2024-01-01"'
303
+ },
304
+ {
305
+ id: 2,
306
+ timestamp: new Date(Date.now() - 15 * 60000),
307
+ executionTime: 1890,
308
+ type: 'UPDATE',
309
+ sql: 'UPDATE products SET price = price * 1.1 WHERE category_id IN (SELECT id FROM categories WHERE name LIKE "%electronics%")'
310
+ },
311
+ {
312
+ id: 3,
313
+ timestamp: new Date(Date.now() - 30 * 60000),
314
+ executionTime: 3200,
315
+ type: 'DELETE',
316
+ sql: 'DELETE FROM user_sessions WHERE created_at < DATE_SUB(NOW(), INTERVAL 30 DAY) AND last_activity < DATE_SUB(NOW(), INTERVAL 7 DAY)'
317
+ }
318
+ ];
319
+
320
+ // 模拟资源使用
321
+ resources.value = {
322
+ cpu: Math.floor(Math.random() * 40) + 20,
323
+ memory: Math.floor(Math.random() * 30) + 40,
324
+ disk: Math.floor(Math.random() * 50) + 10,
325
+ network: Math.floor(Math.random() * 20) + 5
326
+ };
327
+
328
+ // 更新图表
329
+ updateCharts();
330
+
331
+ } catch (error) {
332
+ console.error('加载监控数据失败:', error);
333
+ } finally {
334
+ isRefreshing.value = false;
335
+ }
336
+ }
337
+
338
+ async function refreshData() {
339
+ await loadMonitorData();
340
+ }
341
+
342
+ function toggleAutoRefresh() {
343
+ if (autoRefresh.value) {
344
+ startAutoRefresh();
345
+ } else {
346
+ stopAutoRefresh();
347
+ }
348
+ }
349
+
350
+ function updateRefreshInterval() {
351
+ if (autoRefresh.value) {
352
+ stopAutoRefresh();
353
+ startAutoRefresh();
354
+ }
355
+ }
356
+
357
+ function startAutoRefresh() {
358
+ refreshTimer.value = setInterval(() => {
359
+ loadMonitorData();
360
+ }, refreshInterval.value);
361
+ }
362
+
363
+ function stopAutoRefresh() {
364
+ if (refreshTimer.value) {
365
+ clearInterval(refreshTimer.value);
366
+ refreshTimer.value = null;
367
+ }
368
+ }
369
+
370
+ function updateCharts() {
371
+ nextTick(() => {
372
+ initCharts();
373
+ updatePerformanceChart();
374
+ updateConnectionsChart();
375
+ });
376
+ }
377
+
378
+ function initCharts() {
379
+ if (performanceChart.value && !performanceChartInstance.value) {
380
+ performanceChartInstance.value = echarts.init(performanceChart.value);
381
+ }
382
+
383
+ if (connectionsChart.value && !connectionsChartInstance.value) {
384
+ connectionsChartInstance.value = echarts.init(connectionsChart.value);
385
+ }
386
+
387
+ // 监听窗口大小变化,自适应图表大小
388
+ window.addEventListener('resize', () => {
389
+ performanceChartInstance.value?.resize();
390
+ connectionsChartInstance.value?.resize();
391
+ });
392
+ }
393
+
394
+ function updatePerformanceChart() {
395
+ if (!performanceChartInstance.value) return;
396
+
397
+ // 生成模拟数据
398
+ const hours = 24;
399
+ const data = [];
400
+ const categories = [];
401
+
402
+ for (let i = 0; i < hours; i++) {
403
+ categories.push(`${i}时`);
404
+ data.push(Math.floor(Math.random() * 50) + 10);
405
+ }
406
+
407
+ const option: echarts.EChartsOption = {
408
+ tooltip: {
409
+ trigger: 'axis',
410
+ formatter: '{b0}<br/>响应时间: {c0}ms'
411
+ },
412
+ grid: {
413
+ left: '3%',
414
+ right: '4%',
415
+ bottom: '3%',
416
+ containLabel: true
417
+ },
418
+ xAxis: {
419
+ type: 'category',
420
+ boundaryGap: false,
421
+ data: categories,
422
+ axisLabel: {
423
+ fontSize: 12
424
+ }
425
+ },
426
+ yAxis: {
427
+ type: 'value',
428
+ name: '响应时间(ms)',
429
+ min: 0,
430
+ max: 60,
431
+ axisLabel: {
432
+ fontSize: 12
433
+ }
434
+ },
435
+ series: [
436
+ {
437
+ name: '响应时间',
438
+ type: 'line',
439
+ smooth: true,
440
+ data: data,
441
+ areaStyle: {
442
+ color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
443
+ { offset: 0, color: 'rgba(102, 126, 234, 0.5)' },
444
+ { offset: 1, color: 'rgba(102, 126, 234, 0.1)' }
445
+ ])
446
+ },
447
+ lineStyle: {
448
+ color: '#667eea',
449
+ width: 2
450
+ },
451
+ itemStyle: {
452
+ color: '#667eea'
453
+ }
454
+ }
455
+ ]
456
+ };
457
+
458
+ performanceChartInstance.value.setOption(option);
459
+ }
460
+
461
+ function updateConnectionsChart() {
462
+ if (!connectionsChartInstance.value) return;
463
+
464
+ // 生成模拟数据
465
+ const hours = 12;
466
+ const data = [];
467
+ const categories = [];
468
+
469
+ for (let i = 0; i < hours; i++) {
470
+ categories.push(`${i * 2}时`);
471
+ data.push(Math.floor(Math.random() * 50) + 10);
472
+ }
473
+
474
+ const option: echarts.EChartsOption = {
475
+ tooltip: {
476
+ trigger: 'axis',
477
+ formatter: '{b0}<br/>连接数: {c0}'
478
+ },
479
+ grid: {
480
+ left: '3%',
481
+ right: '4%',
482
+ bottom: '3%',
483
+ containLabel: true
484
+ },
485
+ xAxis: {
486
+ type: 'category',
487
+ data: categories,
488
+ axisLabel: {
489
+ fontSize: 12
490
+ }
491
+ },
492
+ yAxis: {
493
+ type: 'value',
494
+ name: '连接数',
495
+ min: 0,
496
+ max: 60,
497
+ axisLabel: {
498
+ fontSize: 12
499
+ }
500
+ },
501
+ series: [
502
+ {
503
+ name: '连接数',
504
+ type: 'bar',
505
+ data: data,
506
+ itemStyle: {
507
+ color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
508
+ { offset: 0, color: '#10b981' },
509
+ { offset: 1, color: '#059669' }
510
+ ]),
511
+ borderRadius: [4, 4, 0, 0]
512
+ },
513
+ barWidth: '60%'
514
+ }
515
+ ]
516
+ };
517
+
518
+ connectionsChartInstance.value.setOption(option);
519
+ }
520
+
521
+ function clearSlowQueries() {
522
+ slowQueries.value = [];
523
+ }
524
+
525
+ function analyzeQuery(query: any) {
526
+ console.log('分析查询:', query);
527
+ // 这里可以打开查询分析对话框
528
+ }
529
+
530
+ function getStatusIcon(status?: string): string {
531
+ switch (status) {
532
+ case 'online': return 'bi-check-circle';
533
+ case 'offline': return 'bi-x-circle';
534
+ case 'warning': return 'bi-exclamation-triangle';
535
+ default: return 'bi-question-circle';
536
+ }
537
+ }
538
+
539
+ function getStatusText(status?: string): string {
540
+ switch (status) {
541
+ case 'online': return '在线';
542
+ case 'offline': return '离线';
543
+ case 'warning': return '警告';
544
+ default: return '未知';
545
+ }
546
+ }
547
+
548
+ function getPerformanceLevel(responseTime?: number): string {
549
+ if (!responseTime) return '-';
550
+ if (responseTime < 50) return '优秀';
551
+ if (responseTime < 100) return '良好';
552
+ if (responseTime < 200) return '一般';
553
+ return '较慢';
554
+ }
555
+
556
+ function formatBytes(bytes?: number): string {
557
+ if (!bytes) return '0 B';
558
+ const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
559
+ const i = Math.floor(Math.log(bytes) / Math.log(1024));
560
+ return Math.round(bytes / Math.pow(1024, i) * 100) / 100 + ' ' + sizes[i];
561
+ }
562
+
563
+ function formatTime(timestamp: Date): string {
564
+ return new Date(timestamp).toLocaleString('zh-CN');
565
+ }
566
+
567
+ function getExecutionTimeClass(time: number): string {
568
+ if (time < 1000) return 'good';
569
+ if (time < 2000) return 'warning';
570
+ return 'critical';
571
+ }
572
+
573
+ function truncateSql(sql: string, maxLength = 50): string {
574
+ if (sql.length <= maxLength) return sql;
575
+ return sql.substring(0, maxLength) + '...';
576
+ }
577
+
578
+ // 生命周期
579
+ onMounted(() => {
580
+ loadConnections();
581
+ if (autoRefresh.value) {
582
+ startAutoRefresh();
583
+ }
584
+ });
585
+
586
+ onUnmounted(() => {
587
+ stopAutoRefresh();
588
+ });
589
+ </script>
590
+
591
+ <style scoped>
592
+ .database-monitor {
593
+ height: 100%;
594
+ display: flex;
595
+ flex-direction: column;
596
+ background: white;
597
+ border-radius: 12px;
598
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
599
+ overflow: hidden;
600
+ }
601
+
602
+ .monitor-header {
603
+ display: flex;
604
+ justify-content: space-between;
605
+ align-items: center;
606
+ padding: 1rem 1.5rem;
607
+ background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
608
+ border-bottom: 1px solid #e2e8f0;
609
+ }
610
+
611
+ .monitor-title {
612
+ display: flex;
613
+ align-items: center;
614
+ gap: 0.5rem;
615
+ font-weight: 600;
616
+ color: #1e293b;
617
+ font-size: 1.1rem;
618
+ }
619
+
620
+ .monitor-controls {
621
+ display: flex;
622
+ align-items: center;
623
+ gap: 1rem;
624
+ }
625
+
626
+ .connection-select {
627
+ padding: 0.5rem 1rem;
628
+ border: 1px solid #d1d5db;
629
+ border-radius: 8px;
630
+ background: white;
631
+ min-width: 200px;
632
+ font-size: 0.875rem;
633
+ }
634
+
635
+ .btn-refresh {
636
+ display: flex;
637
+ align-items: center;
638
+ gap: 0.25rem;
639
+ padding: 0.5rem 1rem;
640
+ border: 1px solid #d1d5db;
641
+ border-radius: 8px;
642
+ background: white;
643
+ color: #374151;
644
+ font-size: 0.875rem;
645
+ cursor: pointer;
646
+ transition: all 0.2s ease;
647
+ }
648
+
649
+ .btn-refresh:hover:not(:disabled) {
650
+ background: #f3f4f6;
651
+ transform: translateY(-1px);
652
+ }
653
+
654
+ .btn-refresh:disabled {
655
+ opacity: 0.5;
656
+ cursor: not-allowed;
657
+ }
658
+
659
+ .btn-refresh .spin {
660
+ animation: spin 1s linear infinite;
661
+ }
662
+
663
+ @keyframes spin {
664
+ from { transform: rotate(0deg); }
665
+ to { transform: rotate(360deg); }
666
+ }
667
+
668
+ .auto-refresh {
669
+ display: flex;
670
+ align-items: center;
671
+ gap: 0.5rem;
672
+ font-size: 0.875rem;
673
+ color: #374151;
674
+ }
675
+
676
+ .auto-refresh select {
677
+ padding: 0.25rem 0.5rem;
678
+ border: 1px solid #d1d5db;
679
+ border-radius: 4px;
680
+ font-size: 0.75rem;
681
+ }
682
+
683
+ .monitor-content {
684
+ flex: 1;
685
+ overflow-y: auto;
686
+ padding: 1.5rem;
687
+ }
688
+
689
+ /* 状态概览 */
690
+ .status-overview {
691
+ display: grid;
692
+ grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
693
+ gap: 1rem;
694
+ margin-bottom: 2rem;
695
+ }
696
+
697
+ .status-card {
698
+ display: flex;
699
+ align-items: center;
700
+ gap: 1rem;
701
+ padding: 1.25rem;
702
+ background: white;
703
+ border: 1px solid #e5e7eb;
704
+ border-radius: 12px;
705
+ transition: all 0.2s ease;
706
+ }
707
+
708
+ .status-card:hover {
709
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
710
+ transform: translateY(-2px);
711
+ }
712
+
713
+ .status-icon {
714
+ width: 48px;
715
+ height: 48px;
716
+ border-radius: 12px;
717
+ display: flex;
718
+ align-items: center;
719
+ justify-content: center;
720
+ color: white;
721
+ font-size: 1.25rem;
722
+ }
723
+
724
+ .status-icon.online {
725
+ background: linear-gradient(135deg, #10b981 0%, #059669 100%);
726
+ }
727
+
728
+ .status-icon.offline {
729
+ background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
730
+ }
731
+
732
+ .status-icon.warning {
733
+ background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
734
+ }
735
+
736
+ .status-icon:not([class*="online"]):not([class*="offline"]):not([class*="warning"]) {
737
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
738
+ }
739
+
740
+ .status-info {
741
+ flex: 1;
742
+ }
743
+
744
+ .status-title {
745
+ font-size: 0.875rem;
746
+ color: #6b7280;
747
+ margin-bottom: 0.25rem;
748
+ }
749
+
750
+ .status-value {
751
+ font-size: 1.5rem;
752
+ font-weight: 700;
753
+ color: #1e293b;
754
+ margin-bottom: 0.25rem;
755
+ }
756
+
757
+ .status-detail {
758
+ font-size: 0.75rem;
759
+ color: #9ca3af;
760
+ }
761
+
762
+ /* 图表区域 */
763
+ .charts-section {
764
+ display: grid;
765
+ grid-template-columns: 2fr 1fr;
766
+ gap: 1.5rem;
767
+ margin-bottom: 2rem;
768
+ }
769
+
770
+ .chart-container {
771
+ background: white;
772
+ border: 1px solid #e5e7eb;
773
+ border-radius: 12px;
774
+ padding: 1.5rem;
775
+ }
776
+
777
+ .chart-header {
778
+ display: flex;
779
+ justify-content: space-between;
780
+ align-items: center;
781
+ margin-bottom: 1rem;
782
+ }
783
+
784
+ .chart-header h3 {
785
+ font-size: 1.125rem;
786
+ font-weight: 600;
787
+ color: #1e293b;
788
+ margin: 0;
789
+ }
790
+
791
+ .chart-controls {
792
+ display: flex;
793
+ gap: 0.25rem;
794
+ }
795
+
796
+ .range-btn {
797
+ padding: 0.25rem 0.75rem;
798
+ border: 1px solid #e5e7eb;
799
+ background: white;
800
+ border-radius: 6px;
801
+ font-size: 0.75rem;
802
+ cursor: pointer;
803
+ transition: all 0.2s ease;
804
+ }
805
+
806
+ .range-btn:hover {
807
+ background: #f3f4f6;
808
+ }
809
+
810
+ .range-btn.active {
811
+ background: #667eea;
812
+ color: white;
813
+ border-color: #667eea;
814
+ }
815
+
816
+ .chart-content {
817
+ height: 300px;
818
+ display: flex;
819
+ align-items: center;
820
+ justify-content: center;
821
+ }
822
+
823
+ .echart-container {
824
+ width: 100%;
825
+ height: 100%;
826
+ }
827
+
828
+ /* 慢查询部分 */
829
+ .slow-queries-section {
830
+ background: white;
831
+ border: 1px solid #e5e7eb;
832
+ border-radius: 12px;
833
+ padding: 1.5rem;
834
+ margin-bottom: 2rem;
835
+ }
836
+
837
+ .section-header {
838
+ display: flex;
839
+ justify-content: space-between;
840
+ align-items: center;
841
+ margin-bottom: 1rem;
842
+ }
843
+
844
+ .section-header h3 {
845
+ font-size: 1.125rem;
846
+ font-weight: 600;
847
+ color: #1e293b;
848
+ margin: 0;
849
+ }
850
+
851
+ .btn-clear {
852
+ display: flex;
853
+ align-items: center;
854
+ gap: 0.25rem;
855
+ padding: 0.5rem 1rem;
856
+ border: 1px solid #ef4444;
857
+ border-radius: 8px;
858
+ background: white;
859
+ color: #ef4444;
860
+ font-size: 0.875rem;
861
+ cursor: pointer;
862
+ transition: all 0.2s ease;
863
+ }
864
+
865
+ .btn-clear:hover {
866
+ background: #ef4444;
867
+ color: white;
868
+ }
869
+
870
+ .queries-table-wrapper {
871
+ overflow-x: auto;
872
+ }
873
+
874
+ .queries-table {
875
+ width: 100%;
876
+ border-collapse: collapse;
877
+ font-size: 0.875rem;
878
+ }
879
+
880
+ .queries-table th {
881
+ background: #f8fafc;
882
+ padding: 0.75rem;
883
+ text-align: left;
884
+ font-weight: 600;
885
+ color: #374151;
886
+ border-bottom: 2px solid #e5e7eb;
887
+ }
888
+
889
+ .queries-table td {
890
+ padding: 0.75rem;
891
+ border-bottom: 1px solid #f3f4f6;
892
+ }
893
+
894
+ .execution-time {
895
+ font-weight: 600;
896
+ padding: 0.25rem 0.5rem;
897
+ border-radius: 4px;
898
+ }
899
+
900
+ .execution-time.good {
901
+ color: #10b981;
902
+ background: #d1fae5;
903
+ }
904
+
905
+ .execution-time.warning {
906
+ color: #f59e0b;
907
+ background: #fef3c7;
908
+ }
909
+
910
+ .execution-time.critical {
911
+ color: #ef4444;
912
+ background: #fee2e2;
913
+ }
914
+
915
+ .query-type {
916
+ padding: 0.25rem 0.5rem;
917
+ border-radius: 4px;
918
+ font-weight: 600;
919
+ color: white;
920
+ font-size: 0.75rem;
921
+ }
922
+
923
+ .query-type.select { background: #3b82f6; }
924
+ .query-type.insert { background: #10b981; }
925
+ .query-type.update { background: #f59e0b; }
926
+ .query-type.delete { background: #ef4444; }
927
+
928
+ .query-sql {
929
+ max-width: 300px;
930
+ overflow: hidden;
931
+ text-overflow: ellipsis;
932
+ white-space: nowrap;
933
+ font-family: 'Consolas', 'Monaco', monospace;
934
+ font-size: 0.8rem;
935
+ }
936
+
937
+ .btn-analyze {
938
+ padding: 0.25rem 0.5rem;
939
+ border: 1px solid #667eea;
940
+ border-radius: 4px;
941
+ background: white;
942
+ color: #667eea;
943
+ font-size: 0.75rem;
944
+ cursor: pointer;
945
+ transition: all 0.2s ease;
946
+ }
947
+
948
+ .btn-analyze:hover {
949
+ background: #667eea;
950
+ color: white;
951
+ }
952
+
953
+ /* 空状态 */
954
+ .empty-state {
955
+ text-align: center;
956
+ padding: 3rem 2rem;
957
+ color: #6b7280;
958
+ }
959
+
960
+ .empty-state i {
961
+ font-size: 3rem;
962
+ margin-bottom: 1rem;
963
+ color: #d1d5db;
964
+ }
965
+
966
+ .empty-state h3 {
967
+ font-size: 1.25rem;
968
+ margin-bottom: 0.5rem;
969
+ color: #374151;
970
+ }
971
+
972
+ .empty-state p {
973
+ margin: 0;
974
+ font-size: 0.875rem;
975
+ }
976
+
977
+ .empty-state small {
978
+ font-size: 0.75rem;
979
+ color: #9ca3af;
980
+ }
981
+
982
+ /* 资源使用部分 */
983
+ .resources-section {
984
+ background: white;
985
+ border: 1px solid #e5e7eb;
986
+ border-radius: 12px;
987
+ padding: 1.5rem;
988
+ }
989
+
990
+ .resources-grid {
991
+ display: grid;
992
+ grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
993
+ gap: 1.5rem;
994
+ }
995
+
996
+ .resource-item {
997
+ display: flex;
998
+ flex-direction: column;
999
+ gap: 0.5rem;
1000
+ }
1001
+
1002
+ .resource-label {
1003
+ font-size: 0.875rem;
1004
+ color: #6b7280;
1005
+ font-weight: 500;
1006
+ }
1007
+
1008
+ .resource-value {
1009
+ display: flex;
1010
+ align-items: center;
1011
+ gap: 0.75rem;
1012
+ }
1013
+
1014
+ .resource-bar {
1015
+ flex: 1;
1016
+ height: 8px;
1017
+ background: #f3f4f6;
1018
+ border-radius: 4px;
1019
+ overflow: hidden;
1020
+ }
1021
+
1022
+ .resource-fill {
1023
+ height: 100%;
1024
+ transition: width 0.3s ease;
1025
+ }
1026
+
1027
+ .resource-fill.cpu { background: linear-gradient(90deg, #3b82f6, #1d4ed8); }
1028
+ .resource-fill.memory { background: linear-gradient(90deg, #10b981, #059669); }
1029
+ .resource-fill.disk { background: linear-gradient(90deg, #f59e0b, #d97706); }
1030
+ .resource-fill.network { background: linear-gradient(90deg, #8b5cf6, #7c3aed); }
1031
+
1032
+ .resource-value span {
1033
+ font-weight: 600;
1034
+ color: #1e293b;
1035
+ min-width: 40px;
1036
+ text-align: right;
1037
+ }
1038
+
1039
+ /* 响应式设计 */
1040
+ @media (max-width: 1024px) {
1041
+ .charts-section {
1042
+ grid-template-columns: 1fr;
1043
+ }
1044
+
1045
+ .status-overview {
1046
+ grid-template-columns: repeat(2, 1fr);
1047
+ }
1048
+ }
1049
+
1050
+ @media (max-width: 768px) {
1051
+ .monitor-header {
1052
+ flex-direction: column;
1053
+ gap: 1rem;
1054
+ align-items: stretch;
1055
+ }
1056
+
1057
+ .monitor-controls {
1058
+ flex-wrap: wrap;
1059
+ }
1060
+
1061
+ .connection-select {
1062
+ width: 100%;
1063
+ }
1064
+
1065
+ .status-overview {
1066
+ grid-template-columns: 1fr;
1067
+ }
1068
+
1069
+ .resources-grid {
1070
+ grid-template-columns: 1fr;
1071
+ }
1072
+
1073
+ .monitor-content {
1074
+ padding: 1rem;
1075
+ }
1076
+
1077
+ .queries-table {
1078
+ font-size: 0.75rem;
1079
+ }
1080
+
1081
+ .queries-table th,
1082
+ .queries-table td {
1083
+ padding: 0.5rem;
1084
+ }
1085
+ }
1086
+ </style>