-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
549 lines (456 loc) · 16.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SQL Query Optimization Interface</title>
<script src="./js/sql-formatter.min.js"></script>
<script src="./js/highlight.min.js"></script>
<script src="./js/sql.min.js"></script>
<script src="./js/tailwind.min.js"></script>
<script src="./js/fontawesome-free-6.6.0-web/js/all.min.js"></script>
<link rel="stylesheet" href="./css/highlightjs1180stylesdefault-min.css">
<link rel="stylesheet" href="./js/fontawesome-free-6.6.0-web/css/all.min.css">
<script src="./js/api/sql-api.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.23.0/themes/prism.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.23.0/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.23.0/components/prism-sql.min.js"></script>
<!-- 引入 marked.js -->
<!-- <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/14.1.2/marked.min.js" integrity="sha512-bXyBT2/sYjZg1D7ykDS6eJSE4DFDVPJHvbRAfdfYKr6IusrCz7wAmSm36vz9G8zMob25Rvqu90vft3JI71ygcQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<!-- <script src="https://cdn.tailwindcss.com"></script> -->
<!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> -->
<!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/default.min.css"> -->
<!-- 引入 sql-formatter 库 -->
<!-- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/sql-formatter.min.js"></script> -->
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/languages/sql.min.js"></script> -->
</head>
<body class="h-screen bg-gray-100 flex text-sm ">
<!-- Sidebar -->
<div id="sidebar" class="bg-white shadow-lg transition-all duration-300 w-0 overflow-hidden">
<div class="p-2">
<h2 class="text-base font-semibold mb-2">Connections</h2>
<ul class="text-xs">
<li class="mb-1">
<div class="flex items-center">
<i class="fas fa-database w-3 h-3 mr-1"></i>
<span>Database 1</span>
</div>
</li>
<li class="mb-1">
<div class="flex items-center ml-3">
<i class="fas fa-table w-3 h-3 mr-1"></i>
<span>Table 1</span>
</div>
</li>
<li class="mb-1">
<div class="flex items-center ml-3">
<i class="fas fa-table w-3 h-3 mr-1"></i>
<span>Table 2</span>
</div>
</li>
</ul>
</div>
</div>
<!-- Main content -->
<div class="flex-1 flex flex-col">
<!-- Top bar -->
<div class="bg-white shadow-sm p-2 flex items-center justify-between">
<div class="flex items-center">
<!-- <button id="toggleSidebar" class="mr-2">
<i class="fas fa-chevron-right w-4 h-4"></i>
</button> -->
<h1 class="text-lg font-bold">SQL 助手</h1>
</div>
<div class="flex items-center space-x-2">
<!-- <button id="loginButton" class="bg-gray-500 text-white px-2 py-1 rounded text-xs hover:bg-gray-600 flex items-center">
<i class="fas fa-user w-3 h-3 mr-1"></i>
<span>Login</span>
</button> -->
</div>
</div>
<!-- Content area with editor and results -->
<div class="flex-1 flex flex-col">
<!-- Query editor (占 5/3 高度) -->
<div class="flex-[1_3] p-2">
<textarea id="queryEditor" class="w-full h-full p-2 border border-gray-300 rounded resize-none focus:outline-none focus:ring-1 focus:ring-blue-500 text-sm" placeholder="Enter your SQL query here..."></textarea>
</div>
<!-- Query results (占 5/2 高度) -->
<div class="flex-[2_3] p-2 flex flex-col">
<div class="flex justify-between items-center mb-2">
<h2 class="text-base font-semibold">Query Results</h2>
<div class="flex items-center space-x-2">
<button id="executeButton" class="hidden bg-blue-500 text-white px-2 py-1 rounded text-xs hover:bg-blue-600 flex items-center">
<i class="fas fa-play w-3 h-3 mr-1"></i> Execute
</button>
<button id="clearButton" class="bg-red-500 text-white px-2 py-1 rounded text-xs hover:bg-red-600 flex items-center">
<i class="fas fa-trash w-3 h-3 mr-1"></i> Clear
</button>
<button id="formatButton" class="bg-yellow-500 text-white px-2 py-1 rounded text-xs hover:bg-yellow-600 flex items-center">
<i class="fas fa-align-justify w-3 h-3 mr-1"></i> Format
</button>
<button id="optimizeButton" style="margin-right: 30px;" class="bg-green-500 text-white px-2 py-1 rounded text-xs hover:bg-green-600 flex items-center">
<i id="magicIcon" class="fa-solid fa-wand-magic-sparkles w-3 h-3 mr-1"></i>
<i id="magicLoadingIcon" class="hidden fas fa-spinner fa-spin w-3 h-3 mr-1"></i> 芝麻
</button>
<!-- <button id="toggleView" class="text-blue-500 hover:text-blue-600 pl-8">
<i class="fas fa-list w-4 h-4"></i>
</button> -->
</div>
</div>
<div class="relative flex-1 p-4 bg-gray-50 border border-gray-300 rounded text-xs overflow-auto">
<!-- 复制按钮 -->
<button id="copyButton" class="absolute top-2 right-2 bg-gray-200 bg-opacity-50 hover:bg-opacity-75 text-gray-700 px-2 py-1 rounded text-xs flex items-center">
<i id="copyIcon-copy" class="fas fa-copy mr-1"></i>
<i id="copyIcon-check" style="display: none;" class="fas fa-check mr-1"></i>
</button>
<!-- Tooltip 显示在按钮左侧 -->
<div id="copyTooltip" class="hidden absolute top-2 right-10 bg-gray-400 text-white px-2 py-1 rounded text-xs">
Copied!
</div>
<!-- 格式化后的SQL内容 -->
<pre id="formattedQueryContent" data-prismjs-copy-timeout="500" class="h-64 overflow-y-auto">Your formatted query will appear here...</pre>
</div>
</div>
</div>
<!-- Footer -->
<footer class="bg-gray-600 text-white text-xs p-1 text-center">
<div class="mt-1">
© 2024 SQL Helper - All rights reserved.
<a href="#" class="text-blue-400 hover:underline">Privacy Policy</a> |
<a href="#" class="text-blue-400 hover:underline">Terms of Service</a> |
<a href="#" class="text-blue-400 hover:underline">Contact Us</a>
</div>
</footer>
</div>
<script>
// DOM elements
const sidebar = document.getElementById('sidebar');
const toggleSidebarBtn = document.getElementById('toggleSidebar');
const loginButton = document.getElementById('loginButton');
const toggleViewBtn = document.getElementById('toggleView');
const copyResultsBtn = document.getElementById('copyResults');
const formatButton = document.getElementById('formatButton');
const queryEditor = document.getElementById('queryEditor');
const formattedQuery = document.getElementById('formattedQueryContent');
// Toggle sidebar
// let sidebarOpen = false;
// toggleSidebarBtn.addEventListener('click', () => {
// sidebarOpen = !sidebarOpen;
// sidebar.style.width = sidebarOpen ? '12rem' : '0';
// toggleSidebarBtn.innerHTML = sidebarOpen
// ? '<i class="fas fa-chevron-left w-4 h-4"></i>'
// : '<i class="fas fa-chevron-right w-4 h-4"></i>';
// });
// Toggle login/logout
// let isLoggedIn = false;
// loginButton.addEventListener('click', () => {
// isLoggedIn = !isLoggedIn;
// loginButton.innerHTML = isLoggedIn
// ? '<i class="fas fa-user w-3 h-3 mr-1"></i><span>Logout</span>'
// : '<i class="fas fa-user w-3 h-3 mr-1"></i><span>Login</span>';
// });
// Format SQL query and display with syntax highlighting
formatButton.addEventListener('click', () => {
const query = queryEditor.value;
if (query) {
// 格式化 SQL 语句
const formatted = window.sqlFormatter.format(query);
// 使用 highlight.js 进行语法高亮
formattedQuery.innerHTML = `<pre><code class="sql">${formatted}</code></pre>`;
// // 触发 highlight.js 高亮
// document.querySelectorAll('pre code').forEach((block) => {
// hljs.highlightElement(block);
// });
Prism.highlightAll();
} else {
alert('Please enter a SQL query to format.');
}
});
// 复制功能
document.getElementById("copyButton").addEventListener("click", function() {
// 获取 formattedQuery 的内容
const formattedQuery = document.getElementById("formattedQueryContent").innerText;
// 创建临时textarea来复制内容
const tempTextarea = document.createElement("textarea");
tempTextarea.value = formattedQuery;
document.body.appendChild(tempTextarea);
tempTextarea.select();
document.execCommand("copy");
document.body.removeChild(tempTextarea);
// 更改按钮图标为打勾
const copyIconCopy = document.getElementById("copyIcon-copy");
const copyIconCheck = document.getElementById("copyIcon-check");
copyIconCopy.style.display = 'none';
copyIconCheck.style.display = 'block';
// 显示复制成功的 tooltip
const copyTooltip = document.getElementById("copyTooltip");
copyTooltip.classList.remove("hidden");
// 一两秒后恢复原始图标和隐藏 tooltip
setTimeout(() => {
// copyIcon.classList.remove("fa-check");
// copyIcon.classList.add("fa-copy");
copyIconCopy.style.display = 'block';
copyIconCheck.style.display = 'none';
copyTooltip.classList.add("hidden");
}, 1000); // 1500ms 等于 1.5 秒
});
document.getElementById("optimizeButton").addEventListener("click",async function(){
const query = queryEditor.value;
if (query) {
// 格式化 SQL 语句
document.getElementById("magicIcon").classList.add("hidden");
document.getElementById("magicLoadingIcon").classList.remove("hidden");
var htmlContent =await fetchSQLQuery(query);
// 如果解析后仍然有多余的换行符,可以手动移除
const cleanedContent = htmlContent.replace(/>\s+</g, '><');
// 将 HTML 插入到页面中
document.getElementById('formattedQueryContent').innerHTML = cleanedContent;
// 重新高亮代码块
Prism.highlightAll();
document.getElementById("magicIcon").classList.remove("hidden");
document.getElementById("magicLoadingIcon").classList.add("hidden");
// // 使用 highlight.js 进行语法高亮
// formattedQuery.innerHTML = `<pre><code class="sql">${formatted}</code></pre>`;
// // 触发 highlight.js 高亮
// document.querySelectorAll('pre code').forEach((block) => {
// hljs.highlightElement(block);
// });
} else {
alert('Please enter a content.');
}
var message = document.getElementById("")
})
</script>
<style>
pre[class*="language-"],
code[class*="language-"] {
color: #d4d4d4;
font-size: 13px;
text-shadow: none;
font-family: Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace;
direction: ltr;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
line-height: 1.5;
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}
pre[class*="language-"]::selection,
code[class*="language-"]::selection,
pre[class*="language-"] *::selection,
code[class*="language-"] *::selection {
text-shadow: none;
background: #264F78;
}
@media print {
pre[class*="language-"],
code[class*="language-"] {
text-shadow: none;
}
}
pre[class*="language-"] {
padding: 1em;
margin: .5em 0;
overflow: auto;
background: #1e1e1e;
}
:not(pre) > code[class*="language-"] {
padding: .1em .3em;
border-radius: .3em;
color: #db4c69;
background: #1e1e1e;
}
/*********************************************************
* Tokens
*/
.namespace {
opacity: .7;
}
.token.doctype .token.doctype-tag {
color: #569CD6;
}
.token.doctype .token.name {
color: #9cdcfe;
}
.token.comment,
.token.prolog {
color: #6a9955;
}
.token.punctuation,
.language-html .language-css .token.punctuation,
.language-html .language-javascript .token.punctuation {
color: #d4d4d4;
}
.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.inserted,
.token.unit {
color: #b5cea8;
}
.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.deleted {
color: #ce9178;
}
.language-css .token.string.url {
text-decoration: underline;
}
.token.operator,
.token.entity {
color: #d4d4d4;
}
.token.operator.arrow {
color: #569CD6;
}
.token.atrule {
color: #ce9178;
}
.token.atrule .token.rule {
color: #c586c0;
}
.token.atrule .token.url {
color: #9cdcfe;
}
.token.atrule .token.url .token.function {
color: #dcdcaa;
}
.token.atrule .token.url .token.punctuation {
color: #d4d4d4;
}
.token.keyword {
color: #569CD6;
}
.token.keyword.module,
.token.keyword.control-flow {
color: #c586c0;
}
.token.function,
.token.function .token.maybe-class-name {
color: #dcdcaa;
}
.token.regex {
color: #d16969;
}
.token.important {
color: #569cd6;
}
.token.italic {
font-style: italic;
}
.token.constant {
color: #9cdcfe;
}
.token.class-name,
.token.maybe-class-name {
color: #4ec9b0;
}
.token.console {
color: #9cdcfe;
}
.token.parameter {
color: #9cdcfe;
}
.token.interpolation {
color: #9cdcfe;
}
.token.punctuation.interpolation-punctuation {
color: #569cd6;
}
.token.boolean {
color: #569cd6;
}
.token.property,
.token.variable,
.token.imports .token.maybe-class-name,
.token.exports .token.maybe-class-name {
color: #9cdcfe;
}
.token.selector {
color: #d7ba7d;
}
.token.escape {
color: #d7ba7d;
}
.token.tag {
color: #569cd6;
}
.token.tag .token.punctuation {
color: #808080;
}
.token.cdata {
color: #808080;
}
.token.attr-name {
color: #9cdcfe;
}
.token.attr-value,
.token.attr-value .token.punctuation {
color: #ce9178;
}
.token.attr-value .token.punctuation.attr-equals {
color: #d4d4d4;
}
.token.entity {
color: #569cd6;
}
.token.namespace {
color: #4ec9b0;
}
/*********************************************************
* Language Specific
*/
pre[class*="language-javascript"],
code[class*="language-javascript"],
pre[class*="language-jsx"],
code[class*="language-jsx"],
pre[class*="language-typescript"],
code[class*="language-typescript"],
pre[class*="language-tsx"],
code[class*="language-tsx"] {
color: #9cdcfe;
}
pre[class*="language-css"],
code[class*="language-css"] {
color: #ce9178;
}
pre[class*="language-html"],
code[class*="language-html"] {
color: #d4d4d4;
}
.language-regex .token.anchor {
color: #dcdcaa;
}
.language-html .token.punctuation {
color: #808080;
}
/*********************************************************
* Line highlighting
*/
pre[class*="language-"] > code[class*="language-"] {
position: relative;
z-index: 1;
}
.line-highlight.line-highlight {
background: #f7ebc6;
box-shadow: inset 5px 0 0 #f7d87c;
z-index: 0;
}
</style>
</body>
</html>