-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathadmin.html
More file actions
1080 lines (1013 loc) · 32.7 KB
/
Copy pathadmin.html
File metadata and controls
1080 lines (1013 loc) · 32.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
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
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Seedance 任务管理</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: #0a0e27;
color: #e0e0e0;
min-height: 100vh;
}
.header {
background: linear-gradient(135deg, #1a1a3e 0%, #16213e 100%);
padding: 20px 30px;
border-bottom: 1px solid #1e3a5f;
display: flex;
align-items: center;
justify-content: space-between;
}
.header h1 {
font-size: 20px;
color: #a8d8ea;
}
.header .badge {
background: #0f3460;
color: #a8d8ea;
padding: 4px 12px;
border-radius: 12px;
font-size: 12px;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
.panel {
background: #16213e;
border: 1px solid #1e3a5f;
border-radius: 12px;
padding: 20px;
}
.panel-title {
font-size: 16px;
color: #a8d8ea;
margin-bottom: 15px;
display: flex;
align-items: center;
gap: 8px;
}
.panel-full { grid-column: 1 / -1; }
/* Form */
label {
display: block;
font-size: 12px;
color: #8b8fa3;
margin-bottom: 4px;
margin-top: 12px;
}
label:first-child { margin-top: 0; }
input[type="text"], textarea, select {
width: 100%;
padding: 8px 12px;
background: #0d1b36;
border: 1px solid #1e3a5f;
border-radius: 6px;
color: #e0e0e0;
font-size: 13px;
font-family: inherit;
}
textarea { resize: vertical; min-height: 60px; }
input:focus, textarea:focus, select:focus {
outline: none;
border-color: #3a7bd5;
}
select { cursor: pointer; }
/* Checkbox */
.checkbox-row {
display: flex;
align-items: center;
gap: 8px;
margin-top: 12px;
padding: 10px 12px;
background: #0d1b36;
border: 1px solid #1e3a5f;
border-radius: 6px;
}
.checkbox-row.warn {
border-color: #e94560;
background: rgba(233, 69, 96, 0.1);
}
.checkbox-row input[type="checkbox"] {
width: 16px; height: 16px; cursor: pointer;
}
.checkbox-row .cb-label {
font-size: 13px;
cursor: pointer;
flex: 1;
}
.checkbox-row .cb-hint {
font-size: 10px;
color: #e94560;
}
/* Quick insert row */
.quick-insert-row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 6px;
margin-top: 6px;
}
.qi-label {
font-size: 11px;
color: #8b8fa3;
white-space: nowrap;
}
.qi-hint {
font-size: 10px;
color: #555;
font-style: italic;
}
.qi-btn {
padding: 3px 10px;
font-size: 11px;
border: 1px solid #1e3a5f;
border-radius: 4px;
background: #0d1b36;
color: #a8d8ea;
cursor: pointer;
transition: all 0.15s;
white-space: nowrap;
}
.qi-btn:hover { border-color: #3a7bd5; color: #3a7bd5; background: rgba(58,123,213,0.08); }
.qi-btn:active { transform: scale(0.95); }
.qi-btn-custom { background: #16213e; }
.qi-custom {
width: 100px;
padding: 3px 8px;
font-size: 11px;
background: #0d1b36;
border: 1px solid #1e3a5f;
border-radius: 4px;
color: #e0e0e0;
}
.qi-custom:focus { border-color: #3a7bd5; outline: none; }
/* Upload area */
.upload-area {
border: 2px dashed #1e3a5f;
border-radius: 8px;
padding: 20px;
text-align: center;
cursor: pointer;
transition: all 0.2s;
margin-top: 12px;
}
.upload-area:hover { border-color: #3a7bd5; background: rgba(58, 123, 213, 0.05); }
.upload-area .icon { font-size: 28px; margin-bottom: 6px; }
.upload-area .text { font-size: 13px; color: #8b8fa3; }
.upload-file-input { display: none; }
.file-preview {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 10px;
}
.file-thumb {
position: relative;
width: 64px; height: 64px;
border-radius: 6px;
overflow: hidden;
border: 1px solid #1e3a5f;
}
.file-thumb img {
width: 100%; height: 100%;
object-fit: cover;
}
.file-thumb .remove {
position: absolute;
top: 2px; right: 2px;
width: 16px; height: 16px;
background: rgba(233, 69, 96, 0.8);
color: #fff;
border: none;
border-radius: 50%;
font-size: 10px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
}
/* Buttons */
.btn-row {
display: flex;
gap: 10px;
margin-top: 16px;
}
.btn {
padding: 10px 20px;
border: none;
border-radius: 8px;
font-size: 14px;
cursor: pointer;
transition: all 0.2s;
font-weight: 500;
}
.btn-primary {
background: linear-gradient(135deg, #3a7bd5, #6c5ce7);
color: #fff;
flex: 1;
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-secondary {
background: #1e3a5f;
color: #a8d8ea;
}
.btn-secondary:hover { background: #2a4a6f; }
.btn-danger {
background: #e94560;
color: #fff;
}
.btn-danger:hover { background: #d63851; }
.btn-sm {
padding: 5px 12px;
font-size: 12px;
border-radius: 4px;
border: 1px solid #1e3a5f;
background: #16213e;
color: #a8d8ea;
cursor: pointer;
}
.btn-sm:hover { background: #1e3a5f; }
.btn-sm.active { border-color: #3a7bd5; color: #3a7bd5; }
/* Preset cards */
.preset-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
gap: 10px;
margin-top: 10px;
}
.preset-card {
background: #0d1b36;
border: 1px solid #1e3a5f;
border-radius: 8px;
padding: 12px;
cursor: pointer;
transition: all 0.2s;
}
.preset-card:hover { border-color: #3a7bd5; transform: translateY(-1px); }
.preset-card .preset-name {
font-size: 13px;
font-weight: 600;
color: #a8d8ea;
margin-bottom: 6px;
}
.preset-card .preset-desc {
font-size: 11px;
color: #8b8fa3;
margin-bottom: 6px;
line-height: 1.4;
}
.preset-card .preset-tags {
display: flex;
flex-wrap: wrap;
gap: 4px;
}
.preset-card .tag {
font-size: 9px;
padding: 2px 6px;
background: #16213e;
border-radius: 3px;
color: #8b8fa3;
}
/* Task list */
.task-table {
width: 100%;
border-collapse: collapse;
font-size: 12px;
margin-top: 10px;
}
.task-table th {
text-align: left;
padding: 8px;
border-bottom: 1px solid #1e3a5f;
color: #8b8fa3;
font-weight: 500;
}
.task-table td {
padding: 8px;
border-bottom: 1px solid #0d1b36;
color: #cbd5e1;
}
.task-table tr:hover td { background: rgba(58, 123, 213, 0.05); }
.status-badge {
font-size: 10px;
padding: 2px 8px;
border-radius: 10px;
font-weight: 500;
}
.status-pending { background: #1e3a5f; color: #a8d8ea; }
.status-occupied { background: #7c3aed20; color: #a78bfa; }
.status-acked { background: #065f4620; color: #34d399; }
.status-running, .status-configuring { background: #92400e20; color: #fbbf24; }
.status-generating { background: #f0ad4e20; color: #f0ad4e; }
.status-uploading, .status-uploading_hd { background: #9b59b620; color: #9b59b6; }
.status-upscaling { background: #e67e2220; color: #e67e22; }
.status-completed { background: #064e3b20; color: #6ee7b7; }
.status-failed { background: #7f1d1d20; color: #fca5a5; }
/* Log */
.log-area {
background: #0d1b36;
border: 1px solid #1e3a5f;
border-radius: 6px;
padding: 10px;
font-family: 'Consolas', monospace;
font-size: 11px;
max-height: 200px;
overflow-y: auto;
margin-top: 10px;
line-height: 1.6;
color: #8b8fa3;
}
.log-area .log-success { color: #6ee7b7; }
.log-area .log-error { color: #fca5a5; }
/* SSE status */
.sse-status {
display: flex;
align-items: center;
gap: 8px;
font-size: 12px;
}
.sse-dot {
width: 8px; height: 8px;
border-radius: 50%;
background: #555;
}
.sse-dot.on { background: #4caf50; animation: pulse 2s infinite; }
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
/* Model config row */
.config-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
/* ===== 移动端适配 ===== */
@media (max-width: 768px) {
.header {
padding: 12px 16px;
flex-wrap: wrap;
gap: 8px;
}
.header h1 { font-size: 16px; }
.sse-status { font-size: 11px; }
.container {
padding: 12px;
grid-template-columns: 1fr;
gap: 14px;
}
.panel { padding: 14px; border-radius: 10px; }
.panel-full { grid-column: 1; }
.config-row {
grid-template-columns: 1fr;
gap: 8px;
}
.preset-grid {
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.preset-card { padding: 10px; }
.preset-card .preset-desc { font-size: 10px; -webkit-line-clamp: 2; display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
.upload-area { padding: 14px; }
.upload-area .icon { font-size: 22px; }
.btn { padding: 10px 14px; font-size: 13px; }
.btn-row { flex-direction: column; }
/* 任务表格改为卡片布局 */
.task-table thead { display: none; }
.task-table, .task-table tbody, .task-table tr, .task-table td {
display: block;
width: 100%;
}
.task-table tr {
background: #0d1b36;
border: 1px solid #1e3a5f;
border-radius: 8px;
padding: 10px;
margin-bottom: 8px;
}
.task-table td {
display: flex;
justify-content: space-between;
align-items: center;
padding: 4px 0;
border-bottom: none;
font-size: 12px;
}
.task-table td::before {
content: attr(data-label);
font-size: 11px;
color: #8b8fa3;
font-weight: 500;
margin-right: 8px;
white-space: nowrap;
}
}
@media (max-width: 420px) {
.header h1 { font-size: 14px; }
.container { padding: 8px; gap: 10px; }
.panel { padding: 10px; }
.preset-grid { grid-template-columns: 1fr; }
.file-thumb { width: 52px; height: 52px; }
}
</style>
</head>
<body>
<div class="header">
<h1>📋 Seedance 任务管理 (Mock Server)</h1>
<div class="sse-status">
<span class="sse-dot" id="sseDot"></span>
<span id="sseStatusText">SSE: 0 客户端</span>
<span class="badge" id="taskCountBadge">0 任务</span>
<a href="/files" style="color:#a8d8ea;text-decoration:none;font-size:12px;margin-left:8px;padding:4px 10px;background:#0d7377;border-radius:8px;">📁 文件预览</a>
</div>
</div>
<div class="container">
<!-- 左栏: 创建任务 -->
<div class="panel">
<div class="panel-title">📤 推送新任务</div>
<label>描述</label>
<input type="text" id="taskDesc" placeholder="任务描述(可选)">
<label>提示词</label>
<textarea id="taskPrompt" rows="3" placeholder="输入生成提示词,支持 (@图片1) (@图片2) 引用..."></textarea>
<div class="quick-insert-row" id="quickInsertRow">
<span class="qi-label">快捷插入:</span>
<span class="qi-hint" id="qiHint">请先上传参考图片</span>
<span id="qiButtons"></span>
<input class="qi-custom" id="qiCustom" type="text" placeholder="自定义文件名" maxlength="60">
<button class="qi-btn qi-btn-custom" id="qiCustomBtn">插入 (@...)</button>
</div>
<div class="config-row">
<div>
<label>模型</label>
<select id="cfgModel">
<option value="Seedance 2.0 Fast" selected>Seedance 2.0 Fast</option>
<option value="Seedance 2.0">Seedance 2.0</option>
</select>
</div>
<div>
<label>参考模式</label>
<select id="cfgRefMode">
<option value="全能参考" selected>全能参考</option>
<option value="首尾帧">首尾帧</option>
<option value="主体参考">主体参考</option>
</select>
</div>
</div>
<div class="config-row">
<div>
<label>画面比例</label>
<select id="cfgRatio">
<option value="16:9" selected>16:9</option>
<option value="9:16">9:16</option>
<option value="1:1">1:1</option>
<option value="4:3">4:3</option>
<option value="3:4">3:4</option>
<option value="21:9">21:9</option>
<option value="9:21">9:21</option>
</select>
</div>
<div>
<label>视频时长</label>
<select id="cfgDuration">
<option value="4s" selected>4s</option>
<option value="5s">5s</option>
<option value="6s">6s</option>
<option value="7s">7s</option>
<option value="8s">8s</option>
<option value="9s">9s</option>
<option value="10s">10s</option>
</select>
</div>
</div>
<label>参考图片</label>
<div class="upload-area" id="uploadArea">
<div class="icon">📁</div>
<div class="text">点击或拖拽上传参考图片</div>
</div>
<input type="file" class="upload-file-input" id="fileInput" multiple accept="image/jpeg,image/png,image/webp">
<div class="file-preview" id="filePreview"></div>
<div class="checkbox-row" id="realSubmitRow">
<input type="checkbox" id="realSubmit">
<label class="cb-label" for="realSubmit">真实提交到 Seedance 2.0 生成</label>
<span class="cb-hint">默认模拟</span>
</div>
<div class="btn-row">
<button class="btn btn-primary" id="btnPush">📤 推送任务</button>
</div>
</div>
<!-- 右栏: 预制案例 -->
<div class="panel">
<div class="panel-title">⚡ 快捷预制案例</div>
<p style="font-size: 11px; color: #8b8fa3; margin-bottom: 10px;">点击卡片一键填充,或直接推送</p>
<div class="preset-grid" id="presetGrid"></div>
<div style="margin-top: 20px; border-top: 1px solid #1e3a5f; padding-top: 15px;">
<div class="panel-title" style="margin-bottom: 10px;">📡 SSE 客户端</div>
<div id="sseClientList" style="font-size: 12px; color: #8b8fa3;">暂无连接</div>
</div>
<div style="margin-top: 15px;">
<div class="panel-title" style="margin-bottom: 10px;">📝 操作日志</div>
<div class="log-area" id="logArea"></div>
</div>
</div>
<!-- 底部: 任务列表 -->
<div class="panel panel-full">
<div class="panel-title" style="justify-content: space-between;">
<span>📋 任务列表</span>
<button class="btn-sm" id="btnRefreshTasks">🔄 刷新</button>
</div>
<table class="task-table">
<thead>
<tr>
<th>任务编号</th>
<th>描述</th>
<th>提示词</th>
<th>图片</th>
<th>状态</th>
<th>真实提交</th>
<th>占用者</th>
<th>创建时间</th>
</tr>
</thead>
<tbody id="taskTableBody">
<tr><td colspan="8" style="text-align:center;color:#555;">加载中...</td></tr>
</tbody>
</table>
</div>
</div>
<script>
const API = window.location.origin;
// ============================================================
// 预制案例
// ============================================================
const PRESETS = [
{
name: '💃 女孩跳舞',
description: '女孩在舞台上优雅跳舞,带参考图,16:9 横屏',
prompt: '一个穿着红色连衣裙的女孩 (@图片1) 在灯光璀璨的舞台中央优雅地旋转跳舞,裙摆飞扬',
modelConfig: { model: 'Seedance 2.0 Fast', referenceMode: '全能参考', aspectRatio: '16:9', duration: '4s' },
tags: ['portrait', 'dance', '带图'],
useTestImage: true,
testImageColors: [[200, 100, 100]],
},
{
name: '🏔️ 山脉日出',
description: '壮丽山脉延时摄影,带参考图,云海翻涌',
prompt: '壮丽的山脉日出延时摄影 (@图片1) 金色阳光洒满山谷 云海翻涌光影变幻',
modelConfig: { model: 'Seedance 2.0 Fast', referenceMode: '全能参考', aspectRatio: '16:9', duration: '4s' },
tags: ['landscape', 'nature', '带图'],
useTestImage: true,
testImageColors: [[80, 130, 200]],
},
{
name: '📦 产品展示',
description: '产品360度旋转展示,带参考图,1:1正方形',
prompt: '精致的产品在纯白背景上缓慢360度旋转展示 (@图片1) 光影柔和细节清晰',
modelConfig: { model: 'Seedance 2.0 Fast', referenceMode: '全能参考', aspectRatio: '1:1', duration: '4s' },
tags: ['product', 'commercial', '带图'],
useTestImage: true,
testImageColors: [[240, 240, 240]],
},
{
name: '🌊 海浪沙滩',
description: '海浪拍打沙滩,带参考图,竖屏视频',
prompt: '蔚蓝海浪轻柔地拍打金色沙滩 (@图片1) 泡沫退去留下水渍 阳光在水面上闪烁',
modelConfig: { model: 'Seedance 2.0 Fast', referenceMode: '全能参考', aspectRatio: '9:16', duration: '4s' },
tags: ['nature', 'ocean', '带图'],
useTestImage: true,
testImageColors: [[40, 120, 200]],
},
{
name: '🐱 猫咪特写',
description: '可爱猫咪转头看镜头,带参考图',
prompt: '一只毛茸茸的橘猫 (@图片1) 慢慢转头看向镜头 眨了眨大眼睛 背景虚化',
modelConfig: { model: 'Seedance 2.0 Fast', referenceMode: '全能参考', aspectRatio: '1:1', duration: '4s' },
tags: ['animal', 'cute', '带图'],
useTestImage: true,
testImageColors: [[220, 160, 60]],
},
{
name: '🏙️ 城市夜景',
description: '城市霓虹灯夜景延时,带参考图',
prompt: '繁华都市夜景延时摄影 (@图片1) 霓虹灯闪烁 车流形成光轨 高楼大厦灯火辉煌',
modelConfig: { model: 'Seedance 2.0 Fast', referenceMode: '全能参考', aspectRatio: '21:9', duration: '4s' },
tags: ['city', 'night', '带图'],
useTestImage: true,
testImageColors: [[30, 30, 80]],
},
];
// ============================================================
// 状态
// ============================================================
let uploadedFiles = []; // { name, base64, type }
// 清理文件名中的括号,避免干扰 (@xxx) mention 语法
function sanitizeFileName(name) {
return name.replace(/[()\uff08\uff09\[\]\u3010\u3011{}\uff5b\uff5d]/g, '_').replace(/_+/g, '_').replace(/^_|_$/g, '');
}
// ============================================================
// DOM
// ============================================================
const taskDesc = document.getElementById('taskDesc');
const taskPrompt = document.getElementById('taskPrompt');
const cfgModel = document.getElementById('cfgModel');
const cfgRefMode = document.getElementById('cfgRefMode');
const cfgRatio = document.getElementById('cfgRatio');
const cfgDuration = document.getElementById('cfgDuration');
const realSubmitCb = document.getElementById('realSubmit');
const realSubmitRow = document.getElementById('realSubmitRow');
const uploadArea = document.getElementById('uploadArea');
const fileInput = document.getElementById('fileInput');
const filePreview = document.getElementById('filePreview');
const btnPush = document.getElementById('btnPush');
const presetGrid = document.getElementById('presetGrid');
const logArea = document.getElementById('logArea');
const taskTableBody = document.getElementById('taskTableBody');
const btnRefreshTasks = document.getElementById('btnRefreshTasks');
const sseDot = document.getElementById('sseDot');
const sseStatusText = document.getElementById('sseStatusText');
const taskCountBadge = document.getElementById('taskCountBadge');
const sseClientList = document.getElementById('sseClientList');
// ============================================================
// 真实提交警告样式
// ============================================================
// ============================================================
// 快捷插入
// ============================================================
const qiCustom = document.getElementById('qiCustom');
const qiCustomBtn = document.getElementById('qiCustomBtn');
const qiButtons = document.getElementById('qiButtons');
const qiHint = document.getElementById('qiHint');
function insertAtCursor(text) {
taskPrompt.focus();
const start = taskPrompt.selectionStart;
const end = taskPrompt.selectionEnd;
const before = taskPrompt.value.substring(0, start);
const after = taskPrompt.value.substring(end);
const needSpaceBefore = before.length > 0 && !before.endsWith(' ') && !before.endsWith('\n');
const needSpaceAfter = after.length > 0 && !after.startsWith(' ') && !after.startsWith('\n');
const insert = (needSpaceBefore ? ' ' : '') + text + (needSpaceAfter ? ' ' : '');
taskPrompt.value = before + insert + after;
const newPos = start + insert.length;
taskPrompt.setSelectionRange(newPos, newPos);
taskPrompt.focus();
}
function updateQuickInsert() {
qiButtons.innerHTML = '';
if (uploadedFiles.length === 0) {
qiHint.style.display = '';
return;
}
qiHint.style.display = 'none';
uploadedFiles.forEach((f) => {
const btn = document.createElement('button');
btn.className = 'qi-btn';
const tag = `(@${f.fileName})`;
btn.textContent = tag;
btn.title = `插入 ${tag}`;
btn.dataset.insert = tag;
qiButtons.appendChild(btn);
});
}
document.getElementById('quickInsertRow').addEventListener('click', (e) => {
const btn = e.target.closest('.qi-btn');
if (!btn) return;
if (btn.id === 'qiCustomBtn') {
const name = qiCustom.value.trim();
if (!name) { qiCustom.focus(); return; }
insertAtCursor(`(@${name})`);
qiCustom.value = '';
} else if (btn.dataset.insert) {
insertAtCursor(btn.dataset.insert);
}
});
qiCustom.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
e.preventDefault();
qiCustomBtn.click();
}
});
// ============================================================
// 真实提交警告样式
// ============================================================
realSubmitCb.addEventListener('change', () => {
if (realSubmitCb.checked) {
realSubmitRow.classList.add('warn');
realSubmitRow.querySelector('.cb-hint').textContent = '⚠️ 将真实提交!';
} else {
realSubmitRow.classList.remove('warn');
realSubmitRow.querySelector('.cb-hint').textContent = '默认模拟';
}
});
// ============================================================
// 文件上传
// ============================================================
uploadArea.addEventListener('click', () => fileInput.click());
uploadArea.addEventListener('dragover', (e) => { e.preventDefault(); uploadArea.style.borderColor = '#3a7bd5'; });
uploadArea.addEventListener('dragleave', () => { uploadArea.style.borderColor = '#1e3a5f'; });
uploadArea.addEventListener('drop', (e) => {
e.preventDefault();
uploadArea.style.borderColor = '#1e3a5f';
handleFiles(e.dataTransfer.files);
});
fileInput.addEventListener('change', (e) => {
handleFiles(e.target.files);
fileInput.value = '';
});
function handleFiles(files) {
for (const file of files) {
if (!file.type.startsWith('image/')) continue;
const reader = new FileReader();
reader.onload = (e) => {
uploadedFiles.push({
fileName: sanitizeFileName(file.name),
base64: e.target.result,
fileType: file.type,
});
renderFilePreview();
};
reader.readAsDataURL(file);
}
}
function renderFilePreview() {
filePreview.innerHTML = '';
uploadedFiles.forEach((f, i) => {
const thumb = document.createElement('div');
thumb.className = 'file-thumb';
thumb.innerHTML = `
<img src="${f.base64}" alt="${f.fileName}">
<button class="remove" data-idx="${i}" title="移除">×</button>
`;
filePreview.appendChild(thumb);
});
filePreview.querySelectorAll('.remove').forEach(btn => {
btn.addEventListener('click', (e) => {
e.stopPropagation();
uploadedFiles.splice(parseInt(btn.dataset.idx), 1);
renderFilePreview();
});
});
updateQuickInsert();
}
// ============================================================
// 预制案例渲染
// ============================================================
function renderPresets() {
presetGrid.innerHTML = '';
PRESETS.forEach((preset, idx) => {
const card = document.createElement('div');
card.className = 'preset-card';
card.innerHTML = `
<div class="preset-name">${preset.name}</div>
<div class="preset-desc">${preset.description}</div>
<div class="preset-tags">
${preset.tags.map(t => `<span class="tag">${t}</span>`).join('')}
<span class="tag">${preset.modelConfig.aspectRatio}</span>
<span class="tag">${preset.modelConfig.duration}</span>
</div>
<div style="margin-top:8px;display:flex;gap:5px;">
<button class="btn-sm" data-action="fill" data-idx="${idx}">📝 填充</button>
<button class="btn-sm" data-action="push" data-idx="${idx}">📤 推送</button>
</div>
`;
presetGrid.appendChild(card);
});
presetGrid.querySelectorAll('[data-action="fill"]').forEach(btn => {
btn.addEventListener('click', (e) => {
e.stopPropagation();
fillFromPreset(parseInt(btn.dataset.idx));
});
});
presetGrid.querySelectorAll('[data-action="push"]').forEach(btn => {
btn.addEventListener('click', (e) => {
e.stopPropagation();
pushPreset(parseInt(btn.dataset.idx));
});
});
}
function fillFromPreset(idx) {
const p = PRESETS[idx];
taskDesc.value = p.description;
taskPrompt.value = p.prompt;
cfgModel.value = p.modelConfig.model;
cfgRefMode.value = p.modelConfig.referenceMode;
cfgRatio.value = p.modelConfig.aspectRatio;
cfgDuration.value = p.modelConfig.duration;
// 生成测试图片并填充到上传区
uploadedFiles = [];
if (p.useTestImage && p.testImageColors) {
p.testImageColors.forEach((color, i) => {
const base64 = generateTestImage(color[0], color[1], color[2]);
uploadedFiles.push({
fileName: `图片${i + 1}`,
base64,
fileType: 'image/png',
});
});
}
renderFilePreview();
addLog(`📝 已填充预制案例: ${p.name} (${uploadedFiles.length} 张参考图)`);
}
function generateTestImage(r, g, b, size = 512) {
const canvas = document.createElement('canvas');
canvas.width = size;
canvas.height = size;
const ctx = canvas.getContext('2d');
ctx.fillStyle = `rgb(${r},${g},${b})`;
ctx.fillRect(0, 0, size, size);
// 画个十字标记表示测试图
ctx.strokeStyle = 'rgba(255,255,255,0.3)';
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(size / 2, 0);
ctx.lineTo(size / 2, size);
ctx.moveTo(0, size / 2);
ctx.lineTo(size, size / 2);
ctx.stroke();
// 标注颜色值
ctx.fillStyle = 'rgba(255,255,255,0.6)';
ctx.font = '24px sans-serif';
ctx.textAlign = 'center';
ctx.fillText(`TEST (${r},${g},${b})`, size / 2, size / 2 + 8);
return canvas.toDataURL('image/png');
}
async function pushPreset(idx) {
const p = PRESETS[idx];
// 根据 testImageColors 生成测试图片
const refFiles = [];
if (p.useTestImage && p.testImageColors) {
p.testImageColors.forEach((color, i) => {
const base64 = generateTestImage(color[0], color[1], color[2]);
refFiles.push({
fileName: `图片${i + 1}`,
base64,
fileType: 'image/png',
});
});
}
const task = {
description: p.description,
prompt: p.prompt,
tags: p.tags,
modelConfig: p.modelConfig,
referenceFiles: refFiles,
realSubmit: realSubmitCb.checked,
};
try {
const resp = await fetch(`${API}/api/tasks/push`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(task),
});
const data = await resp.json();
if (data.success) {
addLog(`✅ 预制案例 "${p.name}" 已推送: ${data.taskCodes.join(', ')}`, 'success');
refreshTaskList();
} else {
addLog(`❌ 推送失败: ${data.error}`, 'error');
}
} catch (err) {
addLog(`❌ 推送异常: ${err.message}`, 'error');
}
}
// ============================================================
// 推送任务
// ============================================================
btnPush.addEventListener('click', async () => {
const prompt = taskPrompt.value.trim();
if (!prompt && uploadedFiles.length === 0) {
addLog('⚠️ 请输入提示词或上传参考图', 'error');
return;
}
btnPush.disabled = true;
btnPush.textContent = '⏳ 推送中...';
const task = {
description: taskDesc.value.trim(),
prompt,
modelConfig: {
model: cfgModel.value,
referenceMode: cfgRefMode.value,
aspectRatio: cfgRatio.value,
duration: cfgDuration.value,
},
referenceFiles: uploadedFiles.map(f => ({
fileName: f.fileName,
base64: f.base64,
fileType: f.fileType,
})),
realSubmit: realSubmitCb.checked,
};
try {
const resp = await fetch(`${API}/api/tasks/push`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(task),
});
const data = await resp.json();
if (data.success) {
addLog(`✅ 任务已推送: ${data.taskCodes.join(', ')} (通知 ${data.notified} 个客户端)`, 'success');
refreshTaskList();
// 清空表单
taskDesc.value = '';
taskPrompt.value = '';
uploadedFiles = [];
renderFilePreview();
} else {
addLog(`❌ 推送失败: ${data.error}`, 'error');
}
} catch (err) {
addLog(`❌ 推送异常: ${err.message}`, 'error');
}
btnPush.disabled = false;
btnPush.textContent = '📤 推送任务';
});
// ============================================================
// 任务列表
// ============================================================
const STATUS_LABELS = {
pending: '待处理',
occupied: '已占用',
acked: '已确认',
configuring: '⚙️ 配置中',
running: '执行中',
generating: '🎬 生成中',
uploading: '📤 上传标清',
upscaling: '🔺 提升中',