-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathadmin.html
More file actions
467 lines (405 loc) · 18.7 KB
/
Copy pathadmin.html
File metadata and controls
467 lines (405 loc) · 18.7 KB
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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Phonics Workshop | 管理后台</title>
<link rel="stylesheet" href="css/style.css">
<style>
:root {
--panel-bg: #fdfdfd;
}
body {
background: #f0f2f5;
padding: 40px 0;
}
.admin-grid {
display: grid;
grid-template-columns: 350px 1fr;
gap: 30px;
}
.side-panel {
background: white;
border-radius: 20px;
padding: 25px;
border: 1px solid var(--border-soft);
position: sticky;
top: 100px;
height: fit-content;
}
.main-log {
background: #1e1e1e;
color: #d4d4d4;
padding: 20px;
border-radius: 20px;
font-family: 'Consolas', 'Monaco', monospace;
height: 600px;
overflow-y: auto;
font-size: 0.85rem;
line-height: 1.6;
}
.step-item {
padding: 12px;
border-bottom: 1px solid var(--border-soft);
display: flex;
align-items: center;
justify-content: space-between;
}
.status-pill {
padding: 4px 10px;
border-radius: 6px;
font-size: 0.75rem;
font-weight: 700;
text-transform: uppercase;
}
.status-ready {
background: #e0f2fe;
color: #0369a1;
}
.log-line {
padding: 2px 0;
word-break: break-word;
}
.log-info {
color: #58a6ff;
}
.log-success {
color: #7ee787;
}
.log-warn {
color: #d29922;
}
.log-error {
color: #f85149;
}
.log-stdout {
color: #d4d4d4;
}
.log-stderr {
color: #ffa657;
}
.log-connected {
color: #a371f7;
}
.log-time {
color: #6e7681;
margin-right: 8px;
}
.connection-status {
display: inline-flex;
align-items: center;
gap: 6px;
font-size: 0.75rem;
padding: 4px 10px;
border-radius: 20px;
}
.connection-status.connected {
background: #dcfce7;
color: #166534;
}
.connection-status.disconnected {
background: #fee2e2;
color: #dc2626;
}
.connection-dot {
width: 8px;
height: 8px;
border-radius: 50%;
animation: pulse 2s infinite;
}
.connected .connection-dot {
background: #22c55e;
}
.disconnected .connection-dot {
background: #ef4444;
animation: none;
}
@keyframes pulse {
0%,
100% {
opacity: 1;
}
50% {
opacity: 0.5;
}
}
</style>
</head>
<body>
<div class="container">
<div style="margin-bottom: 40px; border-bottom: 2px solid var(--accent); padding-bottom: 20px;">
<h1 style="font-size: 2.5rem; margin-bottom: 10px;">工作台 <span
style="font-weight: 300; opacity: 0.5;">控制台</span></h1>
<p style="color: var(--text-muted);">AI 驱动的词汇生成与资源管理中心</p>
</div>
<div class="admin-grid">
<!-- Control Panel -->
<div class="side-panel">
<div style="margin-bottom: 30px;">
<label
style="display: block; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; color: var(--accent); margin-bottom: 10px;">AI
配置(兼容 OpenAI 格式)</label>
<div style="margin-bottom: 12px;">
<label
style="font-size: 0.7rem; color: var(--text-muted); display: block; margin-bottom: 4px;">API
地址</label>
<input type="text" id="api-base" placeholder="https://api.openai.com/v1"
style="width: 100%; padding: 10px; border: 1px solid var(--border-soft); border-radius: 8px; font-size: 0.85rem;">
</div>
<div style="margin-bottom: 12px;">
<label
style="font-size: 0.7rem; color: var(--text-muted); display: block; margin-bottom: 4px;">API
Key</label>
<input type="password" id="api-key" placeholder="sk-xxx 或 留空使用本地 ADC"
style="width: 100%; padding: 10px; border: 1px solid var(--border-soft); border-radius: 8px; font-size: 0.85rem;">
</div>
<div style="margin-bottom: 12px;">
<label
style="font-size: 0.7rem; color: var(--text-muted); display: block; margin-bottom: 4px;">模型名称</label>
<input type="text" id="api-model"
placeholder="gemini-3-flash-preview / gpt-4o / claude-3.5-sonnet"
value="gemini-3-flash-preview"
style="width: 100%; padding: 10px; border: 1px solid var(--border-soft); border-radius: 8px; font-size: 0.85rem;">
</div>
<div
style="background: var(--bg-main); padding: 10px; border-radius: 8px; font-size: 0.7rem; color: var(--text-muted);">
<strong>常用配置:</strong><br>
• Gemini: 留空地址,填 API Key<br>
• OpenAI: api.openai.com/v1<br>
• Claude: api.anthropic.com<br>
• DeepSeek: api.deepseek.com
</div>
<details style="margin-top: 15px;">
<summary
style="cursor: pointer; font-size: 0.75rem; font-weight: 700; color: var(--accent); padding: 8px 0;">
▸ 自定义提示词 (可选)
</summary>
<div style="margin-top: 10px;">
<textarea id="custom-prompt" rows="4" placeholder="例如:生成更简单的单词 / 优先选择动物类词汇 / 避免复杂拼写"
style="width: 100%; padding: 10px; border: 1px solid var(--border-soft); border-radius: 8px; font-size: 0.85rem; resize: vertical; font-family: inherit;"></textarea>
<div style="display: flex; justify-content: space-between; margin-top: 8px;">
<button type="button" onclick="clearCustomPrompt()"
style="background: none; border: none; font-size: 0.75rem; color: var(--text-muted); cursor: pointer;">清空</button>
<span style="font-size: 0.7rem; color: var(--text-muted);">将追加到系统提示词</span>
</div>
</div>
</details>
</div>
<div style="margin-bottom: 30px;">
<label
style="display: block; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; color: var(--accent); margin-bottom: 15px;">任务执行</label>
<button class="btn btn-primary" style="width: 100%; margin-bottom: 12px; justify-content: center;"
onclick="runTask('generate')">1. 生成词汇(AI + 验证)</button>
<button class="btn"
style="width: 100%; margin-bottom: 12px; justify-content: center; border: 1px solid var(--border-soft);"
onclick="runTask('merge')">2. 合并到规则库</button>
<button class="btn"
style="width: 100%; margin-bottom: 12px; justify-content: center; border: 1px solid var(--border-soft);"
onclick="runTask('tts')">3. 生成语音</button>
<button class="btn"
style="width: 100%; margin-bottom: 12px; justify-content: center; border: 1px solid var(--border-soft);"
onclick="runTask('fix')">修复 Breakdown</button>
<div style="display: flex; gap: 8px; margin-bottom: 12px;">
<button class="btn" id="btn-pause"
style="flex: 1; justify-content: center; border: 1px solid #fde68a; color: #d97706; background: #fffbeb;"
onclick="pauseTask('generate')">暂停生成</button>
<button class="btn"
style="flex: 1; justify-content: center; border: 1px solid #fecaca; color: #dc2626; background: #fef2f2;"
onclick="stopTask('generate')">强制停止</button>
</div>
<button class="btn"
style="width: 100%; justify-content: center; border: 1px solid #fecaca; color: #dc2626;"
onclick="runTask('clean')">清空已生成</button>
</div>
<div id="stats-panel">
<label
style="display: block; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; margin-bottom: 15px;">当前状态</label>
<div id="rules-list">
<!-- Rules will be loaded here -->
<div class="step-item"><span>加载中...</span></div>
</div>
</div>
</div>
<!-- Execution Log -->
<div>
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px;">
<div style="display: flex; align-items: center; gap: 12px;">
<h3 style="font-size: 1.1rem; margin: 0;">执行日志</h3>
<span id="connection-status" class="connection-status disconnected">
<span class="connection-dot"></span>
<span class="connection-text">未连接</span>
</span>
</div>
<button onclick="clearLog()"
style="background: none; border: none; font-size: 0.8rem; color: var(--accent); cursor: pointer;">清空</button>
</div>
<div class="main-log" id="log-output"></div>
</div>
</div>
</div>
<script>
let eventSource = null;
function log(msg, type = 'info') {
const output = document.getElementById('log-output');
const time = new Date().toLocaleTimeString();
const escapedMsg = msg.replace(/</g, '<').replace(/>/g, '>');
output.innerHTML += `<div class="log-line log-${type}"><span class="log-time">[${time}]</span>${escapedMsg}</div>`;
output.scrollTop = output.scrollHeight;
}
function clearLog() {
document.getElementById('log-output').innerHTML = '';
log('日志已清空', 'info');
}
function updateConnectionStatus(connected) {
const el = document.getElementById('connection-status');
el.className = `connection-status ${connected ? 'connected' : 'disconnected'}`;
el.querySelector('.connection-text').textContent = connected ? '已连接' : '未连接';
}
function connectSSE() {
if (eventSource) {
eventSource.close();
}
eventSource = new EventSource('/api/logs/stream');
eventSource.onopen = () => {
updateConnectionStatus(true);
};
eventSource.onmessage = (event) => {
try {
const data = JSON.parse(event.data);
if (data.type === 'connected') {
log('已连接到服务器日志流', 'connected');
return;
}
// 显示日志
const prefix = data.task ? `[${data.task}] ` : '';
log(prefix + data.message, data.type);
// 任务完成时刷新统计
if (data.type === 'success' || data.type === 'error') {
setTimeout(loadStats, 500);
}
} catch (e) {
console.warn('SSE parse error:', e);
}
};
eventSource.onerror = () => {
updateConnectionStatus(false);
// 3秒后重连
setTimeout(connectSSE, 3000);
};
}
async function loadStats() {
try {
const res = await fetch('/api/stats');
const data = await res.json();
if (data.success) {
const s = data.stats;
document.getElementById('rules-list').innerHTML = `
<div class="step-item"><span>分类数</span><span class="status-pill status-ready">${s.categories}</span></div>
<div class="step-item"><span>规则数</span><span class="status-pill status-ready">${s.rules}</span></div>
<div class="step-item"><span>已生成</span><span class="status-pill" style="background:#dcfce7;color:#166534;">${s.generatedRules}</span></div>
<div class="step-item"><span>单词音频</span><span class="status-pill" style="background:#fef3c7;color:#92400e;">${s.wordAudios}</span></div>
<div class="step-item"><span>例句音频</span><span class="status-pill" style="background:#fef3c7;color:#92400e;">${s.sentenceAudios}</span></div>
`;
}
} catch (e) {
document.getElementById('rules-list').innerHTML = '<div class="step-item"><span>服务器未运行</span></div>';
}
}
async function runTask(taskName) {
const baseURL = document.getElementById('api-base').value.trim();
const apiKey = document.getElementById('api-key').value.trim();
const model = document.getElementById('api-model').value.trim() || 'gemini-3-flash';
const customPrompt = document.getElementById('custom-prompt').value.trim();
// 保存配置到本地存储
localStorage.setItem('phonics-api-base', baseURL);
localStorage.setItem('phonics-api-model', model);
localStorage.setItem('phonics-custom-prompt', customPrompt);
const taskNames = {
'generate': '生成词汇',
'merge': '合并规则',
'tts': '生成语音',
'fix': '修复Breakdown',
'clean': '清空'
};
log(`开始执行:${taskNames[taskName] || taskName}...`, 'info');
if (customPrompt) {
log(`自定义提示词: ${customPrompt.substring(0, 50)}${customPrompt.length > 50 ? '...' : ''}`, 'info');
}
try {
const res = await fetch('/api/run', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
task: taskName,
apiKey: apiKey,
baseURL: baseURL,
model: model,
customPrompt: customPrompt
})
});
const data = await res.json();
if (!data.success) {
log(data.message, 'warn');
}
} catch (e) {
log('服务器连接失败,请运行:npm run studio', 'error');
}
}
function clearCustomPrompt() {
document.getElementById('custom-prompt').value = '';
localStorage.removeItem('phonics-custom-prompt');
log('已清空自定义提示词', 'info');
}
async function pauseTask(taskName) {
log(`请求暂停任务: ${taskName}...`, 'warn');
try {
const res = await fetch('/api/pause', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ task: taskName })
});
const data = await res.json();
log(data.message, data.success ? 'warn' : 'error');
} catch (e) {
log('暂停请求失败', 'error');
}
}
async function stopTask(taskName) {
if (!confirm('强制停止将丢失当前正在处理的规则数据,确定要停止吗?')) {
return;
}
log(`强制停止任务: ${taskName}...`, 'error');
try {
const res = await fetch('/api/stop', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ task: taskName })
});
const data = await res.json();
log(data.message, data.success ? 'warn' : 'error');
setTimeout(loadStats, 500);
} catch (e) {
log('停止请求失败', 'error');
}
}
// 页面加载时初始化
window.onload = () => {
// 恢复保存的配置
const savedBase = localStorage.getItem('phonics-api-base');
const savedModel = localStorage.getItem('phonics-api-model');
const savedPrompt = localStorage.getItem('phonics-custom-prompt');
if (savedBase) document.getElementById('api-base').value = savedBase;
if (savedModel) document.getElementById('api-model').value = savedModel;
if (savedPrompt) document.getElementById('custom-prompt').value = savedPrompt;
loadStats();
connectSSE();
log('工作台已初始化,等待任务执行...', 'info');
log('断点续传: 已启用 - 再次运行生成任务会自动跳过已完成的规则', 'info');
};
// 页面关闭时断开连接
window.onbeforeunload = () => {
if (eventSource) eventSource.close();
};
</script>
</body>
</html>