index_old.html 58.5 KB
Newer Older
LiangLiu's avatar
LiangLiu committed
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>LightX2V 文生视频服务</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        .login-container {
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .main-container {
            min-height: 100vh;
            background-color: #f8f9fa;
        }
        .navbar-brand {
            font-weight: bold;
            color: #667eea !important;
        }
        .card {
            border: none;
            border-radius: 15px;
            box-shadow: 0 0 20px rgba(0,0,0,0.1);
        }
        .btn-github {
            background-color: #24292e;
            border-color: #24292e;
            color: white;
        }
        .btn-github:hover {
            background-color: #1a1e22;
            border-color: #1a1e22;
            color: white;
        }
        .task-card {
            transition: transform 0.2s;
        }
        .task-card:hover {
            transform: translateY(-2px);
        }
        .status-badge {
            font-size: 0.8em;
        }
        .user-avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
        }
        .loading {
            display: none;
        }
        .loading.show {
            display: block;
        }
        .fade-enter-active, .fade-leave-active {
            transition: opacity 0.3s;
        }
        .fade-enter-from, .fade-leave-to {
            opacity: 0;
        }
        .task-card {
            border-left: 4px solid #667eea;
            transition: all 0.3s ease;
        }
        .task-card:hover {
            border-left-color: #764ba2;
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        }
        .task-detail-section {
            background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
            border-radius: 8px;
            margin-top: 15px;
        }
        .prompt-text {
            word-break: break-word;
            line-height: 1.6;
        }
        .output-badge {
            font-size: 0.75em;
            margin-right: 5px;
        }
        .btn-group .btn {
            margin-left: 5px;
        }
        .btn-group .btn:first-child {
            margin-left: 0;
        }
        .status-badge i {
            font-size: 0.6em;
        }
        .card-title {
            font-weight: 600;
        }
        .text-truncate {
            max-width: 200px;
            display: inline-block;
            vertical-align: middle;
        }
        .task-card .card-body {
            padding: 1.25rem;
        }
        .badge {
            font-weight: 500;
        }
        .badge i {
            font-size: 0.8em;
        }
        .task-tags .badge {
            font-size: 0.75em;
            padding: 0.35em 0.65em;
        }
        .status-badge {
            font-size: 0.8em;
            padding: 0.4em 0.8em;
        }
        .flex-column .btn-group {
            width: 100%;
        }
        .flex-column .btn-group .btn {
            flex: 1;
        }

        /* 分页组件样式 */
        .pagination .page-link {
            color: #667eea;
            border-color: #dee2e6;
        }
        .pagination .page-item.active .page-link {
            background-color: #667eea;
            border-color: #667eea;
            color: white;
        }
        .pagination .page-item.disabled .page-link {
            color: #6c757d;
            background-color: #fff;
            border-color: #dee2e6;
        }
        .pagination .page-link:hover {
            color: #764ba2;
            background-color: #e9ecef;
            border-color: #dee2e6;
        }
        .pagination .page-item.active .page-link:hover {
            background-color: #764ba2;
            border-color: #764ba2;
            color: white;
        }
    </style>
</head>
<body>
    <div id="app">
        <!-- 登录页面 -->
        <div v-if="!isLoggedIn" class="login-container">
            <div class="container">
                <div class="row justify-content-center">
                    <div class="col-md-6 col-lg-4">
                        <div class="card">
                            <div class="card-body text-center p-5">
                                <h2 class="mb-4">
                                    <i class="fas fa-brain text-primary"></i>
                                    LightX2V
                                </h2>
                                <p class="text-muted mb-4">文生视频服务</p>
                                <button @click="loginWithGitHub" class="btn btn-github btn-lg w-100" :disabled="loading">
                                    <i class="fab fa-github me-2"></i>
                                    {{ loading ? '登录中...' : '使用GitHub登录' }}
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 主应用页面 -->
        <div v-else class="main-container">
            <!-- 导航栏 -->
            <nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
                <div class="container">
                    <a class="navbar-brand" href="/">
                        <i class="fas fa-brain me-2"></i>
                        LightX2V
                    </a>
                    <div class="navbar-nav ms-auto">
                        <div class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle d-flex align-items-center" href="#" id="userDropdown" role="button" data-bs-toggle="dropdown">
                                <img :src="currentUser.avatar_url" alt="Avatar" class="user-avatar me-2">
                                <span>{{ currentUser.username }}</span>
                            </a>
                            <ul class="dropdown-menu">
                                <li><a class="dropdown-item" href="#" @click="logout">退出登录</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </nav>

            <!-- 主要内容 -->
            <div class="container mt-4">
                <!-- 模型列表 -->
                <div class="row mb-4">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-header">
                                <h5 class="mb-0">
                                    <i class="fas fa-list me-2"></i>
                                    可用模型
                                </h5>
                            </div>
                            <div class="card-body">
                                <div class="row">
                                    <div v-for="model in models" :key="`${model.task}-${model.model_cls}-${model.stage}`" class="col-md-4 mb-3">
                                        <div class="card task-card h-100">
                                            <div class="card-body">
                                                <h6 class="card-title">任务类型:{{ model.task }}</h6>
                                                <p class="card-text text-muted">模型名称:{{ model.model_cls }}</p>
                                                <small class="text-muted">推理模式: {{ model.stage }}</small>
                                            </div>
                                        </div>
                                    </div>
                                    <div v-if="models.length === 0" class="col-12 text-center text-muted">
                                        暂无可用模型
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 任务提交 -->
                <div class="row mb-4">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-header">
                                <h5 class="mb-0">
                                    <i class="fas fa-plus me-2"></i>
                                    提交新任务
                                </h5>
                            </div>
                            <div class="card-body">
                                <form @submit.prevent="submitTask">
                                    <div class="row">
                                        <div class="col-md-3 mb-3">
                                            <label for="taskType" class="form-label">任务类型</label>
                                            <select class="form-select" v-model="taskForm.task" required>
                                                <option value="">选择任务类型</option>
                                                <option v-for="taskType in availableTaskTypes" :key="taskType" :value="taskType">
                                                    {{ taskType }}
                                                </option>
                                            </select>
                                        </div>
                                        <div class="col-md-3 mb-3">
                                            <label for="modelClass" class="form-label">模型名称</label>
                                            <select class="form-select" v-model="taskForm.model_cls" required>
                                                <option value="">选择模型名称</option>
                                                <option v-for="modelClass in availableModelClasses" :key="modelClass" :value="modelClass">
                                                    {{ modelClass }}
                                                </option>
                                            </select>
                                        </div>
                                        <div class="col-md-3 mb-3">
                                            <label for="stage" class="form-label">推理模式</label>
                                            <select class="form-select" v-model="taskForm.stage" required>
                                                <option value="">选择推理模式</option>
                                                <option v-for="stage in availableStages" :key="stage" :value="stage">
                                                    {{ stage }}
                                                </option>
                                            </select>
                                        </div>
                                        <div class="col-md-3 mb-3">
                                            <label for="prompt" class="form-label">提示词</label>
                                            <input type="text" class="form-control" v-model="taskForm.prompt" placeholder="请输入提示词" required>
                                        </div>
                                        <div class="col-md-3 mb-3">
                                            <label for="seed" class="form-label">随机种子</label>
                                            <input type="number" class="form-control" v-model="taskForm.seed" placeholder="42" required>
                                        </div>
                                        <div class="col-md-3 mb-3" v-if="taskForm.task === 'i2v'">
                                            <label for="inputFile" class="form-label">输入图片</label>
                                            <input type="file" class="form-control" @change="handleImageUpload" accept="image/*" required>
                                            <div v-if="imagePreview" class="mt-2">
                                                <img :src="imagePreview" alt="预览图片" class="img-thumbnail" style="max-width: 100px; max-height: 100px;">
                                            </div>
                                        </div>
                                        <div class="col-md-3 mb-3" v-if="isAudioModel">
                                            <label for="audioFile" class="form-label">输入音频</label>
                                            <input type="file" class="form-control" @change="handleAudioUpload" accept="audio/*" required>
                                            <div v-if="audioPreview" class="mt-2">
                                                <audio controls style="max-width: 100%; max-height: 60px;">
                                                    <source :src="audioPreview" type="audio/mpeg">
                                                    您的浏览器不支持音频播放
                                                </audio>
                                            </div>
                                        </div>
                                    </div>
                                    <button type="submit" class="btn btn-primary" :disabled="submitting">
                                        <i class="fas fa-paper-plane me-2"></i>
                                        {{ submitting ? '提交中...' : '提交任务' }}
                                    </button>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 任务列表 -->
                <div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-header d-flex justify-content-between align-items-center">
                                <h5 class="mb-0">
                                    <i class="fas fa-tasks me-2"></i>
                                    任务列表
                                </h5>
                                <div class="d-flex align-items-center">
                                    <!-- 状态过滤器 -->
                                    <select v-model="statusFilter" @change="refreshTasks" class="form-select form-select-sm me-2" style="width: auto;">
                                        <option value="ALL" selected>ALL</option>
                                        <option value="CREATED">CREATED</option>
                                        <option value="PENDING">PENDING</option>
                                        <option value="RUNNING">RUNNING</option>
                                        <option value="SUCCEED">SUCCEED</option>
                                        <option value="FAILED">FAILED</option>
                                        <option value="CANCEL">CANCEL</option>
                                    </select>
                                    <button class="btn btn-outline-primary btn-sm" @click="refreshTasks" :disabled="loading">
                                        <i class="fas fa-sync-alt me-1"></i>
                                        刷新
                                    </button>
                                </div>
                            </div>
                            <div class="card-body">
                                <div v-if="tasks.length === 0" class="text-center text-muted">
                                    暂无任务记录
                                </div>
                                <div v-else>
                                    <div v-for="task in tasks" :key="task.task_id" class="card task-card mb-3">
                                        <div class="card-body">
                                            <!-- 任务摘要信息 -->
                                            <div class="row align-items-center">
                                                <div class="col-md-8">
                                                    <div class="d-flex justify-content-between align-items-center mb-3">
                                                        <div class="d-flex align-items-center">
                                                            <h6 class="card-title mb-0 text-primary me-3">
                                                                <i class="fas fa-hashtag me-1"></i>
                                                                {{ task.task_id }}
                                                            </h6>
                                                            <div class="task-tags">
                                                                <span class="badge bg-primary me-1">
                                                                    <i class="fas fa-tasks me-1"></i>
                                                                    {{ task.task_type }}
                                                                </span>
                                                                <span class="badge bg-info me-1">
                                                                    <i class="fas fa-brain me-1"></i>
                                                                    {{ task.model_cls }}
                                                                </span>
                                                                <span class="badge bg-warning">
                                                                    <i class="fas fa-cog me-1"></i>
                                                                    {{ task.stage }}
                                                                </span>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-6">
                                                            <p class="card-text mb-2" v-if="task.params.prompt">
                                                                <strong>
                                                                    <i class="fas fa-comment me-1"></i>
                                                                    提示词:
                                                                </strong>
                                                                <span class="text-truncate d-inline-block" style="max-width: 200px;" :title="task.params.prompt">
                                                                    {{ task.params.prompt.length > 50 ? task.params.prompt.substring(0, 50) + '...' : task.params.prompt }}
                                                                </span>
                                                            </p>
                                                            <p class="card-text mb-1" v-if="task.params.seed">
                                                                <strong>
                                                                    <i class="fas fa-seedling me-1"></i>
                                                                    种子值:
                                                                </strong>
                                                                <span class="badge bg-secondary">{{ task.params.seed }}</span>
                                                            </p>
                                                        </div>
                                                        <div class="col-md-6">
                                                            <p class="card-text mb-2" v-if="task.create_t">
                                                                <strong>
                                                                    <i class="fas fa-calendar me-1"></i>
                                                                    创建时间:
                                                                </strong>
                                                                <small>{{ formatTime(task.create_t) }}</small>
                                                            </p>
                                                            <p v-if="task.status === 'SUCCEED' && task.outputs && Object.keys(task.outputs).length > 0" class="mb-2">
                                                                <strong>
                                                                    <i class="fas fa-file-video me-1"></i>
                                                                    输出:
                                                                </strong>
                                                                <span class="mt-1">
                                                                    <span v-for="(output, key) in task.outputs" :key="key" class="me-2 mb-1 d-inline-flex align-items-center">
                                                                        {{ key }}
                                                                        <i class="fas fa-eye ms-1" style="cursor: pointer; color: #28a745;" @click="viewSingleResult(task.task_id, key, output)" title="查看此文件"></i>
                                                                        <i class="fas fa-download ms-1" style="cursor: pointer; color: #007bff;" @click="downloadSingleResult(task.task_id, key, output)" title="下载此文件"></i>
                                                                    </span>
                                                                </span>
                                                            </p>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-md-4 text-end">
                                                    <div class="d-flex align-items-center justify-content-end">
                                                        <span :class="getStatusBadgeClass(task.status)" class="badge status-badge me-2">
                                                            <i class="fas fa-circle me-1"></i>
                                                            {{ task.status }}
                                                        </span>
                                                        <div class="btn-group" role="group">
                                                            <button class="btn btn-outline-info btn-sm" @click="toggleTaskDetail(task.task_id)">
                                                                <i class="fas fa-info-circle me-1"></i>
                                                                {{ expandedTasks.includes(task.task_id) ? '收起' : '详情' }}
                                                            </button>
                                                            <button v-if="['CREATED', 'PENDING', 'RUNNING'].includes(task.status)"
                                                                    class="btn btn-outline-warning btn-sm"
                                                                    @click="cancelTask(task.task_id)">
                                                                <i class="fas fa-stop me-1"></i>
                                                                取消
                                                            </button>
                                                            <button v-if="['SUCCEED', 'FAILED', 'CANCEL'].includes(task.status)"
                                                                    class="btn btn-outline-success btn-sm"
                                                                    @click="resumeTask(task.task_id)">
                                                                <i class="fas fa-redo me-1"></i>
                                                                重试
                                                            </button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>

                                            <!-- 详细展开信息 -->
                                            <div v-if="expandedTasks.includes(task.task_id)" class="task-detail-section p-3">
                                                <div class="row">
                                                    <div class="col-md-6">
                                                        <h6 class="text-muted mb-2">
                                                            <i class="fas fa-comment me-1"></i>
                                                            完整提示词
                                                        </h6>
                                                        <div class="bg-white p-3 rounded border">
                                                            <p class="mb-0 prompt-text">{{ task.params.prompt || '无提示词' }}</p>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-6">
                                                        <h6 class="text-muted mb-2">
                                                            <i class="fas fa-cog me-1"></i>
                                                            任务参数
                                                        </h6>
                                                        <div class="bg-white p-3 rounded border">
                                                            <div class="mb-3 d-flex align-items-center">
                                                                <strong class="me-2">任务类型:</strong>
                                                                <span class="badge bg-primary">
                                                                    <i class="fas fa-tasks me-1"></i>
                                                                    {{ task.task_type }}
                                                                </span>
                                                            </div>
                                                            <div class="mb-3 d-flex align-items-center">
                                                                <strong class="me-2">模型名称:</strong>
                                                                <span class="badge bg-info">
                                                                    <i class="fas fa-brain me-1"></i>
                                                                    {{ task.model_cls }}
                                                                </span>
                                                            </div>
                                                            <div class="mb-3 d-flex align-items-center">
                                                                <strong>推理模式:</strong>
                                                                <span class="badge bg-warning ms-2">
                                                                    <i class="fas fa-cog me-1"></i>
                                                                    {{ task.stage }}
                                                                </span>
                                                            </div>
                                                            <div class="mb-3 d-flex align-items-center" v-if="task.params.seed">
                                                                <strong>种子值:</strong>
                                                                <span class="badge bg-secondary ms-2">{{ task.params.seed }}</span>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row mt-3">
                                                    <div class="col-md-6">
                                                        <h6 class="text-muted mb-2">
                                                            <i class="fas fa-clock me-1"></i>
                                                            时间信息
                                                        </h6>
                                                        <div class="bg-white p-3 rounded border">
                                                            <ul class="list-unstyled mb-0">
                                                                <li><strong>创建时间:</strong> {{ formatTime(task.create_t) }}</li>
                                                                <li><strong>更新时间:</strong> {{ formatTime(task.update_t) }}</li>
                                                            </ul>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-6" v-if="task.outputs && task.inputs">
                                                        <h6 class="text-muted mb-2">
                                                            <i class="fas fa-file-video me-1"></i>
                                                            输入文件/输出结果
                                                        </h6>
                                                        <div class="bg-white p-3 rounded border">
                                                            <div v-for="(input, key) in task.inputs" :key="key" class="mb-2">
                                                                <strong>输入文件:</strong>
                                                                <span class="badge bg-secondary output-badge">{{ key }}</span>
                                                            </div>
                                                            <div v-for="(output, key) in task.outputs" :key="key" class="mb-2">
                                                                <strong>输出结果:</strong>
                                                                <span class="badge bg-success output-badge">{{ key }}</span>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <!-- 分页组件 -->
                                <div v-if="pagination && pagination.total_pages > 0" class="d-flex justify-content-between align-items-center mt-4">
                                    <div class="text-muted">
                                        显示第 {{ (pagination.page - 1) * pagination.page_size + 1 }} -
                                        {{ Math.min(pagination.page * pagination.page_size, pagination.total) }} 条,
                                        共 {{ pagination.total }} 条记录
                                    </div>
                                    <nav aria-label="任务列表分页">
                                        <ul class="pagination pagination-sm mb-0">
                                            <!-- 上一页 -->
                                            <li class="page-item" :class="{ disabled: pagination.page <= 1 }">
                                                <a class="page-link" href="#" @click.prevent="changePage(pagination.page - 1)">
                                                    <i class="fas fa-chevron-left"></i>
                                                </a>
                                            </li>

                                            <!-- 页码 -->
                                            <li v-for="pageNum in visiblePages" :key="pageNum"
                                                class="page-item" :class="{ active: pageNum === pagination.page }">
                                                <a class="page-link" href="#" @click.prevent="changePage(pageNum)">
                                                    {{ pageNum }}
                                                </a>
                                            </li>

                                            <!-- 下一页 -->
                                            <li class="page-item" :class="{ disabled: pagination.page >= pagination.total_pages }">
                                                <a class="page-link" href="#" @click.prevent="changePage(pagination.page + 1)">
                                                    <i class="fas fa-chevron-right"></i>
                                                </a>
                                            </li>
                                        </ul>
                                    </nav>

                                    <!-- 每页显示数量选择器 -->
                                    <div class="d-flex align-items-center">
                                        <span class="text-muted me-2">每页显示:</span>
                                        <select v-model="pageSize" @change="changePageSize" class="form-select form-select-sm" style="width: auto;">
                                            <option value="5">5</option>
                                            <option value="10">10</option>
                                            <option value="20">20</option>
                                            <option value="50">50</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 加载指示器 -->
        <div v-if="loading" class="loading position-fixed top-50 start-50 translate-middle show">
            <div class="spinner-border text-primary" role="status">
                <span class="visually-hidden">加载中...</span>
            </div>
        </div>

        <!-- 提示消息 -->
        <div v-if="alert.show" class="position-fixed top-0 start-50 translate-middle-x mt-3" style="z-index: 9999;">
            <div :class="`alert alert-${alert.type} alert-dismissible fade show`" role="alert">
                {{ alert.message }}
                <button type="button" class="btn-close" @click="alert.show = false"></button>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

    <script>
        const { createApp, ref, computed, onMounted, watch } = Vue;

        createApp({
            setup() {
                // 响应式数据
                const isLoggedIn = ref(false);
                const loading = ref(false);
                const submitting = ref(false);
                const currentUser = ref({});
                const models = ref([]);
                const tasks = ref([]);
                const alert = ref({ show: false, message: '', type: 'info' });
                const expandedTasks = ref([]); // 新增:用于控制任务详情展开

                // 分页相关数据
                const pagination = ref(null);
                const currentPage = ref(1);
                const pageSize = ref(10);
                const statusFilter = ref('ALL');

                const taskForm = ref({
                    task: '',
                    model_cls: '',
                    stage: '',
                    imageFile: null,
                    audioFile: null,
                    prompt: '',
                    seed: 42
                });

                const imagePreview = ref(null);
                const audioPreview = ref(null);

                // 计算属性
                const availableTaskTypes = computed(() => {
                    return [...new Set(models.value.map(m => m.task))];
                });

                const availableModelClasses = computed(() => {
                    if (!taskForm.value.task) return [];
                    return [...new Set(models.value
                        .filter(m => m.task === taskForm.value.task)
                        .map(m => m.model_cls))];
                });

                const availableStages = computed(() => {
                    if (!taskForm.value.task || !taskForm.value.model_cls) return [];
                    return [...new Set(models.value
                        .filter(m => m.task === taskForm.value.task && m.model_cls === taskForm.value.model_cls)
                        .map(m => m.stage))];
                });

                const isAudioModel = computed(() => {
                    return taskForm.value.model_cls && (taskForm.value.model_cls.includes('audio') || taskForm.value.model_cls.includes('Audio'));
                });

                // 分页相关计算属性
                const visiblePages = computed(() => {
                    if (!pagination.value) return [];
                    const totalPages = pagination.value.total_pages;
                    const current = pagination.value.page;
                    const pages = [];

                    // 显示最多5个页码
                    let start = Math.max(1, current - 2);
                    let end = Math.min(totalPages, current + 2);

                    // 调整起始位置,确保显示5个页码(如果可能)
                    if (end - start < 4 && totalPages > 4) {
                        if (start === 1) {
                            end = Math.min(totalPages, start + 4);
                        } else {
                            start = Math.max(1, end - 4);
                        }
                    }

                    for (let i = start; i <= end; i++) {
                        pages.push(i);
                    }
                    return pages;
                });

                // 方法
                const showAlert = (message, type = 'info') => {
                    alert.value = { show: true, message, type };
                    setTimeout(() => {
                        alert.value.show = false;
                    }, 5000);
                };

                const setLoading = (value) => {
                    loading.value = value;
                };

                const apiCall = async (endpoint, options = {}) => {
                    const url = `${endpoint}`;
                    const headers = {
                        'Content-Type': 'application/json',
                        ...options.headers
                    };

                    if (localStorage.getItem('accessToken')) {
                        headers['Authorization'] = `Bearer ${localStorage.getItem('accessToken')}`;
                    }

                    const response = await fetch(url, {
                        ...options,
                        headers
                    });

                    if (response.status === 401) {
                        logout();
                        throw new Error('认证失败,请重新登录'); }
                    if (response.status === 400) {
                        const error = await response.json();
                        showAlert(error.message, 'danger');
                        throw new Error(error.message);
                    }

                    // 添加50ms延迟,防止触发服务端频率限制
                    await new Promise(resolve => setTimeout(resolve, 50));

                    return response;
                };

                const loginWithGitHub = async () => {
                    try {
                        setLoading(true);
                        const response = await fetch('./auth/login/github');
                        const data = await response.json();
                        window.location.href = data.auth_url;
                    } catch (error) {
                        showAlert('获取GitHub认证URL失败', 'danger');
                    } finally {
                        setLoading(false);
                    }
                };

                const handleGitHubCallback = async (code) => {
                    try {
                        setLoading(true);
                        const response = await fetch(`./auth/callback/github?code=${code}`);
                        if (response.ok) {
                            const data = await response.json();
                            console.log(data);
                            localStorage.setItem('accessToken', data.access_token);
                            localStorage.setItem('currentUser', JSON.stringify(data.user_info));
                            currentUser.value = data.user_info;
                            isLoggedIn.value = true;
                        } else {
                            const error = await response.json();
                            showAlert(`登录失败: ${error.detail}`, 'danger');
                        }
                        window.location.href = '/';
                    } catch (error) {
                        showAlert('登录过程中发生错误', 'danger');
                        console.error(error);
                    } finally {
                        setLoading(false);
                    }
                };

                const logout = () => {
                    localStorage.removeItem('accessToken');
                    localStorage.removeItem('currentUser');
                    currentUser.value = {};
                    isLoggedIn.value = false;
                    models.value = [];
                    tasks.value = [];
                };

                const loadModels = async () => {
                    try {
                        const response = await apiCall('./api/v1/model/list');
                        if (response.ok) {
                            const data = await response.json();
                            console.log(data);
                            models.value = data.models || [];

                            // 如果有模型,自动选择第一个模型的信息
                            if (models.value.length > 0) {
                                const firstModel = models.value[0];
                                taskForm.value.task = firstModel.task;
                                taskForm.value.model_cls = firstModel.model_cls;
                                taskForm.value.stage = firstModel.stage;
                            }
                        } else {
                            showAlert('加载模型列表失败', 'danger');
                        }
                    } catch (error) {
                        showAlert(`加载模型失败: ${error.message}`, 'danger');
                    }
                };

                const handleImageUpload = (event) => {
                    const file = event.target.files[0];
                    taskForm.value.imageFile = file;

                    // 创建图片预览
                    if (file) {
                        const reader = new FileReader();
                        reader.onload = (e) => {
                            imagePreview.value = e.target.result;
                        };
                        reader.readAsDataURL(file);
                    } else {
                        imagePreview.value = null;
                    }
                };

                const handleAudioUpload = (event) => {
                    const file = event.target.files[0];
                    taskForm.value.audioFile = file;

                    // 创建音频预览
                    if (file) {
                        const reader = new FileReader();
                        reader.onload = (e) => {
                            audioPreview.value = e.target.result;
                        };
                        reader.readAsDataURL(file);
                    } else {
                        audioPreview.value = null;
                    }
                };

                const submitTask = async () => {
                    try {
                        setLoading(true);
                        submitting.value = true;

                        // 准备提交数据
                        var formData = {
                            task: taskForm.value.task,
                            model_cls: taskForm.value.model_cls,
                            stage: taskForm.value.stage,
                            prompt: taskForm.value.prompt,
                            seed: taskForm.value.seed
                        };
                        if (taskForm.value.model_cls.startsWith('wan2.1')) {
                            formData.negative_prompt = "镜头晃动,色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走"
                        }

                        // 如果是i2v任务且有图片文件,将图片转换为base64
                        if (taskForm.value.task === 'i2v' && taskForm.value.imageFile) {
                            const base64 = await fileToBase64(taskForm.value.imageFile);
                            formData.input_image = {
                                type: 'base64',
                                data: base64
                            };
                        }

                        // 如果是音频模型且有音频文件,将音频转换为base64
                        if (isAudioModel.value && taskForm.value.audioFile) {
                            const base64 = await fileToBase64(taskForm.value.audioFile);
                            formData.input_audio = {
                                type: 'base64',
                                data: base64
                            };
                            formData.negative_prompt = "色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走"
                        }

                        const response = await apiCall('./api/v1/task/submit', {
                            method: 'POST',
                            body: JSON.stringify(formData)
                        });

                        if (response.ok) {
                            const result = await response.json();
                            showAlert(`任务提交成功!任务ID: ${result.task_id}`, 'success');
                            await refreshTasks();
                        } else {
                            const error = await response.json();
                            showAlert(`任务提交失败: ${error.message}`, 'danger');
                        }
                    } catch (error) {
                        showAlert(`提交任务失败: ${error.message}`, 'danger');
                    } finally {
                        submitting.value = false;
                        setLoading(false);
                    }
                };

                const fileToBase64 = (file) => {
                    return new Promise((resolve, reject) => {
                        const reader = new FileReader();
                        reader.readAsDataURL(file);
                        reader.onload = () => {
                            // 移除data:image/xxx;base64,前缀,只保留base64部分
                            const base64 = reader.result.split(',')[1];
                            resolve(base64);
                        };
                        reader.onerror = error => reject(error);
                    });
                };

                const formatTime = (timestamp) => {
                    if (!timestamp) return '';
                    // 将浮点时间戳转换为毫秒(JavaScript Date 构造函数需要毫秒)
                    const date = new Date(timestamp * 1000);
                    return date.toLocaleString('zh-CN');
                };

                const refreshTasks = async () => {
                    try {
                        const params = new URLSearchParams({
                            page: currentPage.value.toString(),
                            page_size: pageSize.value.toString()
                        });

                        if (statusFilter.value !== 'ALL') {
                            params.append('status', statusFilter.value);
                        }

                        const response = await apiCall(`./api/v1/task/list?${params.toString()}`);
                        if (response.ok) {
                            const data = await response.json();
                            console.log(data);
                            tasks.value = data.tasks || [];
                            pagination.value = data.pagination || null;
                        } else {
                            showAlert('刷新任务列表失败', 'danger');
                        }
                    } catch (error) {
                        showAlert(`刷新任务列表失败: ${error.message}`, 'danger');
                    }
                };

                const changePage = (page) => {
                    if (page < 1 || (pagination.value && page > pagination.value.total_pages)) {
                        return;
                    }
                    currentPage.value = page;
                    refreshTasks();
                };

                const changePageSize = () => {
                    currentPage.value = 1; // 重置到第一页
                    refreshTasks();
                };

                const getStatusBadgeClass = (status) => {
                    const statusMap = {
                        'SUCCEED': 'bg-success',
                        'FAILED': 'bg-danger',
                        'RUNNING': 'bg-warning',
                        'PENDING': 'bg-secondary',
                        'CREATED': 'bg-secondary'
                    };
                    return statusMap[status] || 'bg-secondary';
                };

                const toggleTaskDetail = (taskId) => {
                    if (expandedTasks.value.includes(taskId)) {
                        expandedTasks.value = expandedTasks.value.filter(id => id !== taskId);
                    } else {
                        expandedTasks.value.push(taskId);
                    }
                };

                const downloadSingleResult = async (taskId, key, outputPath) => {
                    try {
                        setLoading(true);
                        const response = await apiCall(`./api/v1/task/result?task_id=${taskId}&name=${key}`);
                        if (response.ok) {
                            const blob = await response.blob();
                            const url = window.URL.createObjectURL(blob);
                            const a = document.createElement('a');
                            a.href = url;
                            a.download = `${outputPath}`;
                            document.body.appendChild(a);
                            a.click();
                            document.body.removeChild(a);
                            window.URL.revokeObjectURL(url);
                        } else {
                            showAlert('获取结果失败', 'danger');
                        }
                    } catch (error) {
                        showAlert(`下载结果失败: ${error.message}`, 'danger');
                    } finally {
                        setLoading(false);
                    }
                };

                const viewSingleResult = async (taskId, key, outputPath) => {
                    try {
                        setLoading(true);
                        const response = await apiCall(`./api/v1/task/result?task_id=${taskId}&name=${key}`);
                        if (response.ok) {
                            const blob = await response.blob();
                            const videoBlob = new Blob([blob], { type: 'video/mp4' });
                            const url = window.URL.createObjectURL(videoBlob);
                            window.open(url, '_blank');
                        } else {
                            showAlert('获取结果失败', 'danger');
                        }
                    } catch (error) {
                        showAlert(`查看结果失败: ${error.message}`, 'danger');
                    } finally {
                        setLoading(false);
                    }
                };

                const cancelTask = async (taskId) => {
                    try {
                        const response = await apiCall(`./api/v1/task/cancel?task_id=${taskId}`);
                        if (response.ok) {
                            showAlert('任务取消成功', 'success');
                            await refreshTasks();
                        } else {
                            const error = await response.json();
                            showAlert(`取消任务失败: ${error.message}`, 'danger');
                        }
                    } catch (error) {
                        showAlert(`取消任务失败: ${error.message}`, 'danger');
                    }
                };

                const resumeTask = async (taskId) => {
                    try {
                        const response = await apiCall(`./api/v1/task/resume?task_id=${taskId}`);
                        if (response.ok) {
                            showAlert('任务重试成功', 'success');
                            await refreshTasks();
                        } else {
                            const error = await response.json();
                            showAlert(`重试任务失败: ${error.message}`, 'danger');
                        }
                    } catch (error) {
                        showAlert(`重试任务失败: ${error.message}`, 'danger');
                    }
                };

                const initModelAndTasks = async () => {
                    await loadModels();
                    await refreshTasks();
                };

                // 监听器
                watch(() => taskForm.value.task, () => {
                    // 当任务类型改变时,清空模型类和推理模式
                    taskForm.value.model_cls = '';
                    taskForm.value.stage = '';

                    // 如果当前任务类型有对应的模型,自动选择第一个
                    const availableModels = models.value.filter(m => m.task === taskForm.value.task);
                    if (availableModels.length > 0) {
                        const firstModel = availableModels[0];
                        taskForm.value.model_cls = firstModel.model_cls;
                        taskForm.value.stage = firstModel.stage;
                    }

                    // 清空图片预览
                    imagePreview.value = null;
                    taskForm.value.file = null;
                });

                watch(() => taskForm.value.model_cls, () => {
                    // 当模型类改变时,清空推理模式
                    taskForm.value.stage = '';

                    // 如果当前模型类有对应的推理模式,自动选择第一个
                    const availableStages = models.value
                        .filter(m => m.task === taskForm.value.task && m.model_cls === taskForm.value.model_cls)
                        .map(m => m.stage);
                    if (availableStages.length > 0) {
                        taskForm.value.stage = availableStages[0];
                    }
                });

                // 生命周期
                onMounted(() => {
                    // 检查是否已登录
                    const savedToken = localStorage.getItem('accessToken');
                    const savedUser = localStorage.getItem('currentUser');

                    if (savedToken && savedUser) {
                        currentUser.value = JSON.parse(savedUser);
                        isLoggedIn.value = true;
                        initModelAndTasks();
                    } else {
                        // 检查是否是GitHub回调
                        const urlParams = new URLSearchParams(window.location.search);
                        const code = urlParams.get('code');
                        if (code) {
                            handleGitHubCallback(code);
                        }
                    }
                });

                return {
                    isLoggedIn,
                    loading,
                    submitting,
                    currentUser,
                    models,
                    tasks,
                    alert,
                    taskForm,
                    imagePreview,
                    availableTaskTypes,
                    availableModelClasses,
                    availableStages,
                    expandedTasks,
                    pagination,
                    currentPage,
                    pageSize,
                    statusFilter,
                    visiblePages,
                    isAudioModel,
                    showAlert,
                    loginWithGitHub,
                    logout,
                    loadModels,
                    handleImageUpload,
                    handleAudioUpload,
                    submitTask,
                    refreshTasks,
                    changePage,
                    changePageSize,
                    getStatusBadgeClass,
                    formatTime,
                    toggleTaskDetail,
                    downloadSingleResult,
                    viewSingleResult,
                    cancelTask,
                    resumeTask
                };
            }
        }).mount('#app');
    </script>
</body>
</html>