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,1046 @@
1
+ <template>
2
+ <div class="sql-query-editor">
3
+ <div class="query-header">
4
+ <div class="query-title">
5
+ <i class="bi bi-terminal"></i>
6
+ <span>SQL查询编辑器</span>
7
+ </div>
8
+ <div class="query-controls">
9
+ <select v-model="selectedConnection" class="connection-select">
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-run" @click="executeQuery" :disabled="!querySql || !selectedConnection">
16
+ <i class="bi bi-play-fill"></i>
17
+ <span>执行</span>
18
+ </button>
19
+ <button class="btn-format" @click="formatSql" :disabled="!querySql">
20
+ <i class="bi bi-code-slash"></i>
21
+ <span>格式化</span>
22
+ </button>
23
+ <button class="btn-clear" @click="clearQuery">
24
+ <i class="bi bi-trash"></i>
25
+ <span>清空</span>
26
+ </button>
27
+ <button class="btn-save" @click="saveQuery" :disabled="!querySql">
28
+ <i class="bi bi-save"></i>
29
+ <span>保存</span>
30
+ </button>
31
+ </div>
32
+ </div>
33
+
34
+ <div class="query-editor-wrapper">
35
+ <div class="editor-toolbar">
36
+ <div class="toolbar-left">
37
+ <button
38
+ v-for="snippet in sqlSnippets"
39
+ :key="snippet.name"
40
+ class="snippet-btn"
41
+ @click="insertSnippet(snippet)"
42
+ :title="snippet.description"
43
+ >
44
+ <i :class="snippet.icon"></i>
45
+ <span>{{ snippet.name }}</span>
46
+ </button>
47
+ </div>
48
+ <div class="toolbar-right">
49
+ <span class="line-info">行: {{ currentLine }}, 列: {{ currentColumn }}</span>
50
+ <span class="sql-mode">{{ getSqlModeLabel() }}</span>
51
+ </div>
52
+ </div>
53
+
54
+ <div class="editor-container">
55
+ <textarea
56
+ ref="sqlEditor"
57
+ v-model="querySql"
58
+ class="sql-editor"
59
+ placeholder="在此输入SQL查询语句..."
60
+ @input="handleInput"
61
+ @keydown="handleKeydown"
62
+ @scroll="syncScroll"
63
+ spellcheck="false"
64
+ ></textarea>
65
+ <div class="line-numbers" ref="lineNumbers" @scroll="syncScroll">
66
+ <div
67
+ v-for="line in lineCount"
68
+ :key="line"
69
+ class="line-number"
70
+ :class="{ 'current-line': line === currentLine }"
71
+ >
72
+ {{ line }}
73
+ </div>
74
+ </div>
75
+ </div>
76
+ </div>
77
+
78
+ <div class="query-results" v-if="queryResults.length > 0 || queryError">
79
+ <div class="results-header">
80
+ <div class="results-info">
81
+ <i class="bi bi-table"></i>
82
+ <span>查询结果</span>
83
+ <span class="results-count" v-if="queryResults.length > 0">
84
+ ({{ queryResults.length }} 行)
85
+ </span>
86
+ </div>
87
+ <div class="results-actions">
88
+ <button class="btn-export" @click="exportResults" v-if="queryResults.length > 0">
89
+ <i class="bi bi-download"></i>
90
+ <span>导出</span>
91
+ </button>
92
+ <button class="btn-clear-results" @click="clearResults">
93
+ <i class="bi bi-x-lg"></i>
94
+ <span>清除</span>
95
+ </button>
96
+ </div>
97
+ </div>
98
+
99
+ <div class="results-content">
100
+ <div class="error-message" v-if="queryError">
101
+ <i class="bi bi-exclamation-triangle"></i>
102
+ <div>
103
+ <strong>查询错误:</strong>
104
+ <p>{{ queryError }}</p>
105
+ </div>
106
+ </div>
107
+
108
+ <div class="results-table-wrapper" v-else>
109
+ <table class="results-table">
110
+ <thead>
111
+ <tr>
112
+ <th v-for="column in columns" :key="column" @click="sortByColumn(column)">
113
+ {{ column }}
114
+ <i class="bi bi-arrow-down-up" v-if="sortColumn === column"></i>
115
+ </th>
116
+ </tr>
117
+ </thead>
118
+ <tbody>
119
+ <tr v-for="(row, index) in sortedResults" :key="index">
120
+ <td v-for="column in columns" :key="column" :title="row[column]">
121
+ {{ formatCellValue(row[column]) }}
122
+ </td>
123
+ </tr>
124
+ </tbody>
125
+ </table>
126
+
127
+ <div class="pagination" v-if="totalPages > 1">
128
+ <button @click="prevPage" :disabled="currentPage === 1">
129
+ <i class="bi bi-chevron-left"></i>
130
+ </button>
131
+ <span class="page-info">{{ currentPage }} / {{ totalPages }}</span>
132
+ <button @click="nextPage" :disabled="currentPage === totalPages">
133
+ <i class="bi bi-chevron-right"></i>
134
+ </button>
135
+ </div>
136
+ </div>
137
+ </div>
138
+ </div>
139
+
140
+ <!-- 保存查询对话框 -->
141
+ <div class="modal-overlay" v-if="showSaveDialog">
142
+ <div class="modal-content">
143
+ <div class="modal-header">
144
+ <h3>保存SQL查询</h3>
145
+ <button class="modal-close" @click="closeSaveDialog">
146
+ <i class="bi bi-x-lg"></i>
147
+ </button>
148
+ </div>
149
+ <div class="modal-body">
150
+ <div class="form-group">
151
+ <label>查询名称</label>
152
+ <input v-model="queryName" type="text" placeholder="输入查询名称" class="form-input">
153
+ </div>
154
+ <div class="form-group">
155
+ <label>描述</label>
156
+ <textarea v-model="queryDescription" placeholder="输入查询描述" class="form-textarea" rows="3"></textarea>
157
+ </div>
158
+ </div>
159
+ <div class="modal-footer">
160
+ <button class="btn-cancel" @click="closeSaveDialog">取消</button>
161
+ <button class="btn-confirm" @click="confirmSave" :disabled="!queryName">保存</button>
162
+ </div>
163
+ </div>
164
+ </div>
165
+ </div>
166
+ </template>
167
+
168
+ <script lang="ts" setup>
169
+ import { ref, computed, onMounted, nextTick, watch } from 'vue';
170
+ import { ConnectionService } from '@/service/database';
171
+ import type { ConnectionEntity } from '@/typings/database';
172
+
173
+ const connectionService = new ConnectionService();
174
+
175
+ // 响应式数据
176
+ const querySql = ref('');
177
+ const selectedConnection = ref('');
178
+ const connections = ref<ConnectionEntity[]>([]);
179
+ const queryResults = ref<any[]>([]);
180
+ const queryError = ref('');
181
+ const currentLine = ref(1);
182
+ const currentColumn = ref(1);
183
+ const showSaveDialog = ref(false);
184
+ const queryName = ref('');
185
+ const queryDescription = ref('');
186
+
187
+ // 分页相关
188
+ const currentPage = ref(1);
189
+ const pageSize = ref(50);
190
+
191
+ // 排序相关
192
+ const sortColumn = ref('');
193
+ const sortDirection = ref<'asc' | 'desc'>('asc');
194
+
195
+ // SQL代码片段
196
+ const sqlSnippets = ref([
197
+ { name: 'SELECT', icon: 'bi-cursor-text', description: 'SELECT语句模板', template: 'SELECT * FROM table_name WHERE condition;' },
198
+ { name: 'INSERT', icon: 'bi-plus-square', description: 'INSERT语句模板', template: 'INSERT INTO table_name (column1, column2) VALUES (value1, value2);' },
199
+ { name: 'UPDATE', icon: 'bi-pencil-square', description: 'UPDATE语句模板', template: 'UPDATE table_name SET column1 = value1 WHERE condition;' },
200
+ { name: 'DELETE', icon: 'bi-trash', description: 'DELETE语句模板', template: 'DELETE FROM table_name WHERE condition;' },
201
+ { name: 'JOIN', icon: 'bi-link-45deg', description: 'JOIN语句模板', template: 'SELECT a.*, b.* FROM table_a a JOIN table_b b ON a.id = b.id;' },
202
+ { name: 'FUNCTION', icon: 'bi-gear', description: '函数模板', template: 'SELECT COUNT(*), AVG(column), MAX(column), MIN(column) FROM table_name;' }
203
+ ]);
204
+
205
+ // 计算属性
206
+ const lineCount = computed(() => {
207
+ return querySql.value.split('\n').length;
208
+ });
209
+
210
+ const columns = computed(() => {
211
+ if (queryResults.value.length === 0) return [];
212
+ return Object.keys(queryResults.value[0]);
213
+ });
214
+
215
+ const sortedResults = computed(() => {
216
+ if (!sortColumn.value) return queryResults.value;
217
+
218
+ return [...queryResults.value].sort((a, b) => {
219
+ const aVal = a[sortColumn.value];
220
+ const bVal = b[sortColumn.value];
221
+
222
+ if (aVal === null || aVal === undefined) return 1;
223
+ if (bVal === null || bVal === undefined) return -1;
224
+
225
+ let comparison = 0;
226
+ if (typeof aVal === 'number' && typeof bVal === 'number') {
227
+ comparison = aVal - bVal;
228
+ } else {
229
+ comparison = String(aVal).localeCompare(String(bVal));
230
+ }
231
+
232
+ return sortDirection.value === 'asc' ? comparison : -comparison;
233
+ });
234
+ });
235
+
236
+ const totalPages = computed(() => {
237
+ return Math.ceil(sortedResults.value.length / pageSize.value);
238
+ });
239
+
240
+ const paginatedResults = computed(() => {
241
+ const start = (currentPage.value - 1) * pageSize.value;
242
+ const end = start + pageSize.value;
243
+ return sortedResults.value.slice(start, end);
244
+ });
245
+
246
+ // 引用
247
+ const sqlEditor = ref<HTMLTextAreaElement>();
248
+ const lineNumbers = ref<HTMLDivElement>();
249
+
250
+ // 方法
251
+ async function loadConnections() {
252
+ try {
253
+ const response = await connectionService.getAllConnections();
254
+ connections.value = response || [];
255
+ } catch (error) {
256
+ console.error('加载连接列表失败:', error);
257
+ }
258
+ }
259
+
260
+ function handleInput() {
261
+ updateCursorInfo();
262
+ updateLineNumbers();
263
+ }
264
+
265
+ function handleKeydown(event: KeyboardEvent) {
266
+ // Tab键插入缩进
267
+ if (event.key === 'Tab') {
268
+ event.preventDefault();
269
+ const textarea = sqlEditor.value;
270
+ if (!textarea) return;
271
+
272
+ const start = textarea.selectionStart;
273
+ const end = textarea.selectionEnd;
274
+ const text = querySql.value;
275
+
276
+ // 插入2个空格作为缩进
277
+ const newText = text.substring(0, start) + ' ' + text.substring(end);
278
+ querySql.value = newText;
279
+
280
+ // 设置光标位置
281
+ nextTick(() => {
282
+ textarea.selectionStart = textarea.selectionEnd = start + 2;
283
+ updateCursorInfo();
284
+ });
285
+ }
286
+
287
+ // Ctrl+Enter 执行查询
288
+ if (event.ctrlKey && event.key === 'Enter') {
289
+ executeQuery();
290
+ }
291
+ }
292
+
293
+ function updateCursorInfo() {
294
+ const textarea = sqlEditor.value;
295
+ if (!textarea) return;
296
+
297
+ const text = textarea.value;
298
+ const position = textarea.selectionStart;
299
+
300
+ const textBeforeCursor = text.substring(0, position);
301
+ const lines = textBeforeCursor.split('\n');
302
+
303
+ currentLine.value = lines.length;
304
+ currentColumn.value = lines[lines.length - 1].length + 1;
305
+ }
306
+
307
+ function updateLineNumbers() {
308
+ // 行号由模板自动更新
309
+ }
310
+
311
+ function syncScroll() {
312
+ if (sqlEditor.value && lineNumbers.value) {
313
+ lineNumbers.value.scrollTop = sqlEditor.value.scrollTop;
314
+ }
315
+ }
316
+
317
+ function insertSnippet(snippet: any) {
318
+ const textarea = sqlEditor.value;
319
+ if (!textarea) return;
320
+
321
+ const start = textarea.selectionStart;
322
+ const end = textarea.selectionEnd;
323
+ const text = querySql.value;
324
+
325
+ const newText = text.substring(0, start) + snippet.template + text.substring(end);
326
+ querySql.value = newText;
327
+
328
+ nextTick(() => {
329
+ textarea.focus();
330
+ updateCursorInfo();
331
+ });
332
+ }
333
+
334
+ async function executeQuery() {
335
+ if (!querySql.value.trim() || !selectedConnection.value) {
336
+ return;
337
+ }
338
+
339
+ queryError.value = '';
340
+ queryResults.value = [];
341
+
342
+ try {
343
+ // 这里需要调用实际的查询API
344
+ // const response = await databaseService.executeQuery(selectedConnection.value, querySql.value);
345
+
346
+ // 模拟查询结果
347
+ const mockResults = [
348
+ { id: 1, name: '测试数据1', email: 'test1@example.com', created_at: '2024-01-01' },
349
+ { id: 2, name: '测试数据2', email: 'test2@example.com', created_at: '2024-01-02' },
350
+ { id: 3, name: '测试数据3', email: 'test3@example.com', created_at: '2024-01-03' }
351
+ ];
352
+
353
+ queryResults.value = mockResults;
354
+ currentPage.value = 1;
355
+
356
+ } catch (error: any) {
357
+ queryError.value = error.message || '查询执行失败';
358
+ }
359
+ }
360
+
361
+ function formatSql() {
362
+ // 简单的SQL格式化
363
+ let formatted = querySql.value
364
+ .replace(/\s+/g, ' ')
365
+ .replace(/,/g, ',\n ')
366
+ .replace(/\bFROM\b/gi, '\nFROM')
367
+ .replace(/\bWHERE\b/gi, '\nWHERE')
368
+ .replace(/\bORDER BY\b/gi, '\nORDER BY')
369
+ .replace(/\bGROUP BY\b/gi, '\nGROUP BY')
370
+ .replace(/\bHAVING\b/gi, '\nHAVING')
371
+ .replace(/\bLIMIT\b/gi, '\nLIMIT')
372
+ .trim();
373
+
374
+ querySql.value = formatted;
375
+ }
376
+
377
+ function clearQuery() {
378
+ querySql.value = '';
379
+ queryError.value = '';
380
+ queryResults.value = [];
381
+ currentPage.value = 1;
382
+ }
383
+
384
+ function clearResults() {
385
+ queryResults.value = [];
386
+ queryError.value = '';
387
+ }
388
+
389
+ function sortByColumn(column: string) {
390
+ if (sortColumn.value === column) {
391
+ sortDirection.value = sortDirection.value === 'asc' ? 'desc' : 'asc';
392
+ } else {
393
+ sortColumn.value = column;
394
+ sortDirection.value = 'asc';
395
+ }
396
+ }
397
+
398
+ function exportResults() {
399
+ if (queryResults.value.length === 0) return;
400
+
401
+ // 生成表头映射
402
+ const headers: Record<string, string> = {};
403
+ columns.value.forEach(col => {
404
+ headers[col] = col;
405
+ });
406
+
407
+ // 使用导出工具
408
+ import('../utils/export').then(({ exportDataToCSV }) => {
409
+ exportDataToCSV(queryResults.value, headers, `query_results_${new Date().getTime()}.csv`);
410
+ });
411
+ }
412
+
413
+ function formatCellValue(value: any): string {
414
+ if (value === null || value === undefined) return '';
415
+
416
+ // 尝试检测并格式化 JSON 数据
417
+ let strValue = String(value);
418
+ if (typeof value === 'string') {
419
+ // 检查是否可能是 JSON 字符串
420
+ const trimmedValue = strValue.trim();
421
+ if ((trimmedValue.startsWith('{') && trimmedValue.endsWith('}')) ||
422
+ (trimmedValue.startsWith('[') && trimmedValue.endsWith(']'))) {
423
+ try {
424
+ const parsed = JSON.parse(trimmedValue);
425
+ // 格式化 JSON 并限制长度
426
+ const formatted = JSON.stringify(parsed, null, 2);
427
+ if (formatted.length > 50) {
428
+ return formatted.substring(0, 50) + '...';
429
+ }
430
+ return formatted;
431
+ } catch (e) {
432
+ // 不是有效的 JSON,继续处理
433
+ }
434
+ }
435
+ } else if (typeof value === 'object') {
436
+ // 对于对象或数组类型,直接格式化
437
+ try {
438
+ const formatted = JSON.stringify(value, null, 2);
439
+ if (formatted.length > 50) {
440
+ return formatted.substring(0, 50) + '...';
441
+ }
442
+ return formatted;
443
+ } catch (e) {
444
+ // 格式化失败,继续处理
445
+ }
446
+ }
447
+
448
+ // 对于普通字符串,限制显示长度
449
+ if (strValue.length > 50) return strValue.substring(0, 50) + '...';
450
+
451
+ return strValue;
452
+ }
453
+
454
+ function getSqlModeLabel(): string {
455
+ const sql = querySql.value.toUpperCase().trim();
456
+ if (sql.startsWith('SELECT')) return 'SELECT';
457
+ if (sql.startsWith('INSERT')) return 'INSERT';
458
+ if (sql.startsWith('UPDATE')) return 'UPDATE';
459
+ if (sql.startsWith('DELETE')) return 'DELETE';
460
+ if (sql.startsWith('CREATE')) return 'CREATE';
461
+ if (sql.startsWith('DROP')) return 'DROP';
462
+ if (sql.startsWith('ALTER')) return 'ALTER';
463
+ return 'SQL';
464
+ }
465
+
466
+ function saveQuery() {
467
+ showSaveDialog.value = true;
468
+ }
469
+
470
+ function closeSaveDialog() {
471
+ showSaveDialog.value = false;
472
+ queryName.value = '';
473
+ queryDescription.value = '';
474
+ }
475
+
476
+ function confirmSave() {
477
+ // 保存查询逻辑
478
+ console.log('保存查询:', {
479
+ name: queryName.value,
480
+ description: queryDescription.value,
481
+ sql: querySql.value,
482
+ connectionId: selectedConnection.value
483
+ });
484
+
485
+ closeSaveDialog();
486
+ }
487
+
488
+ function nextPage() {
489
+ if (currentPage.value < totalPages.value) {
490
+ currentPage.value++;
491
+ }
492
+ }
493
+
494
+ function prevPage() {
495
+ if (currentPage.value > 1) {
496
+ currentPage.value--;
497
+ }
498
+ }
499
+
500
+ // 生命周期
501
+ onMounted(() => {
502
+ loadConnections();
503
+ });
504
+
505
+ // 监听查询文本变化
506
+ watch(querySql, () => {
507
+ nextTick(() => {
508
+ updateCursorInfo();
509
+ });
510
+ });
511
+ </script>
512
+
513
+ <style scoped>
514
+ .sql-query-editor {
515
+ display: flex;
516
+ flex-direction: column;
517
+ height: 100%;
518
+ background: white;
519
+ border-radius: 12px;
520
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
521
+ overflow: hidden;
522
+ }
523
+
524
+ .query-header {
525
+ display: flex;
526
+ justify-content: space-between;
527
+ align-items: center;
528
+ padding: 1rem 1.5rem;
529
+ background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
530
+ border-bottom: 1px solid #e2e8f0;
531
+ }
532
+
533
+ .query-title {
534
+ display: flex;
535
+ align-items: center;
536
+ gap: 0.5rem;
537
+ font-weight: 600;
538
+ color: #1e293b;
539
+ font-size: 1.1rem;
540
+ }
541
+
542
+ .query-controls {
543
+ display: flex;
544
+ align-items: center;
545
+ gap: 0.5rem;
546
+ }
547
+
548
+ .connection-select {
549
+ padding: 0.5rem 1rem;
550
+ border: 1px solid #d1d5db;
551
+ border-radius: 8px;
552
+ background: white;
553
+ min-width: 200px;
554
+ font-size: 0.875rem;
555
+ }
556
+
557
+ .query-controls button {
558
+ display: flex;
559
+ align-items: center;
560
+ gap: 0.25rem;
561
+ padding: 0.5rem 1rem;
562
+ border: 1px solid #d1d5db;
563
+ border-radius: 8px;
564
+ background: white;
565
+ color: #374151;
566
+ font-size: 0.875rem;
567
+ cursor: pointer;
568
+ transition: all 0.2s ease;
569
+ }
570
+
571
+ .query-controls button:hover:not(:disabled) {
572
+ background: #f3f4f6;
573
+ transform: translateY(-1px);
574
+ }
575
+
576
+ .query-controls button:disabled {
577
+ opacity: 0.5;
578
+ cursor: not-allowed;
579
+ }
580
+
581
+ .btn-run {
582
+ background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
583
+ color: white !important;
584
+ border: none !important;
585
+ }
586
+
587
+ .btn-run:hover:not(:disabled) {
588
+ background: linear-gradient(135deg, #059669 0%, #047857 100%) !important;
589
+ }
590
+
591
+ .btn-format {
592
+ background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
593
+ color: white !important;
594
+ border: none !important;
595
+ }
596
+
597
+ .btn-save {
598
+ background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%) !important;
599
+ color: white !important;
600
+ border: none !important;
601
+ }
602
+
603
+ .query-editor-wrapper {
604
+ flex: 1;
605
+ display: flex;
606
+ flex-direction: column;
607
+ min-height: 300px;
608
+ }
609
+
610
+ .editor-toolbar {
611
+ display: flex;
612
+ justify-content: space-between;
613
+ align-items: center;
614
+ padding: 0.5rem 1rem;
615
+ background: #f8fafc;
616
+ border-bottom: 1px solid #e5e7eb;
617
+ font-size: 0.875rem;
618
+ }
619
+
620
+ .toolbar-left {
621
+ display: flex;
622
+ gap: 0.25rem;
623
+ }
624
+
625
+ .snippet-btn {
626
+ display: flex;
627
+ align-items: center;
628
+ gap: 0.25rem;
629
+ padding: 0.25rem 0.5rem;
630
+ background: white;
631
+ border: 1px solid #d1d5db;
632
+ border-radius: 6px;
633
+ font-size: 0.75rem;
634
+ cursor: pointer;
635
+ transition: all 0.2s ease;
636
+ }
637
+
638
+ .snippet-btn:hover {
639
+ background: #667eea;
640
+ color: white;
641
+ border-color: #667eea;
642
+ }
643
+
644
+ .toolbar-right {
645
+ display: flex;
646
+ gap: 1rem;
647
+ align-items: center;
648
+ color: #6b7280;
649
+ }
650
+
651
+ .sql-mode {
652
+ background: #667eea;
653
+ color: white;
654
+ padding: 0.125rem 0.5rem;
655
+ border-radius: 4px;
656
+ font-size: 0.75rem;
657
+ font-weight: 500;
658
+ }
659
+
660
+ .editor-container {
661
+ flex: 1;
662
+ display: flex;
663
+ position: relative;
664
+ overflow: hidden;
665
+ }
666
+
667
+ .sql-editor {
668
+ flex: 1;
669
+ padding: 1rem;
670
+ padding-left: 4rem;
671
+ border: none;
672
+ outline: none;
673
+ font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
674
+ font-size: 14px;
675
+ line-height: 1.5;
676
+ resize: none;
677
+ background: #fafafa;
678
+ color: #1e293b;
679
+ tab-size: 2;
680
+ white-space: pre;
681
+ overflow-wrap: normal;
682
+ overflow-x: auto;
683
+ }
684
+
685
+ .line-numbers {
686
+ position: absolute;
687
+ left: 0;
688
+ top: 0;
689
+ width: 3rem;
690
+ padding: 1rem 0.5rem;
691
+ background: #f1f5f9;
692
+ border-right: 1px solid #e2e8f0;
693
+ font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
694
+ font-size: 14px;
695
+ line-height: 1.5;
696
+ text-align: right;
697
+ color: #64748b;
698
+ overflow: hidden;
699
+ pointer-events: none;
700
+ }
701
+
702
+ .line-number {
703
+ height: 21px;
704
+ display: flex;
705
+ justify-content: flex-end;
706
+ align-items: center;
707
+ }
708
+
709
+ .current-line {
710
+ background: rgba(102, 126, 234, 0.1);
711
+ color: #667eea;
712
+ font-weight: 600;
713
+ }
714
+
715
+ .query-results {
716
+ background: white;
717
+ border-top: 1px solid #e2e8f0;
718
+ max-height: 400px;
719
+ display: flex;
720
+ flex-direction: column;
721
+ }
722
+
723
+ .results-header {
724
+ display: flex;
725
+ justify-content: space-between;
726
+ align-items: center;
727
+ padding: 1rem 1.5rem;
728
+ background: #f8fafc;
729
+ border-bottom: 1px solid #e2e8f0;
730
+ }
731
+
732
+ .results-info {
733
+ display: flex;
734
+ align-items: center;
735
+ gap: 0.5rem;
736
+ font-weight: 600;
737
+ color: #1e293b;
738
+ }
739
+
740
+ .results-count {
741
+ color: #64748b;
742
+ font-weight: 400;
743
+ }
744
+
745
+ .results-actions {
746
+ display: flex;
747
+ gap: 0.5rem;
748
+ }
749
+
750
+ .results-actions button {
751
+ display: flex;
752
+ align-items: center;
753
+ gap: 0.25rem;
754
+ padding: 0.5rem 1rem;
755
+ border: 1px solid #d1d5db;
756
+ border-radius: 8px;
757
+ background: white;
758
+ color: #374151;
759
+ font-size: 0.875rem;
760
+ cursor: pointer;
761
+ transition: all 0.2s ease;
762
+ }
763
+
764
+ .results-actions button:hover {
765
+ background: #f3f4f6;
766
+ }
767
+
768
+ .btn-export {
769
+ background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
770
+ color: white !important;
771
+ border: none !important;
772
+ }
773
+
774
+ .results-content {
775
+ flex: 1;
776
+ overflow: hidden;
777
+ }
778
+
779
+ .error-message {
780
+ display: flex;
781
+ align-items: flex-start;
782
+ gap: 0.75rem;
783
+ padding: 1rem 1.5rem;
784
+ background: #fef2f2;
785
+ border-left: 4px solid #ef4444;
786
+ color: #991b1b;
787
+ }
788
+
789
+ .error-message i {
790
+ color: #ef4444;
791
+ font-size: 1.25rem;
792
+ margin-top: 0.125rem;
793
+ }
794
+
795
+ .error-message p {
796
+ margin: 0.5rem 0 0 0;
797
+ font-family: monospace;
798
+ background: #fee2e2;
799
+ padding: 0.5rem;
800
+ border-radius: 4px;
801
+ }
802
+
803
+ .results-table-wrapper {
804
+ height: 100%;
805
+ overflow: hidden;
806
+ display: flex;
807
+ flex-direction: column;
808
+ }
809
+
810
+ .results-table {
811
+ width: 100%;
812
+ border-collapse: collapse;
813
+ font-size: 0.875rem;
814
+ }
815
+
816
+ .results-table th {
817
+ background: #f8fafc;
818
+ padding: 0.75rem;
819
+ text-align: left;
820
+ font-weight: 600;
821
+ color: #374151;
822
+ border-bottom: 2px solid #e5e7eb;
823
+ cursor: pointer;
824
+ user-select: none;
825
+ white-space: nowrap;
826
+ }
827
+
828
+ .results-table th:hover {
829
+ background: #f1f5f9;
830
+ }
831
+
832
+ .results-table td {
833
+ padding: 0.75rem;
834
+ border-bottom: 1px solid #f3f4f6;
835
+ max-width: 200px;
836
+ overflow: hidden;
837
+ text-overflow: ellipsis;
838
+ white-space: nowrap;
839
+ }
840
+
841
+ .results-table tr:hover {
842
+ background: #fafbfc;
843
+ }
844
+
845
+ .pagination {
846
+ display: flex;
847
+ justify-content: center;
848
+ align-items: center;
849
+ gap: 0.5rem;
850
+ padding: 1rem;
851
+ background: #f8fafc;
852
+ border-top: 1px solid #e2e8f0;
853
+ }
854
+
855
+ .pagination button {
856
+ padding: 0.5rem 0.75rem;
857
+ border: 1px solid #d1d5db;
858
+ border-radius: 6px;
859
+ background: white;
860
+ cursor: pointer;
861
+ transition: all 0.2s ease;
862
+ }
863
+
864
+ .pagination button:hover:not(:disabled) {
865
+ background: #667eea;
866
+ color: white;
867
+ border-color: #667eea;
868
+ }
869
+
870
+ .pagination button:disabled {
871
+ opacity: 0.5;
872
+ cursor: not-allowed;
873
+ }
874
+
875
+ .page-info {
876
+ padding: 0.5rem 1rem;
877
+ font-size: 0.875rem;
878
+ color: #6b7280;
879
+ }
880
+
881
+ /* 模态框样式 */
882
+ .modal-overlay {
883
+ position: fixed;
884
+ top: 0;
885
+ left: 0;
886
+ right: 0;
887
+ bottom: 0;
888
+ background: rgba(0, 0, 0, 0.5);
889
+ display: flex;
890
+ justify-content: center;
891
+ align-items: center;
892
+ z-index: 1000;
893
+ }
894
+
895
+ .modal-content {
896
+ background: white;
897
+ border-radius: 12px;
898
+ width: 90%;
899
+ max-width: 500px;
900
+ box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
901
+ }
902
+
903
+ .modal-header {
904
+ display: flex;
905
+ justify-content: space-between;
906
+ align-items: center;
907
+ padding: 1.5rem;
908
+ border-bottom: 1px solid #e5e7eb;
909
+ }
910
+
911
+ .modal-header h3 {
912
+ margin: 0;
913
+ font-size: 1.25rem;
914
+ font-weight: 600;
915
+ color: #1e293b;
916
+ }
917
+
918
+ .modal-close {
919
+ background: none;
920
+ border: none;
921
+ font-size: 1.25rem;
922
+ cursor: pointer;
923
+ color: #6b7280;
924
+ padding: 0.25rem;
925
+ }
926
+
927
+ .modal-close:hover {
928
+ color: #374151;
929
+ }
930
+
931
+ .modal-body {
932
+ padding: 1.5rem;
933
+ }
934
+
935
+ .form-group {
936
+ margin-bottom: 1rem;
937
+ }
938
+
939
+ .form-group label {
940
+ display: block;
941
+ margin-bottom: 0.5rem;
942
+ font-weight: 500;
943
+ color: #374151;
944
+ }
945
+
946
+ .form-input,
947
+ .form-textarea {
948
+ width: 100%;
949
+ padding: 0.75rem;
950
+ border: 1px solid #d1d5db;
951
+ border-radius: 8px;
952
+ font-size: 0.875rem;
953
+ transition: border-color 0.2s ease;
954
+ }
955
+
956
+ .form-input:focus,
957
+ .form-textarea:focus {
958
+ outline: none;
959
+ border-color: #667eea;
960
+ box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
961
+ }
962
+
963
+ .modal-footer {
964
+ display: flex;
965
+ justify-content: flex-end;
966
+ gap: 0.5rem;
967
+ padding: 1.5rem;
968
+ border-top: 1px solid #e5e7eb;
969
+ }
970
+
971
+ .btn-cancel,
972
+ .btn-confirm {
973
+ padding: 0.75rem 1.5rem;
974
+ border-radius: 8px;
975
+ font-weight: 500;
976
+ cursor: pointer;
977
+ transition: all 0.2s ease;
978
+ }
979
+
980
+ .btn-cancel {
981
+ background: white;
982
+ border: 1px solid #d1d5db;
983
+ color: #374151;
984
+ }
985
+
986
+ .btn-cancel:hover {
987
+ background: #f3f4f6;
988
+ }
989
+
990
+ .btn-confirm {
991
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
992
+ border: none;
993
+ color: white;
994
+ }
995
+
996
+ .btn-confirm:hover:not(:disabled) {
997
+ background: linear-gradient(135deg, #5a67d8 0%, #667eea 100%);
998
+ }
999
+
1000
+ .btn-confirm:disabled {
1001
+ opacity: 0.5;
1002
+ cursor: not-allowed;
1003
+ }
1004
+
1005
+ /* 响应式设计 */
1006
+ @media (max-width: 768px) {
1007
+ .query-header {
1008
+ flex-direction: column;
1009
+ gap: 1rem;
1010
+ align-items: stretch;
1011
+ }
1012
+
1013
+ .query-controls {
1014
+ flex-wrap: wrap;
1015
+ }
1016
+
1017
+ .connection-select {
1018
+ width: 100%;
1019
+ }
1020
+
1021
+ .editor-toolbar {
1022
+ flex-direction: column;
1023
+ gap: 0.5rem;
1024
+ align-items: stretch;
1025
+ }
1026
+
1027
+ .toolbar-left {
1028
+ overflow-x: auto;
1029
+ padding-bottom: 0.5rem;
1030
+ }
1031
+
1032
+ .sql-editor {
1033
+ font-size: 12px;
1034
+ }
1035
+
1036
+ .results-header {
1037
+ flex-direction: column;
1038
+ gap: 1rem;
1039
+ align-items: stretch;
1040
+ }
1041
+
1042
+ .results-table-wrapper {
1043
+ overflow-x: auto;
1044
+ }
1045
+ }
1046
+ </style>