du
2025-04-16 740f9098c6baffc95ee2d1c0e029bb092e1f48d0
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
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
<template>
  <div class="pages">
    <div class="template-top">
      <div class="top-left">
        <div style="font-size: 16px" class="top-icon">
          <ArrowLeft @click="goBack" style="width: 1em; height: 1em; cursor: pointer" />
        </div>
        <span class="back-text" @click="goBack">{{ t('courseCenter.goBack') }}</span>
        <el-input
          v-if="isEditing"
          ref="inputRef"
          v-model="editName"
          style="width: 300px"
          size="small"
          :placeholder="t('common.inputText') + t('courseCenter.courseName')"
          @blur="saveEdit"
          @keydown.enter="saveEdit"
        />
 
        <!-- 如果不在编辑,显示文本 -->
        <div
          v-else
          @click="toggleEdit"
          :prefix-icon="Edit"
          style="display: flex; align-items: center; cursor: pointer"
        >
          <span>{{ courseInfo.name }}</span>
        </div>
        <span>{{ t('courseCenter.estimatedDuration') }}: {{ videoDuration }}</span>
        <span>{{ t('courseCenter.wordCount') }}:{{ videoText }}</span>
      </div>
      <div class="top-right">
        <span v-if="saveTime">{{ saveTime }} {{ t('courseCenter.saved') }}</span>
        <el-button size="small" @click="saveSubmit('save')">{{ t('common.save') }}</el-button>
        <el-button type="primary" size="small" @click="saveSubmit('')">{{
          t('courseCenter.composeViode')
        }}</el-button>
      </div>
    </div>
    <div class="template-main">
      <div class="template-box template-left">
        <div class="page">
          <div
            >{{ t('courseCenter.page') }}:({{ PPTArr ? PPTArr.length : 1 }}){{
              t('courseCenter.pageTitle')
            }}</div
          >
          <div class="line"></div>
          <el-upload
            ref="uploadRef"
            class="upload-demo"
            accept=".pptx,.pdf"
            :limit="1"
            :headers="headers"
            :action="`${config.base_url}/infra/file/upload`"
            :on-exceed="handleExceed"
            :on-change="handleChange"
            :on-success="handleSuccess"
            :on-error="handleError"
            :show-file-list="false"
          >
            <template #trigger>
              <el-button type="primary" :icon="Upload">
                {{ t('courseCenter.upload') }} PPT/PDF
              </el-button>
            </template>
          </el-upload>
        </div>
        <!-- 左侧场景页面缩略图 -->
        <div v-if="showLeftList" style="height: calc(100% - 86px)">
          <div class="image-list">
            <draggable
              :list="PPTArr"
              :disabled="false"
              item-key="name"
              ghost-class="ghost"
              chosen-class="chosen"
              @start="state.dragging = true"
              @end="state.dragging = false"
              animation="300"
            >
              <template #item="{ element, index }">
                <div class="mt-2 w-100%">
                  <div class="list" @click="choosePPt(element)">
                    <!-- 背景图片(必显示) -->
                    <el-image
                      class="background"
                      :src="element.pictureUrl"
                      fit="contain"
                      :style="{
                        width: thumViewSize.width + 'px',
                        height: thumViewSize.height + 'px',
                        top: '0px',
                        left: '0px'
                      }"
                    />
                    <!-- 画中画(有则显示) -->
                    <el-image
                      v-if="element.innerPicture?.src"
                      class="ppt-bg"
                      :style="{
                        width: element.innerPicture.width * (thumViewSize.width / 800) + 'px',
                        height: element.innerPicture.height * (thumViewSize.height / 450) + 'px',
                        top: element.innerPicture.top * (thumViewSize.width / 800) + 'px',
                        left: element.innerPicture.marginLeft * (thumViewSize.height / 450) + 'px',
                        borderColor: element.isActive ? '#0683ee' : ''
                      }"
                      :src="element.innerPicture.src"
                      fit="contain"
                    />
                    <!-- 数字人(有则显示) -->
                    <el-image
                      v-if="element.showDigitalHuman"
                      class="host"
                      :style="{
                        width: PPTpositon.w * (thumViewSize.width / 800) + 'px',
                        height: PPTpositon.h * (thumViewSize.height / 450) + 'px',
                        top: PPTpositon.y * (thumViewSize.width / 800) + 'px',
                        left: PPTpositon.x * (thumViewSize.height / 450) + 'px'
                      }"
                      :src="selectHost?.pictureUrl"
                    />
                    <div class="list-index" :style="element.isActive ? 'background: #409eff' : ''">
                      {{ index + 1 }}
                    </div>
                    <div class="icon-content">
                      <el-icon
                        size="20"
                        color="#ffffff"
                        style="margin-right: 5px"
                        @click.stop="copyDocument(element, index)"
                      >
                        <CopyDocument />
                      </el-icon>
                      <el-icon
                        size="20"
                        color="#ffffff"
                        style="margin-right: 5px"
                        @click.stop="deleteDocument(element)"
                      >
                        <Delete />
                      </el-icon>
                      <el-checkbox v-model="element.isChecked" size="large" />
                    </div>
                  </div>
                </div>
              </template>
            </draggable>
          </div>
          <div class="page-btn">
            <el-button type="primary" size="small" :icon="Delete" @click.stop="deleteMore" />
          </div>
        </div>
        <div class="left-upload-setting" v-if="!showLeftList">
          <!-- <img src="" alt=""> -->
          <div>ppt{{ t('courseCenter.analyzing') }}...</div>
          <el-progress :percentage="percentagePPT" />
          <el-button @click="cancelAnalyze">{{ t('common.cancel') }}</el-button>
          <div>{{ t('courseCenter.analyzingTitle') }}</div>
        </div>
      </div>
      <!-- 中间主画布 -->
      <div class="template-box template-middle">
        <div class="middle-top">
          <el-select v-model="courseInfo.aspect" placeholder="Select" style="width: 140px">
            <el-option
              v-for="item in options"
              :key="item.label"
              :label="item.label"
              :value="item.label"
            />
          </el-select>
        </div>
        <div class="main-box relative">
          <div class="list">
            <div
              class="main-image-box"
              :style="{ width: viewSize.width + 'px', height: viewSize.height + 'px',position: 'relative' }"
            >
              <!-- 背景(必显示) -->
              <el-image
                v-show="selectPPT.pictureUrl"
                class="background1"
                :src="selectPPT.pictureUrl"
                style="z-index: 2"
              />
 
              <!-- 画中画 -->
              <Vue3DraggableResizable
                v-if="selectPPT.innerPicture && selectPPT.innerPicture.src"
                :parent="true"
                :initW="selectPPT.innerPicture.width"
                :initH="selectPPT.innerPicture.height"
                v-model:x="selectPPT.innerPicture.marginLeft"
                v-model:y="selectPPT.innerPicture.top"
                v-model:w="selectPPT.innerPicture.width"
                v-model:h="selectPPT.innerPicture.height"
                v-model:active="selectPPT.innerPicture.active"
                :draggable="true"
                :resizable="true"
                @activated="print('PPT activated')"
                @deactivated="print('PPT deactivated')"
                @drag-start="print('PPT drag-start')"
                @resize-start="print('PPT resize-start')"
                @dragging="print('PPT dragging')"
                @resizing="print('PPT resizing')"
                @drag-end="print('PPT drag-end')"
                @resize-end="print('PPT resize-end')"
                style="z-index: 3"
              >
                <el-image class="ppt-bg" :src="selectPPT.innerPicture.src"  />
                <el-icon
                  v-if="PPTpositon.active"
                  size="20"
                  color="#409eff"
                  style="position: absolute; top: 5px; right: 5px; z-index: 4"
                  @click.stop="deleteInnerPicture"
                >
                  <Delete />
                </el-icon>
              </Vue3DraggableResizable>
                <Vue3DraggableResizable
                  v-if="selectPPT.showDigitalHuman"
                  :parent="false"
                  :lockAspectRatio="true"
                  :minW="350"
                  :initW="PPTpositon.w"
                  :initH="PPTpositon.h"
                  @drag-move="onDragMove"
                  v-model:x="PPTpositon.x"
                  v-model:y="PPTpositon.y"
                  v-model:w="PPTpositon.w"
                  v-model:h="PPTpositon.h"
                  v-model:active="PPTpositon.active"
                  :draggable="true"
                  :resizable="true"
                  @activated="print('activated')"
                  @deactivated="print('deactivated')"
                  @drag-start="print('drag-start')"
                  @resize-start="print('resize-start')"
                  @dragging="print('dragging')"
                  @resizing="print('resizing')"
                  @drag-end="print('drag-end')"
                  @resize-end="print('resize-end')"
                  style="z-index: 1"
                >
                  <!--                {{PPTpositon.w}}{{PPTpositon.h}}-->
                  <el-image
                    class="minddle-host-image"
                    :src="selectHost ? selectHost.pictureUrl : ''"
                  />
 
                  <el-icon
                    v-if="PPTpositon.active"
                    size="20"
                    color="#409eff"
                    style="position: absolute; top: 5px; right: 5px; z-index: 4"
                    @click.stop="deleteDigitalHuman"
                  >
                    <Delete />
                  </el-icon>
                </Vue3DraggableResizable>
            </div>
          </div>
          <el-card
            v-show="voiceData.show"
            class="voice-card absolute right-10px bottom-10px w-300px"
          >
            <div class="flex flex-col">
              <div class="flex flex-col p-10px border-b-solid border-b-1px border-gray-200">
                <div class="flex items-baseline">
                  <span class="text-16px">{{ t('courseCenter.speedSpeech') }}</span>
                  <el-button
                    class="ml-10px"
                    type="info"
                    link
                    @click="voiceData.speechRate = voiceData.defaultSpeechRate"
                  >
                    {{ t('courseCenter.restoreDefault') }}
                  </el-button>
                </div>
                <el-slider
                  class="speech-slider px-10px mb-20px"
                  v-model="voiceData.speechRate"
                  :step="0.05"
                  :min="0.6"
                  :max="1.5"
                  :marks="voiceData.marks"
                  :show-spots="false"
                />
              </div>
              <div class="flex flex-col p-10px">
                <div class="flex items-baseline">
                  <span class="text-16px">{{ t('courseCenter.enlargeVolume') }}</span>
                  <el-button
                    class="ml-10px"
                    type="info"
                    link
                    @click="voiceData.volume = voiceData.defaultVolume"
                  >
                    {{ t('courseCenter.restoreDefault') }}
                  </el-button>
                </div>
                <el-slider
                  class="speech-slider px-10px mb-20px"
                  v-model="voiceData.volume"
                  :step="0.1"
                  :min="1"
                  :max="2"
                  :marks="voiceData.marks2"
                  :show-spots="false"
                />
              </div>
            </div>
          </el-card>
        </div>
        <div class="voice-main">
          <el-text class="mx-1" type="primary" size="small">{{
            t('courseCenter.oralBroadcastingContent')
          }}</el-text>
<!--          <div class="voice-item">-->
<!--            <span-->
<!--              :class="selectPPT.driverType == item.itemValue ? 'active-item' : ''"-->
<!--              v-for="(item, index) in driveType"-->
<!--              :key="index"-->
<!--              @click="driveTypeChange(item)"-->
<!--              >{{ item.name }}</span-->
<!--            >-->
<!--          </div>-->
          <div class="media-box">
            <el-button type="primary" :icon="Mic" size="small" @click="openSelect">{{
              selectPPT.selectAudio ? selectPPT.selectAudio.name : t('courseCenter.notSelect')
            }}</el-button>
            <el-button
              type="success"
              :icon="Headset"
              size="small"
              @click="voiceData.show = !voiceData.show"
            />
          </div>
        </div>
        <div v-if="selectPPT.driverType == 1" style="position: relative">
          <div class="middle-textarea">
            <!-- <el-input
              v-model="selectPPT.pptRemark"
              ref="textareaRef"
              @select="handlePptRemarkSelection"
              :rows="5"
              type="textarea"
              :placeholder="t('common.inputText') + t('courseCenter.oralBroadcastingContent')"
              show-word-limit
              maxlength="1200"
              resize="none"
            /> -->
            <Editor style="height: 196px; overflow-y: hidden;" v-model="selectPPT.pptRemark" :defaultConfig="editorConfig" mode="simple" @on-created="handleCreated" />
          </div>
          <div class="tool-box">
            <div class="tool-btn">
              <!-- 新增智能讲稿按钮 -->
<!--              <el-button type="primary" size="small" @click="openScriptRewriter">{{-->
<!--                t('courseCenter.intelligentSpeech')-->
<!--              }}</el-button>-->
<!--              <el-button type="primary" @click="openReplaceDialog" size="small">{{-->
<!--                t('courseCenter.batchReplace')-->
<!--              }}</el-button>-->
<!--              <el-button type="primary" size="small" @click="handleWord">{{-->
<!--                t('courseCenter.polyphonicCharacters')-->
<!--              }}</el-button>-->
<!--              <el-dropdown placement="bottom" @command="handleNumber" style="margin: 0 12px;">-->
<!--                  <el-button type="primary" size="small">{{ t('courseCenter.number') }}</el-button>-->
<!--                  <template #dropdown>-->
<!--                      <el-dropdown-menu>-->
<!--                          <el-dropdown-item command="读数字">读数字</el-dropdown-item>-->
<!--                          <el-dropdown-item command="读数值">读数值</el-dropdown-item>-->
<!--                      </el-dropdown-menu>-->
<!--                  </template>-->
<!--              </el-dropdown>-->
<!--              <el-dropdown placement="bottom" @command="handleBreak">-->
<!--                  <el-button type="primary" size="small">{{ t('courseCenter.pause') }}</el-button>-->
<!--                  <template #dropdown>-->
<!--                      <el-dropdown-menu>-->
<!--                          <el-dropdown-item command="0.5秒">0.5秒</el-dropdown-item>-->
<!--                          <el-dropdown-item command="1秒">1秒</el-dropdown-item>-->
<!--                          <el-dropdown-item command="2秒">2秒</el-dropdown-item>-->
<!--                      </el-dropdown-menu>-->
<!--                  </template>-->
<!--              </el-dropdown>-->
              <div></div>
            </div>
            <el-button type="primary" :icon="VideoPlay" size="small" @click="createAudio">{{
              t('courseCenter.tryListening')
            }}</el-button>
          </div>
          <div class="audio-play" v-if="showAudioPlay">
            <div>{{ t('courseCenter.listeningTrial') }}...</div>
            <el-button @click="pauseAudio">{{ t('courseCenter.cancelTrialListening') }}</el-button>
          </div>
          <div class="audio-play" v-if="showAudioPlay1">
            <div>生成中...</div>
          </div>
        </div>
        <div v-else class="audio-upload" style="position: relative">
          <div class="audio-play" v-if="startAudioPlay">
            <div>{{ t('courseCenter.playing') }}...</div>
            <el-button @click="cancelAudio">{{ t('courseCenter.cancelPlayback') }}</el-button>
          </div>
          <el-tooltip effect="dark" :content="t('courseCenter.toolTip')" placement="top">
            <el-upload
              v-model:file-list="selectPPT.fileList"
              ref="uploadAudioRef"
              class="upload-demo"
              accept=".wav,.mp3"
              :limit="1"
              :headers="headers"
              :action="`${config.base_url}/infra/file/upload`"
              :on-success="handleAudioSuccess"
              :on-change="handleAudioChange"
              :on-preview="audioPlay"
              :on-exceed="audioExceed"
              :show-file-list="true"
            >
              <template #trigger>
                <el-button type="primary" :icon="Upload">{{
                  t('courseCenter.uploadAudio')
                }}</el-button>
              </template>
            </el-upload>
          </el-tooltip>
        </div>
      </div>
      <div class="template-box template-right" v-if="showDigitalHumanTool">
        <div class="tabs-1">
          <div
            class="tabs-item"
            v-for="item in tabs1"
            :key="item.itemValue"
            @click="tabs1Click(item)"
          >
            <div>{{ item.itemName }}</div>
            <span v-if="tabs1ActiveNum == item.itemValue"></span>
          </div>
        </div>
        <div class="tabs-2">
          <div
            :class="{ 'tabs-active': tabs2ActiveNum == item.itemValue }"
            v-for="item in tabs2"
            @click="tabs2Click(item)"
            :key="item.itemValue"
          >
            {{ item.itemName }}
          </div>
          <div
            :class="{ 'tabs-active': tabs3ActiveNum == item.itemValue }"
            v-for="item in tabs3"
            @click="tabs3Click(item)"
            :key="item.itemValue"
          >
            {{ item.itemName }}
          </div>
        </div>
        <div class="host-list">
          <div
            class="host-item"
            v-for="(item, index) in hostList"
            :key="index"
            @click="chooseHost(item)"
          >
            <div class="background"></div>
            <div class="host-name">{{ item.name }}</div>
            <el-image
              class="ppt-bg"
              :src="item.pictureUrl"
              :style="{
                width: '100%',
                height: '100%',
                objectFit: 'contain',
                maxWidth: '100%',
                maxHeight: '100%'
              }"
            />
          </div>
          <Pagination
            small="true"
            :total="total"
            v-model:page="queryParams.pageNo"
            v-model:limit="queryParams.pageSize"
            @pagination="getList"
          />
        </div>
      </div>
      <!-- 模板设置 -->
      <div class="template-box template-right" v-if="showTemplateTool">
        <div class="tabs-2"> </div>
        <div class="template-list">
          <div
            class="template-item"
            v-for="(template, index) in templates"
            :key="index"
            @click="chooseTemplate(template)"
          >
            <div class="list-index" :style="template.isActive ? 'background: #409eff' : ''">
              {{ index + 1 }}
            </div>
            <el-image class="background" :src="template.previewImage" fit="contain" />
          </div>
        </div>
        <div class="apply-all">
          <el-checkbox v-model="applyAllTemplate" :label="t('courseCenter.uploadAudio')" />
        </div>
      </div>
      <!-- 背景设置 -->
      <div class="template-box template-right" v-if="showHeadImageTool">
        <div class="image-setting">
          <!--          上传图片成功后,将当前场景的背景修改为上传的图片url-->
 
          <div>{{ t('courseCenter.uploadImage') }}</div>
          <UploadImg v-model="selectPPT.pictureUrl" :limit="1" />
        </div>
      </div>
      <!-- 画中画设置 -->
      <div class="template-box template-right" v-if="showInnerPictureTool">
        <div class="image-setting">
          <!--          上传图片成功后,将当前场景的画中画修改为上传的图片url-->
 
          <div>{{ t('courseCenter.uploadImage') }}</div>
          <UploadImg v-model="selectPPT.innerPicture.src" :limit="1" />
        </div>
      </div>
      <div class="template-box template-right" v-if="showImageSet">
        <div class="image-setting">
          <div>{{ t('courseCenter.imageProperties') }}</div>
          <div class="img-setting">
            <span class="setting-label">{{ t('courseCenter.position') }}</span>
            X <el-input v-model="PPTpositon.x" type="number" :min="20" :max="460" /> Y
            <el-input v-model="PPTpositon.y" type="number" :min="20" :max="180" />
          </div>
          <div class="img-setting">
            <span class="setting-label">{{ t('courseCenter.hierarchicalStructure') }}</span>
            <el-input v-model="PPTpositon.depth" type="number" :min="0" :max="999" />
          </div>
          <div class="img-setting">
            <span class="setting-label">{{ t('courseCenter.size') }}</span>
            W <el-input v-model="PPTpositon.w" type="number" :min="20" :max="760" /> H
            <el-input v-model="PPTpositon.h" type="number" :min="20" :max="360" />
          </div>
        </div>
      </div>
      <div class="template-box template-tool">
        <div
          v-for="(item, index) in rightTools"
          :key="index"
          class="tool-item"
          @click="handleChangeTool(item)"
        >
          <img :src="item.isActive ? item.activeUrl : item.url" alt="" />
          <div class="tool-name" :style="item.isActive ? 'color:#0088fe' : ''">
            {{ item.name }}
          </div>
        </div>
      </div>
    </div>
    <uploadExplain ref="uploadExplainRef" @success="uploadSubmit" />
    <AudioSelect ref="audioSelect" @success="selectAudio" />
    <mergeWarningDialog ref="warningDialog" />
    <ReplaceDialog ref="replaceDialog" :ppt-arr="PPTArr" @submit="handleReplacement" />
    <!-- 添加智能讲稿组件 -->
    <Rewriter
      ref="rewriterRef"
      :image-url="currentImageUrl"
      :title="''"
      :content="selectPPT.pptRemark"
      @confirm="handleRewritten"
    />
     <!-- 多音字 -->
     <el-dialog v-model="dialogVisible" title="点击需要纠正的多音字,选择正确的发音" width="500" @close="dialogVisible = false">
      <el-tag v-for="(item, index) in textList" :key="index" type="primary" effect="dark" style="margin-right: 10px;cursor: pointer;" @click="handleTag(item)">
          {{ item }}
      </el-tag>
    </el-dialog>
  </div>
</template>
<script lang="ts" setup>
import { ref, reactive, onMounted } from 'vue'
import draggable from 'vuedraggable'
 
import Vue3DraggableResizable from 'vue3-draggable-resizable'
import 'vue3-draggable-resizable/dist/Vue3DraggableResizable.css'
import { config } from '@/config/axios/config'
import { genFileId } from 'element-plus'
import type { UploadRawFile } from 'element-plus'
import { getAccessToken, getTenantId } from '@/utils/auth'
import * as pptTemplateApi from '@/api/pptTemplate'
import uploadExplain from './uploadExplain.vue'
import AudioSelect from './audioSelect.vue'
import mergeWarningDialog from './mergeWarningDialog.vue'
import ReplaceDialog from './replaceDialog.vue' // 引入批量替换组件
import Rewriter from './rewriter.vue'
import template from '@/assets/imgs/template.png'
import templateActive from '@/assets/imgs/template-active.png'
import user from '@/assets/imgs/user.png'
import userActive from '@/assets/imgs/user-active.png'
import bg from '@/assets/imgs/bg.png'
import bgActive from '@/assets/imgs/bg-active.png'
import innerPicture from '@/assets/imgs/inner-picture.png'
import innerPictureActive from '@/assets/imgs/inner-picture-active.png'
import { TemplateApi } from '@/api/digitalcourse/template'
const { t } = useI18n() // 国际化
//用户信息
import { useUserStore } from '@/store/modules/user'
import {
  Edit,
  ArrowLeft,
  Upload,
  Mic,
  Headset,
  Delete,
  QuestionFilled,
  VideoPlay,
  CopyDocument
} from '@element-plus/icons-vue'
import { generateUUID } from '@/utils'
import { useRoute, useRouter } from 'vue-router'
import { cloneDeep } from 'lodash-es'
// 富文本编辑器
import '@wangeditor/editor/dist/css/style.css' // 引入 css
import { Editor } from '@wangeditor/editor-for-vue'
import { Boot } from '@wangeditor/editor'
import TitleBlack from './title-black/index.js';  // 这个路径根据你的配置来
Boot.registerModule(TitleBlack)
//多音字
import { polyphonic } from 'pinyin-pro';
//编辑器内容转换ssml
import { useEditorHtml } from '@/hooks/web/useEditorHtml';
import {coursesDelete} from "@/api/pptTemplate";
const editorHtml = useEditorHtml()
const router = useRouter() // 路由
const route = useRoute() //
//用户信息
const userStore = useUserStore()
const userId = computed(() => userStore.user.id)
const message = useMessage()
const isEditing = ref(false)
const inputRef = ref(null)
// 切换到编辑模式
const toggleEdit = () => {
  isEditing.value = true
  editName.value = courseInfo.value.name
  nextTick(() => {
    inputRef.value.focus()
  })
};
const onDragMove = (evt, data) => {
  console.log(evt)
  console.log(data)
 
  // 限制坐标
  if (data.x < -100) {
    data.x = -100; // 可以设置最小坐标为 -100
  }
  if (data.y < -100) {
    data.y = -100; // 可以设置最小坐标为 -100
  }
};
// 保存编辑后的名称
const saveEdit = () => {
  isEditing.value = false
  courseInfo.value.name = editName.value
}
let humanId = 0
 
//课程基本信息
const courseInfo = ref({
  id: 0,
  accountId: userId.value,
  aspect: '16:9',
  name: '未命名草稿',
  duration: 0,
  status: 0,
  pageMode: 2,//ppt课件视频
  matting: 1,
  width: 1920,
  height: 1080
})
// 当比例改变时更新宽度和高度
watch(
  () => courseInfo.value.aspect,
  (newAspect) => {
    courseInfo.value.width = newAspect === '16:9' ? 1920 : 1080
    courseInfo.value.height = newAspect === '16:9' ? 1080 : 1920
  }
)
 
const editName = ref(courseInfo.value.name)
const viewSize = reactive({
  width: 800,
  height: (800 * 9) / 16
})
const thumViewSize = reactive({
  width: 152,
  height: (152 * 9) / 16
})
const digitalHumanSize = reactive({
  width: 640,
  height: 360
})
// 添加缩放比例计算
const scaleRatio = computed(() => ({
  width: courseInfo.value.width / viewSize.width, // 1920/800 = 2.4
  height: courseInfo.value.height / viewSize.height // 1080/450 = 2.4
}))
 
const PPTpositon = reactive({
  x: viewSize.width - digitalHumanSize.width,
  y: viewSize.height - digitalHumanSize.height,
  w: digitalHumanSize.width,
  h: digitalHumanSize.height,
  depth: 0,
  active: false
})
 
const componentsInfo = reactive({
  width: PPTpositon.w / 5,
  height: PPTpositon.h / 4,
  marginLeft: PPTpositon.x / 4,
  top: PPTpositon.y / 4.5,
  depth: PPTpositon.depth
})
//背景设置
const showHeadImageTool = ref(false)
//数字人设置
const showDigitalHumanTool = ref(false)
//模板设置
const showTemplateTool = ref(false)
//画中画设置
const showInnerPictureTool = ref(false)
//图片属性
const showImageSet = ref(false)
//是否将模板应用到所有页面
const applyAllTemplate = ref(false)
 
const xScale = viewSize.width / thumViewSize.width
// const yScale = viewSize.height / thumViewSize.height
//左侧ppt数字人位置
const leftWidth = computed(() => {
  return PPTpositon.w / xScale + 'px'
})
const leftHeight = computed(() => {
  return PPTpositon.h / xScale + 'px'
})
const leftTop = computed(() => {
  return PPTpositon.y / xScale + 'px'
})
const leftLeft = computed(() => {
  return PPTpositon.x / xScale + 'px'
})
const print = (val) => {
  console.log(val)
}
const state = reactive({
  dragging: false
})
 
//预设模板
const TEMPLATE_PRESETS = ref([])
const templates = ref([])
 
const selectTemplate = ref([])
 
//数字人tab
const tabs1 = [
  {
    itemName: t('courseCenter.model'),
    itemValue: '0'
  },
  {
    itemName: t('courseCenter.my'),
    itemValue: '1'
  }
]
const tabs1ActiveNum = ref('0')
const tabs2ActiveNum = ref('')
const tabs2 = [
  {
    itemName: t('courseCenter.all'),
    itemValue: ''
  },
  {
    itemName: t('courseCenter.man'),
    itemValue: '1'
  },
  {
    itemName: t('courseCenter.woman'),
    itemValue: '2'
  }
]
const tabs3ActiveNum = ref()
const tabs3 = [
  {
    itemName: t('courseCenter.standingPosture'),
    itemValue: '1'
  },
  {
    itemName: t('courseCenter.sittingPosture'),
    itemValue: '2'
  }
]
const tabs1Click = (item) => {
  tabs1ActiveNum.value = item.itemValue
  getList()
}
const tabs2Click = (item) => {
  tabs2ActiveNum.value = item.itemValue
  getList()
}
const tabs3Click = (item) => {
  tabs3ActiveNum.value = item.itemValue
  getList()
}
//驱动类型
const selectDriveType = ref({
  name: t('courseCenter.textDriven'),
  itemValue: 1,
  isActive: true
})
const driveType = reactive([
  {
    name: t('courseCenter.textDriven'),
    itemValue: 1,
    isActive: true
  },
  {
    name: t('courseCenter.soundDriven'),
    isActive: false,
    itemValue: 2
  }
])
const driveTypeChange = (item) => {
  selectPPT.value.driverType = item.itemValue
}
//右侧设置
const rightTools = reactive([
  {
    name: t('courseCenter.template'),
    url: template,
    activeUrl: templateActive,
    isActive: false
  },
  {
    name: t('courseCenter.digitalPeople'),
    url: user,
    activeUrl: userActive,
    isActive: false
  },
  {
    name: t('courseCenter.background'),
    url: bg,
    activeUrl: bgActive,
    isActive: false
  },
  {
    name: t('courseCenter.pictureInPicture'),
    url: innerPicture,
    activeUrl: innerPictureActive,
    isActive: false
  }
])
const handleChangeTool = (item) => {
  rightTools.forEach((child) => {
    if (child.name == item.name) {
      child.isActive = true
    } else {
      child.isActive = false
    }
  })
  if (item.name == t('courseCenter.background')) {
    showHeadImageTool.value = true
    showTemplateTool.value = false
    showDigitalHumanTool.value = false
    showInnerPictureTool.value = false
  } else if (item.name == t('courseCenter.digitalPeople')) {
    showHeadImageTool.value = false
    showTemplateTool.value = false
    showDigitalHumanTool.value = true
    showInnerPictureTool.value = false
  } else if (item.name == t('courseCenter.template')) {
    showHeadImageTool.value = false
    showTemplateTool.value = true
    showDigitalHumanTool.value = false
    showInnerPictureTool.value = false
  } else if (item.name == t('courseCenter.pictureInPicture')) {
    showHeadImageTool.value = false
    showTemplateTool.value = false
    showDigitalHumanTool.value = false
    showInnerPictureTool.value = true
  }
}
 
const PPTArr = ref()
//ppt解析进度
const percentagePPT = ref(0)
const showLeftList = ref(true)
 
const selectPPT = ref({
  pictureUrl: '',
  innerPicture: {
    //定义画中画对象,属性与数字人相同
    name: '画中画',
    src: '',
    cover: '',
    width: 0,
    height: 0,
    originWidth: 0,
    originHeight: 0,
    category: 1,
    depth: 1, //画中画1-100
    top: 0,
    marginLeft: 0,
    businessId: generateUUID(),
    entityType: 0,
    entityId: '0'
  },
  pptRemark: '',
  driverType: 1,
  uploadAudioUrl: '',
  fileList: [] as any,
  selectAudio: {
    id: '',
    code: '',
    name: ''
  },
  showDigitalHuman: true
}) //选择的PPT
const checked5 = ref(false)
const options = [
  {
    value: '1',
    label: '16:9'
  },
  {
    value: '2',
    label: '9:16'
  }
]
const uploadRef = ref()
const headers = {
  Accept: 'application/json, text/plain, */*',
  Authorization: 'Bearer ' + getAccessToken(),
  'tenant-id': getTenantId()
}
//上传文件对象
const uploadFileObj = reactive({
  filename: '',
  size: 0,
  url: '',
  md5: '16b4c5e61897159b11405883ebd6749c',
  courseId: 23388,
  docType: 1,
  status: 0,
  extInfo: '{"addMode":true,"docType":1,"pptNotes":true,"pptContent":false,"notesPolish":false}',
  resolveType: 1
})
//智能讲稿组件begin
//添加ref
const rewriterRef = ref()
// 计算当前要传入的图片URL
const currentImageUrl = computed(() => {
  if (selectPPT.value?.innerPicture?.src) {
    return selectPPT.value.innerPicture.src
  }
  return selectPPT.value?.pictureUrl || ''
})
// 打开智能讲稿弹窗
const openScriptRewriter = () => {
  if (!selectPPT.value?.pptRemark && !currentImageUrl.value) {
    message.warning('请先选中页面')
    return
  }
  rewriterRef.value.open()
}
// 处理讲稿内容
const handleRewritten = (rewrittenContent) => {
  selectPPT.value.pptRemark = rewrittenContent
}
//智能讲稿组件end
const handleExceed = (files) => {
  uploadRef.value!.clearFiles()
  const file = files[0] as UploadRawFile
  file.uid = genFileId()
  uploadRef.value!.handleStart(file)
}
 
// 上传相关的处理函数
const handleChange = (files) => {
  // 获取文件扩展名
  const extension = files.name.split('.').pop().toLowerCase()
 
  // 设置文档类型 1:ppt 2:pdf
  uploadFileObj.docType = extension === 'pdf' ? 2 : 1
  uploadFileObj.filename = files.name
  uploadFileObj.size = files.size
}
 
const uploadExplainRef = ref()
const handleSuccess = (rawFile) => {
  message.success('上传成功!')
  uploadFileObj.url = rawFile.data
  uploadExplainRef.value.open()
  uploadRef.value!.clearFiles()
}
 
const handleError = (err) => {
  message.error('上传失败,请重试')
  console.error('Upload error:', err)
}
 
//上传音频
const uploadAudioRef = ref()
const handleAudioSuccess = (rawFile) => {
  console.log('--------', rawFile)
  message.success('上传成功!')
  selectPPT.value.uploadAudioUrl = rawFile.data
  // uploadAudioRef.value!.clearFiles();
  selectPPT.value.fileList = [
    {
      name: uploadAudioFile.value,
      url: rawFile.data
    }
  ]
}
const uploadAudioFile = ref()
const handleAudioChange = (files) => {
  uploadAudioFile.value = files.name
}
//ppt上传说明回调
const uploadSubmit = (uploadForm) => {
  console.log('-------ppt上传说明', uploadForm)
  pptTemplateApi.createPPT(uploadFileObj).then((res) => {
    if (res) {
      //将课程名称修改为附件名称
      courseInfo.value.name = uploadFileObj.filename.split('.').slice(0, -1).join('.')
      editName.value = courseInfo.value.name
      schedulePPT(res)
    }
  })
}
//解析ppt
const schedulePPTTimer = ref()
const schedulePPT = (id) => {
  percentagePPT.value = 0
  if (schedulePPTTimer.value) {
    clearInterval(schedulePPTTimer.value)
  }
  showLeftList.value = false
  schedulePPTTimer.value = setInterval(() => {
    pptTemplateApi.getSchedule(id).then((res) => {
      if (res && typeof res == 'string') {
        const progress = Number(res)
        // 添加解析失败的判断
        if (progress < 0) {
          clearInterval(schedulePPTTimer.value)
          showLeftList.value = true
          message.error('PPT解析失败,请重试')
          return
        }
        percentagePPT.value = parseInt(`${progress * 100}`)
      } else if (res && res.length > 0) {
        console.log('courseInfo', courseInfo.value)
        res.forEach((item) => {
          item.isActive = false
          item.isChecked = false
          item.driverType = 1
          item.selectAudio = {}
          item.uploadAudioUrl = ''
          item.fileList = []
          item.businessId = generateUUID()
          item.width = courseInfo.value.width
          item.height = courseInfo.value.height
          let ppturl = item.pictureUrl
          //是否展示背景 如果展示背景,则背景等于模板背景,否则为空
          if (selectTemplate.value.showBackground) {
            item.pictureUrl = selectTemplate.value.bgImage
          } else {
            item.pictureUrl = ''
          }
          // 如果展示背景,并且展示ppt,则ppt放到画中画
          // console.log('selectTemplate',selectTemplate.value)
          // console.log('selectTemplate.value.pptW',selectTemplate.value.pptW
          // ,'selectTemplate.value.pptH',selectTemplate.value.pptH
          // )
          if (item.pictureUrl && selectTemplate.value.showPpt) {
            item.innerPicture = {
              name: '画中画',
              src: ppturl,
              cover: ppturl,
              width: selectTemplate.value.pptW,
              height: selectTemplate.value.pptH,
              originWidth: selectTemplate.value.pptW,
              originHeight: selectTemplate.value.pptH,
              category: 1,
              depth: 1,
              top: selectTemplate.value.pptY,
              marginLeft: selectTemplate.value.pptX,
              businessId: generateUUID(),
              entityType: 0,
              entityId: '0'
            }
          }
          //如果不展示背景,则ppt放到背景,画中画为空
          else if (!item.pictureUrl && selectTemplate.value.showPpt) {
            item.pictureUrl = ppturl
            item.innerPicture = {
              src: '',
              cover: '',
              width: 0,
              height: 0,
              top: 0,
              marginLeft: 0,
              category: 1
            }
          }
          // 初始化是否展示数字人
          item.showDigitalHuman = true
          // 数字人位置和尺寸也需要缩放
          console.log(selectTemplate.value)
          PPTpositon.w = selectTemplate.value.humanW
          PPTpositon.h = selectTemplate.value.humanH
          PPTpositon.x = selectTemplate.value.humanX
          PPTpositon.y = selectTemplate.value.humanY
        })
        PPTArr.value = res
        console.log('PPTArr.value', PPTArr.value)
        PPTArr.value[0].isActive = true
        selectPPT.value = PPTArr.value[0]
        console.log('selectPPT.value', selectPPT.value)
        showLeftList.value = true
        clearInterval(schedulePPTTimer.value)
        //轮询保存课程
        /**
         * 后端数据库压力过大,暂时停止定时保存
         */
        // saveInter()
      }
    })
  }, 2000)
}
//视频总字数、时长
const videoText = ref(0)
const videoDuration = ref('')
watch(
  () => PPTArr.value,
  (val) => {
    if (!val) {
      return
    }
    // 计算总字数 - 修改为去除SSML标签后再计算长度
    videoText.value = val.reduce((prev, curr) => {
      if (!curr.pptRemark) return prev;
 
      // 去除所有SSML标签,只保留文本内容
      const plainText = curr.pptRemark;
      return prev + plainText.length;
    }, 0)
    //视频时长换算
    let videoTime = (videoText.value / 200) * 60
    videoDuration.value = formateVideoTime(Math.ceil(videoTime))
  },
  { deep: true }
)
//视频时长换算
const formateVideoTime = (times: any) => {
  let hours: any = parseInt(`${times / 60 / 60}`) // 计算小时数
  let restMinutes: any = parseInt(`${(times / 60) % 60}`) // 分钟数取余,得到剩余分钟数
  let seconds: any = parseInt(`${times % 60}`) // 将剩余分钟数转换为秒数
  if (hours < 10) {
    hours = '0' + hours
  }
  if (restMinutes < 10) {
    restMinutes = '0' + restMinutes
  }
  if (seconds < 10) {
    seconds = '0' + seconds
  }
  return hours + ':' + restMinutes + ':' + seconds
}
//取消解析ppt
const cancelAnalyze = () => {
  showLeftList.value = true
  clearInterval(schedulePPTTimer.value)
}
const copyDocument = (item, index) => {
  let copyItem = cloneDeep(item)
  copyItem.id = generateUUID()
  copyItem.isActive = false
  PPTArr.value.splice(index + 1, 0, copyItem)
}
const deleteDocument = (item) => {
  PPTArr.value = PPTArr.value.filter((child) => child.id !== item.id)
}
const deleteDigitalHuman = () => {
  selectPPT.value.showDigitalHuman = false
}
//删除画中画
const deleteInnerPicture = () => {
  selectPPT.value.innerPicture.src = ''
}
//删除多个ppt
const deleteMore = () => {
  let selected = PPTArr.value.filter((child) => child.isChecked == true)
  if (selected.length == 0) {
    message.warning('请先选择要删除的ppt')
  } else {
    let newPPTArr = PPTArr.value.filter((child) => child.isChecked !== true)
    PPTArr.value = newPPTArr
  }
}
/** 查询数字人列表 */
const hostList = ref()
const loading = ref(true) // 列表的加载中
const total = ref(0)
const queryParams = reactive({
  pageNo: 1,
  pageSize: 100,
  type: '',
  gender: '',
  posture: ''
})
const getList = async () => {
  loading.value = true
  try {
    queryParams.type = tabs1ActiveNum.value
    queryParams.gender = tabs2ActiveNum.value
    queryParams.posture = tabs3ActiveNum.value
    queryParams.status = 0
    let data = await pptTemplateApi.pageList(queryParams)
    //如果数字人列表 data为空 则切换type再查询一次
    if (data.list.length == 0) {
      queryParams.type = tabs1ActiveNum.value == '0' ? '1' : '0'
      tabs1ActiveNum.value = queryParams.type
      data = await pptTemplateApi.pageList(queryParams)
      if (data.list.length == 0) {
        //如果还是没有,则提示没有有效的数字人,请联系管理员
        message.error('没有有效的数字人,请联系管理员')
        return
      }
    }
    data.list.forEach((item) => {
      item.isActive = false
    })
    hostList.value = data.list
    humanId=hostList.value[0].id
    selectHost.value = hostList.value[0]
    // 切换数字人姿势条件时,修改数字人在ppt的位置
    initHumanPositon(selectHost.value)
    total.value = data.total
  } finally {
    loading.value = false
  }
}
const choosePPt = (item) => {
  PPTArr.value.forEach((child) => {
    if (child.id == item.id) {
      child.isActive = true
    } else {
      child.isActive = false
    }
  })
  selectPPT.value = item
}
const selectHost = ref() // 选择的数字人
const chooseHost = (item) => {
  console.log(item)
  //将数字人id变成全局变量
  humanId=item.id
  hostList.value.forEach((el) => {
    if (el.id == item.id) {
      el.isActive = true
    } else {
      el.isActive = false
    }
  })
  selectHost.value = item
  // 点击数字人列表中的图像时,修改数字人在ppt的位置
  initHumanPositon(item)
}
// 根据数字人的不同姿势初始化其在ppt的位置
const initHumanPositon = (data) => {
  console.log(digitalHumanSize)
  if (data.posture === 1) {
    PPTpositon.x = viewSize.width - digitalHumanSize.width
    PPTpositon.y = viewSize.height - digitalHumanSize.height
    PPTpositon.w = digitalHumanSize.width
    PPTpositon.h = digitalHumanSize.height
  } else if (data.posture === 2) {
    PPTpositon.x = viewSize.width - digitalHumanSize.width
    PPTpositon.y = viewSize.height - digitalHumanSize.height
    PPTpositon.w = digitalHumanSize.width
    PPTpositon.h = digitalHumanSize.height
  }
}
//打开弹框
const audioSelect = ref()
const audioSelectData = ref()
const openSelect = () => {
  audioSelect.value.open()
}
const selectAudio = (data) => {
  console.log(data)
  audioSelectData.value = data
  // selectPPT.value.selectAudio = data[0]
  // 遍历所有场景,应用相同的声音模型
  if (data==undefined){
    selectPPT.value.selectAudio.name=''
    return {}
  }else {
    PPTArr.value.forEach((scene) => {
      scene.selectAudio = data[0]
    })
  }
 
}
//生成课程id
const coursesCreate = () => {
  const params = {
    accountId: userId.value
  }
  pptTemplateApi.coursesCreate(params).then((res) => {
    console.log(res)
    if (res) {
      courseInfo.value.id = res
    }
  })
}
 
//获取保存时间
const saveTime = ref()
const getSaveTime = () => {
  const date = new Date()
  let h: any = date.getHours() //hour
  let m: any = date.getMinutes() //minute
  let s: any = date.getSeconds() //second
  if (h < 10) {
    h = '0' + h
  }
  if (m < 10) {
    m = '0' + m
  }
  if (s < 10) {
    s = '0' + s
  }
  return h + ':' + m + ':' + s
}
const warningDialog = ref()
 
// 语速 音量
const voiceData = reactive({
  show: false,
  speechRate: 1,
  volume: 1,
  defaultSpeechRate: 1,
  defaultVolume: 1,
  marks: {
    0.6: '0.6',
    1: '1',
    1.5: '1.5'
  },
  marks2: {
    1: '1',
    1.5: '1.5',
    2: '2'
  }
})
const removeHtmlTags= (html) =>{
  const parser = new DOMParser();
  const doc = parser.parseFromString(html, 'text/html');
  return doc.body.textContent || "";
}
 
const saveSubmit = async (type) => {
  // 检查场景是否为空
  if (!PPTArr.value || PPTArr.value.length === 0) {
    message.warning('场景为空,请先上传PPT!')
    return false
  }
 
  //保存课程
  let saveSubmitForm = {
    accountId: courseInfo.value.accountId,
    aspect: courseInfo.value.aspect,
    duration: courseInfo.value.duration,
    height: courseInfo.value.height,
    matting: courseInfo.value.matting,
    name: courseInfo.value.name,
    pageMode: courseInfo.value.pageMode,
    ppt: [],
    scenes: [],
    status: courseInfo.value.status,
    width: courseInfo.value.width,
    pageInfo: '',
    thumbnail: '',
    subtitlesStyle: '{}'
  }
  // if(type == "save"){
  Reflect.set(saveSubmitForm, 'id', courseInfo.value.id)
  // }else{
  //   Reflect.set(saveSubmitForm, "courseMediaId", courseInfo.value.id);
  // }
 
  //组装数据
  const scenes: any = []
  const pageInfo = {
    docInfo: {
      docType: 1,
      fileName: uploadFileObj.filename,
      fileSize: uploadFileObj.size
    },
    scenes: [] as any[]
  }
  let thumbnail = ''
  const { name, pictureUrl, code, type: digitalHumanType } = selectHost.value // 解构以避免循环引用
  const digitalHumanComponents = {
    name,
    src: pictureUrl,
    cover: pictureUrl,
    width: PPTpositon.w * scaleRatio.value.width,
    height: PPTpositon.h * scaleRatio.value.height,
    originWidth: PPTpositon.w * scaleRatio.value.width,
    originHeight: PPTpositon.h * scaleRatio.value.height,
    category: 2, // 1: PPT, 2: 数字人, 3: 其他
    depth: componentsInfo.depth,
    top: PPTpositon.y * scaleRatio.value.height,
    marginLeft: PPTpositon.x * scaleRatio.value.width,
    entityId: code,
    entityType: digitalHumanType, // 如果是数字人,则是数字人类型 0: 普通, 1: 专属
    businessId: generateUUID(),
    digitbotType: tabs1ActiveNum.value,
    matting: 1,
    marker: 1
  }
 
  let pageNum = 1
  if (PPTArr.value && PPTArr.value.length > 0) {
    console.log('开始处理PPTArr数据')
    PPTArr.value.forEach((item, index) => {
      console.log(`处理第 ${index + 1} 个场景`)
      try {
        pageInfo.scenes.push(item.businessId)
        if (pageNum == 1) {
          thumbnail = item.pictureUrl
          pageNum++
        }
        console.log(item)
 
        const innerPictureCom = item.innerPicture
        console.log('innerPictureCom:', JSON.stringify(innerPictureCom))
        console.log(item.pptRemark)
        item.pptRemark = removeHtmlTags(item.pptRemark)
        // item.pptRemark = editorRef.value.getText()
        // item.pptRemark=item.pptRemark.replace(/<[^>]+>/g, '')
        const formatItem = {
          background: {
            backgroundType: item.backgroundType,
            entityId: '',
            width: courseInfo.value.width,
            height: courseInfo.value.height,
            depth: 0,
            src: item.pictureUrl,
            cover: item.pictureUrl,
            originWidth: item.width,
            originHeight: item.height,
            color: '#ffffff',
            pptRemark: item.pptRemark
          },
          hasPerson: item.showDigitalHuman==true? 1 : 2,
          components: [
            {
              ...cloneDeep(digitalHumanComponents), // 深拷贝
              status: item.showDigitalHuman ? 0 : 1
            },
            ...(item.innerPicture?.src
              ? [
                  {
                    ...cloneDeep(item.innerPicture),
                    // 保存时放大画中画的尺寸和位置
                    width: item.innerPicture.width * scaleRatio.value.width,
                    height: item.innerPicture.height * scaleRatio.value.height,
                    top: item.innerPicture.top * scaleRatio.value.height,
                    marginLeft: item.innerPicture.marginLeft * scaleRatio.value.width,
                    category: 1,
                    id: undefined
                  }
                ]
              : [])
          ],
          driverType: item.driverType,
          duration: '',
          orderNo: index + 1,
          textDriver: {
            pitch: '',
            speed: '',
            speech_rate: voiceData.speechRate,
            volume: voiceData.volume,
            smartSpeed: '',
            textJson: item.pptRemark,
          },
          audioDriver: {
            fileName: item.fileList && item.fileList[0]?.name,
            audioId: '',
            audioUrl: item.uploadAudioUrl,
            useVideoBackgroundAudio: ''
          },
          voice: {
            voiceId:audioSelectData.value == undefined ? null : audioSelectData.value[0].id,
            entityId: item.selectAudio && item.selectAudio.code,
            tonePitch: '',
            voiceType: item.selectAudio && item.selectAudio.voiceType,
            speechRate: '',
            name: item.selectAudio && item.selectAudio.name
          },
          businessId: item.businessId
        }
        scenes.push(formatItem)
      } catch (error) {
        console.error(`处理第 ${index + 1} 个场景时出错:`, error)
        //抛出异常
        throw error
      }
    })
  }
  console.log('pageInfo:', JSON.stringify(pageInfo))
  console.log('thumbnail:', thumbnail)
 
  try {
    saveSubmitForm.pageInfo = JSON.stringify(pageInfo)
    saveSubmitForm.thumbnail = thumbnail
    saveSubmitForm.scenes = cloneDeep(scenes)
    console.log('saveSubmitForm:', cloneDeep(saveSubmitForm))
  } catch (error) {
    console.error('保存表单数据时出错:', error)
  }
 
  if (type == 'save') {
    try {
      const res = await pptTemplateApi.coursesSave(stringifySafely(saveSubmitForm))
      if (res) {
        message.success('保存成功!')
        saveTime.value = getSaveTime()
        return true // 返回保存成功标志
      }
      return false
    } catch (error) {
      console.error('保存课程时出错:', error)
      message.error('保存失败,请重试')
      return false
    }
  } else {
    // 合成视频前先保存
    try {
      const saveResult = await saveSubmit('save')
      if (!saveResult) {
        message.error('保存失败,请重试后再合成视频')
        return
      }
 
      // 校验场景数据
      let warningStrArr: any = []
      for (let i = 0; i < PPTArr.value.length; i++) {
        const item = PPTArr.value[i]
        console.log(item)
        // 校验背景宽高
        if (!item.width || !item.height) {
          message.warning('背景尺寸无效,请检查宽高设置,或者重新选择模板')
          return
        }
        if (item.driverType == 1) {
          // 去除所有HTML标签和SSML标签后再判断内容是否为空
          const plainText = item.pptRemark ? item.pptRemark.replace(/<[^>]+>/g, '') : ''
          if (!plainText || plainText.trim() === '') {
            warningStrArr.push(
              `场景<span style="color: red; font-weight: bold;">${i + 1}</span>无有效的口播内容`
            )
          }
          else {
            //判断去除标签后的内容长度是否超过2000字
            if (plainText.length > 2000) {
              warningStrArr.push(
                `场景<span style="color: red; font-weight: bold;">${i + 1}</span>口播内容超过2000字,请减少或拆分场景`
              )
            }
          }
        }
      }
 
      if (warningStrArr.length > 0) {
        warningDialog.value.open(warningStrArr.map((warning) => `<div>${warning}</div>`).join(''))
        return
      }
 
      // 合成视频
      try {
        const res = await pptTemplateApi.megerMedia(saveSubmitForm)
        if (res) {
          message.success('合成视频任务提交成功,请到我的视频中查看!')
        }
      } catch (error) {
        console.error('合成视频失败:', error)
        message.error('合成视频失败,请重试')
      }
    } catch (error) {
      console.error('保存或合成过程出错:', error)
      message.error('操作失败,请重试')
    }
  }
}
function stringifySafely(obj) {
  const seen = new WeakSet()
  return JSON.stringify(obj, (key, value) => {
    if (typeof value === 'object' && value !== null) {
      if (seen.has(value)) {
        return // 循环引用时返回 undefined
      }
      seen.add(value)
    }
    return value
  })
}
//定时保存
// const saveTimer = ref()
// const saveInter = () => {
//   if (saveTimer.value) {
//     clearInterval(saveTimer.value)
//   }
//   saveTimer.value = setInterval(() => {
//     saveSubmit('save')
//   }, 60000)
// }
//生成试听
const showAudioPlay = ref(false) //显示试听
const showAudioPlay1 = ref(false) //显示试听
//显示声音驱动的文件播放弹框
const startAudioPlay = ref(false)
const textareaRef = ref()
const selectTextarea = ref('')
//上传音频文件超出限制后的提示
const audioExceed = () => {
  message.warning('最多上传一个声音驱动文件!')
}
const currentAudio = ref()
 
const handlePptRemarkSelection = () => {
  if (textareaRef.value) {
    const textarea = textareaRef.value.$el.querySelector('textarea')
    if (textarea) {
      // 使用事件对象中的选中文本
      selectTextarea.value = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd)
      console.log('选中的文本:', selectTextarea.value)
    }
  }
}
//富文本编辑器  -start
// 编辑器实例,必须用 shallowRef
const editorRef = shallowRef()
const editorConfig = { placeholder: '请输入内容...' }
const handleCreated = (editor) => {
    editorRef.value = editor // editor 实例
}
//停顿
const handleBreak = (e) => {
    //节点插入
    const node = {
        type: 'title-black',
        children: [{ text: e }]
    }
    editorRef.value.restoreSelection() // 恢复选区
    editorRef.value.insertNode(node);
    editorRef.value.move(1);
}
//数字
const handleNumber = (e) => {
    editorRef.value.focus()
    selectTextarea.value = editorRef.value.getSelectionText()
    let reg = /^\d+$/
    if (!selectTextarea.value || selectTextarea.value.length == 0 || !reg.test(selectTextarea.value)) {
      message.warning('请先选中需指定读法的数字')
        return false
    }
    //节点插入
    const node = {
        type: 'number-value',
        numberVal: selectTextarea.value,
        children: [{ text: e }]
    }
    editorRef.value.restoreSelection() // 恢复选区
    editorRef.value.insertNode(node);
    editorRef.value.move(1);
}
//多音字
const dialogVisible = ref(false)
const textList = ref([])
const handleWord = () => {
    editorRef.value.focus()
    selectTextarea.value = editorRef.value.getSelectionText()
    if (!selectTextarea.value) {
      message.warning('请先选中需指定读法的文本')
        return false
    }
    if (selectTextarea.value.length > 1) {
      message.warning('只能选择一个字')
        return false
    }
    let textPinyin = polyphonic(selectTextarea.value, { toneType: 'num', type: 'array' })[0];
    if (textPinyin.length > 1) {
        textList.value = textPinyin;
        dialogVisible.value = true
    } else {
      message.warning(`${selectTextarea.value}不是多音字`)
    }
}
const handleTag = (name) => {
    dialogVisible.value = false
    //节点插入
    const node = {
        type: 'text-value',
        textVal: selectTextarea.value,
        children: [{ text: name }]
    }
    editorRef.value.restoreSelection() // 恢复选区
    editorRef.value.insertNode(node);
    editorRef.value.move(1);
}
const createAudio = async () => {
  // 获取编辑器文本内容
  const text = editorRef.value.getText();
 
  // 检查文本是否为空
  if (!text) {
    message.warning('请输入需要试听文本的内容…');
    return false;
  }
 
  // 截取文本长度不超过 100
  const truncatedText = text.length > 100 ? text.substring(0, 100) : text;
  console.log(audioSelectData.value)
  if (audioSelectData.value == undefined) {
    const params = {
      text: truncatedText,
      humanId: humanId,
      voiceId: null,
    };
    try {
      // 显示音频播放加载状态
      showAudioPlay1.value = true;
 
      // 调用 API 创建音频
      const res = await pptTemplateApi.createAudio(params);
 
      // 检查响应是否有效且无错误
      if (res && !res.error) {
        console.log(res);
        // 隐藏加载状态,显示音频播放状态
        showAudioPlay1.value = false;
        showAudioPlay.value = true;
 
        // 初始化 Audio 对象
        currentAudio.value = new Audio(res);
 
        // 添加播放结束事件监听器
        currentAudio.value.addEventListener('ended', () => {
          showAudioPlay.value = false;
          currentAudio.value = null;
        });
 
        // 播放音频
        currentAudio.value.play();
      } else {
        // 响应无效或有错误,隐藏加载状态
        showAudioPlay1.value = false;
      }
    } catch (error) {
      // 捕获请求错误,隐藏加载状态并打印错误信息
      console.error('API 请求失败:', error);
      showAudioPlay1.value = false;
    }
  }else {
    const params = {
      text: truncatedText,
      humanId: null,
      voiceId: audioSelectData.value[0].id,
    };
    try {
      // 显示音频播放加载状态
      showAudioPlay1.value = true;
 
      // 调用 API 创建音频
      const res = await pptTemplateApi.createAudio(params);
 
      // 检查响应是否有效且无错误
      if (res && !res.error) {
        console.log(res);
        // 隐藏加载状态,显示音频播放状态
        showAudioPlay1.value = false;
        showAudioPlay.value = true;
 
        // 初始化 Audio 对象
        currentAudio.value = new Audio(res);
 
        // 添加播放结束事件监听器
        currentAudio.value.addEventListener('ended', () => {
          showAudioPlay.value = false;
          currentAudio.value = null;
        });
 
        // 播放音频
        currentAudio.value.play();
      } else {
        // 响应无效或有错误,隐藏加载状态
        showAudioPlay1.value = false;
      }
    } catch (error) {
      // 捕获请求错误,隐藏加载状态并打印错误信息
      console.error('API 请求失败:', error);
      showAudioPlay1.value = false;
    }
  }
  // 构建请求参数
 
 
 
}
//取消试听
const pauseAudio = () => {
  currentAudio.value.pause()
  currentAudio.value = null
  showAudioPlay.value = false
}
//声音驱动的文件
const currentAudioFile = ref()
//声音驱动的文件播放
const audioPlay = (file) => {
  // 确保 file.response.data 是一个有效的 URL
  if (!file.response.data) {
    message.error('未获取到文件')
    return
  }
  // 停止当前播放的音频(如果存在)
  if (currentAudioFile.value) {
    currentAudioFile.value.pause()
    currentAudioFile.value.currentTime = 0 // 重置播放位置
  }
 
  // 创建新的 Audio 实例
  const audio = new Audio(file.response.data)
  currentAudioFile.value = audio
 
  // 监听播放结束事件
  audio.addEventListener('ended', () => {
    cancelAudio()
  })
 
  // 开始播放
  startAudioPlay.value = true
  audio.play()
}
//取消声音驱动的文件播放
const cancelAudio = () => {
  if (currentAudioFile.value) {
    currentAudioFile.value.pause()
    // 可选:重置播放位置
    currentAudioFile.value.currentTime = 0
    currentAudioFile.value = null
  }
  startAudioPlay.value = false
}
//返回
const goBack = () => {
  console.log(PPTArr.value,courseInfo.value.id)
  if (!PPTArr.value) {
  //  删除当前课程
    pptTemplateApi.coursesDelete(courseInfo.value.id).then((res) => {
      console.log(res)
    })
  }
  router.go(-1)
}
const getCourseDetail = (id) => {
  pptTemplateApi.coursesDetail(id).then((res) => {
    console.log(res)
    if (res) {
      //回显数据处理
      // 课程基本信息
      courseInfo.value = res
      if (res.scenes && res.scenes.length > 0) {
        //左侧数据列表
        res.scenes.forEach((item) => {
          item.isActive = false
          item.isChecked = false
          item.pictureUrl = item.background.src
          item.pptRemark = editorHtml.parseElemHtml(item.background.pptRemark);
          item.backgroundType = item.background.backgroundType
          item.width = item.background.width
          item.height = item.background.height
          item.showDigitalHuman = item.components.find((p) => p.category == 2).status == 0 //根据数字人模板的status判断是否显示数字人
          // 画中画位置和尺寸缩小
          const innerPicture = item.components.find((p) => p.category == 1)
          if (innerPicture) {
            item.innerPicture = {
              ...innerPicture,
              width: innerPicture.width / scaleRatio.value.width,
              height: innerPicture.height / scaleRatio.value.height,
              top: innerPicture.top / scaleRatio.value.height,
              marginLeft: innerPicture.marginLeft / scaleRatio.value.width
            }
          }
        })
        PPTArr.value = res.scenes
        PPTArr.value[0].isActive = true
        selectPPT.value = PPTArr.value[0]
        console.log('getCourseDetail selectPPT.value:', selectPPT.value)
        // selectPPT.value.uploadAudioUrl = PPTArr.value[0].audioDriver?.audioUrl;
        // selectPPT.value.selectAudio = PPTArr.value[0].voice;
        // 遍历所有场景,应用相同的声音模型
        PPTArr.value.forEach((scene, index) => {
          //如果res.scenes[index] 有voice且不为空
          if (res.scenes[index].voice) {
            scene.selectAudio = res.scenes[index].voice
            scene.selectAudio.code = res.scenes[index].voice.entityId
            scene.selectAudio.id = res.scenes[index].voice.voiceId
          }
          scene.uploadAudioUrl = res.scenes[index].audioDriver?.audioUrl
        })
        if (PPTArr.value[0].audioDriver?.fileName && PPTArr.value[0].audioDriver?.audioUrl) {
          selectPPT.value.fileList = [
            {
              name: PPTArr.value[0].audioDriver?.fileName,
              url: PPTArr.value[0].audioDriver?.audioUrl
            }
          ]
        }
        //选择的数字人信息
        const hostInfo = res.scenes[0].components.find((component) => component.category === 2)
        // 先在当前数字人列表中查找
        let foundHost = hostList.value.find(item => item.code === hostInfo.entityId)
 
        // 如果在当前列表中没找到,且当前是公共数字人列表,则切换到我的数字人列表重新获取
        if (!foundHost && tabs1ActiveNum.value === '0') {
          // 保存公共数字人列表的第一个数字人作为默认值
          const defaultPublicHost = hostList.value[0]
 
          // 切换到"我的"数字人
          tabs1ActiveNum.value = '1'
          // 重新获取数字人列表
          getList().then(() => {
            // 在新列表中查找
            foundHost = hostList.value.find(item => item.code === hostInfo.entityId)
 
            // 如果在"我的"数字人中也没找到,则使用默认公共数字人
            if (!foundHost) {
              tabs1ActiveNum.value = '0' // 切回公共数字人tab
              foundHost = defaultPublicHost // 使用之前保存的默认公共数字人
              message.warning('未找到原数字人,已使用默认公共数字人替代')
            }
 
            // 设置选中的数字人
            selectHost.value = foundHost || hostList.value[0]
          })
        } else {
          // 设置选中的数字人
          selectHost.value = foundHost || hostList.value[0]
        }
 
        // 设置选中的数字人
        selectHost.value = foundHost || hostList.value[0]
        if (hostInfo) {
          PPTpositon.w = hostInfo.width / scaleRatio.value.width
          PPTpositon.h = hostInfo.height / scaleRatio.value.height
          PPTpositon.x = hostInfo.marginLeft / scaleRatio.value.width
          PPTpositon.y = hostInfo.top / scaleRatio.value.height
        }
        // selectHost.value.name = hostInfo.name;
        // selectHost.value.pictureUrl = hostInfo.src;
        // selectHost.value.id = hostInfo.entityId;
        //数字人位置信息
        componentsInfo.width = hostInfo.width
        componentsInfo.height = hostInfo.height
        componentsInfo.top = hostInfo.top
        componentsInfo.marginLeft = hostInfo.marginLeft
        componentsInfo.depth = hostInfo.depth
        //数字人类型
        tabs1ActiveNum.value = hostInfo.digitbotType
        driveType.forEach((child) => {
          if (child.name == hostInfo.driverType) {
            selectDriveType.value = child
          }
        })
        //选择声音信息
        const voiceInfo = res.scenes[0].voice
        audioSelectData.value = [
          {
            id: voiceInfo.voiceId,
            entityId: voiceInfo.entityId,
            name: voiceInfo.name
          }
        ]
      }
      //上传文件信息
      const pageInfo = res.pageInfo ? JSON.parse(res.pageInfo) : ''
      uploadFileObj.filename = pageInfo ? pageInfo.docInfo.fileName : ''
      uploadFileObj.size = pageInfo ? pageInfo.docInfo.fileSize : ''
 
      //应用模板 这里用户可能已经调整了模板,所以这里不应用模板
      // applyTemplate()
    }
  })
}
//选择模板
const chooseTemplate = (currTemplate) => {
  selectTemplate.value = cloneDeep(currTemplate)
  console.log('选择的模板信息:', currTemplate)
  templates.value.forEach((item) => {
    item.isActive = false
  })
  currTemplate.isActive = true
  applyTemplate()
}
 
const applyTemplate = (ppt = null) => {
  const template = selectTemplate.value
  const pptList = applyAllTemplate.value ? PPTArr.value : [selectPPT.value]
 
  // 数字人是统一生效的,先处理
  console.log(template)
  pptList.forEach((item) => {
    // 保存原始ppt图片
    const originalPPT = item.innerPicture?.src || item.pictureUrl
    console.log('originalPPT', originalPPT)
    if (template.showBackground) {
      item.pictureUrl = template.bgImage
      if (template.showPpt) {
        item.innerPicture = {
          name: '画中画',
          src: originalPPT,
          cover: template.bgImage,
          width: template.pptW,
          height: template.pptH,
          top: template.pptY,
          marginLeft: template.pptX,
          category: 1,
          depth: 1,
          businessId: generateUUID(),
          entityType: 1,
          originHeight: courseInfo.value.height,
          originWidth: courseInfo.value.width,
          entityId: 1,
          templateId: template.id,
        }
      }
    } else {
      item.pictureUrl = originalPPT
      item.innerPicture.src = ''
    }
 
    item.showDigitalHuman = template.showDigitalHuman
    // 添加同步宽高的逻辑
    const targetTemplate = selectTemplate.value
    console.log(PPTArr)
    PPTArr.value.forEach((otherItem) => {
      if (otherItem.templateId === item.templateId) {
        otherItem.width = item.width
        otherItem.height = item.height
      }
    })
  })
 
  // 数字人位置也需要缩放
  PPTpositon.w = selectTemplate.value.humanW
  PPTpositon.h = selectTemplate.value.humanH
  PPTpositon.x = selectTemplate.value.humanX
  PPTpositon.y = selectTemplate.value.humanY
}
 
const replaceDialog = ref(null)
 
// 打开弹出框
const openReplaceDialog = () => {
  replaceDialog.value.open()
}
 
// 处理提交的替换规则
const escapeRegExp = (string) => {
  return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') // 转义正则中的特殊字符
}
 
const handleReplacement = (replacements) => {
  PPTArr.value.forEach((item) => {
    if (item.pptRemark) {
      replacements.forEach((replacement) => {
        const fromEscaped = escapeRegExp(replacement.from) // 转义特殊字符
        const regExp = new RegExp(fromEscaped, 'g') // 使用转义后的字符串构造正则表达式
        item.pptRemark = item.pptRemark.replace(regExp, replacement.to)
      })
    }
  })
  message.success('批量替换成功!')
}
 
onMounted(async () => {
  let data = await TemplateApi.getTemplatePage(queryParams)
  TEMPLATE_PRESETS.value = data.list.map((item) => {
    return {
      ...item,
      showBackground: item.showBackground === 1,
      showDigitalHuman: item.showDigitalHuman === 1,
      showPpt: item.showPpt === 1
    }
  })
  if (templates.value.length > 0) selectTemplate.value = cloneDeep(templates.value[0])
  templates.value = TEMPLATE_PRESETS.value.map((template) => cloneDeep(template))
  selectTemplate.value = cloneDeep(templates.value[0])
  // console.log('onMounted selectTemplate.value',selectTemplate.value)
  await getList()
  console.log(route.query.id)
  if (route.query.id) {
    await getCourseDetail(route.query.id)
    // saveInter() // 启动定时保存
  } else {
    coursesCreate()
  }
})
onUnmounted(() => {
  // clearInterval(saveTimer.value)
  console.log(schedulePPTTimer.value)
  clearInterval(schedulePPTTimer.value)
  if (currentAudioFile.value) {
    currentAudioFile.value.removeEventListener('ended', cancelAudio)
    currentAudioFile.value = null
  }
})
</script>
<style scoped lang="scss">
.pages {
  height: 100%;
  background-color: #f5f7fa;
}
 
.minddle-host-image {
  z-index: 5;
  width: 100%;
  height: 100%;
}
 
.template-top {
  display: flex;
  height: 60px;
  padding: 0 30px;
  line-height: 60px;
  background-color: #fff;
  border: 1px solid #ebeef5;
  box-shadow: 0 3px 6px rgb(175 175 175 / 16%);
  justify-content: space-between;
 
  .top-left {
    display: flex;
    align-items: center;
 
    .top-icon {
      display: flex;
      align-items: center;
    }
 
    .back-text {
      margin-right: 20px;
      margin-left: 10px;
      cursor: pointer;
    }
 
    span {
      margin: 0 25px;
    }
  }
 
  .top-right {
    span {
      margin: 0 20px;
    }
  }
}
 
.template-main {
  display: flex;
  height: calc(100% - 82px);
  padding: 10px;
  justify-content: space-around;
 
  .template-left {
    position: relative;
    width: 180px;
    background-color: #fff;
    border: 1px solid #ebeef5;
    box-shadow: 0 3px 6px rgb(175 175 175 / 16%);
 
    .page {
      margin: 0;
 
      div {
        // height: 30px;
        padding: 5px 10px;
        margin: 0;
        line-height: 30px;
        border-bottom: 1px solid #ebeef5;
      }
 
      .line {
        width: 30px;
        height: 3px;
        padding: 0;
        margin: 0;
        background-color: aqua;
      }
 
      .upload-demo {
        text-align: center;
      }
    }
 
    .left-upload-setting {
      display: flex;
      height: calc(100% - 86px);
      padding: 0 20px;
      text-align: center;
      flex-direction: column;
      justify-content: center;
      align-items: center;
 
      div {
        line-height: 40px;
      }
 
      ::v-deep(.el-progress-bar) {
        width: 180px;
      }
 
      .el-button {
        margin: 20px 0;
      }
    }
 
    .image-list {
      height: calc(100% - 70px);
      padding: 10px;
      overflow: hidden auto;
      border-bottom: 1px solid #ebeef5;
 
      .list {
        position: relative;
        height: calc(152px * 9 / 16); // 使用缩略图的固定高度
        margin: 20px 0;
        box-sizing: content-box;
 
        .list-index {
          position: absolute;
          top: 10px;
          left: 10px;
          z-index: 100;
          width: 25px;
          height: 25px;
          line-height: 25px;
          color: #fff;
          text-align: center;
          background: #122121;
          border-radius: 5px;
        }
 
        // 确保背景图片填充整个容器
        .background {
          position: absolute;
          width: 100%;
          height: 100%;
        }
        .background1 {
          position: absolute;
          width: 100%;
          height: 100%;
          background-color: rgba(0, 0, 0, 0);
        }
 
        .ppt-bg {
          z-index: 2;
          // width: 152px;
          // height: 100%;
        }
 
        .host {
          position: absolute;
          z-index: 3;
        }
 
        .icon-content {
          position: absolute;
          top: 0;
          right: 10px;
          display: flex;
          cursor: pointer;
          align-items: center;
          z-index: 4;
        }
      }
    }
 
    .page-btn {
      position: absolute;
      bottom: 10px;
      width: 85%;
      padding: 0 10px;
    }
  }
 
  .template-middle {
    display: flex;
    width: 56%;
    background-color: #fff;
    box-shadow: 0 3px 6px rgb(175 175 175 / 16%);
    flex-grow: 1; // 确保中间区域可以自适应高度
    flex-direction: column;
    justify-content: flex-start;
 
    .middle-top {
      padding: 5px 20px;
    }
 
    .main-box {
      display: flex;
      padding: 10px 20px;
      border: 1px solid #ebeef5;
      justify-content: center;
 
      .main-image-box {
        position: relative;
        // width: 760px;
        // height: 360px;
        border: 1px solid #ebeef5;
        box-sizing: content-box;
      }
 
      .list {
        position: relative;
        display: flex;
        width: 95%;
        justify-content: center;
      }
 
      .ppt-bg {
        z-index: 2;
        width: 100%;
        height: 100%;
      }
 
      .host {
        position: absolute;
        right: 0;
        bottom: 0;
        width: 300px;
      }
    }
 
    .voice-main {
      display: flex;
      justify-content: space-between;
      padding: 10px;
 
      .voice-item {
        width: 180px;
        height: 30px;
        overflow: hidden;
        cursor: pointer;
        background-color: #c9c9c9;
        border-radius: 12px;
 
        span {
          display: inline-block;
          width: 50%;
          height: 30px;
          line-height: 30px;
          text-align: center;
        }
 
        .active-item {
          color: #fff;
          background-color: #409eff;
        }
      }
 
      .media-box {
        display: flex;
        align-items: center;
 
        .mic {
          display: flex;
          align-items: center;
          width: 50px;
          justify-content: space-around;
          padding: 5px 10px;
        }
      }
    }
 
    .audio-upload {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 200px;
    }
 
    .middle-textarea {
      padding: 5px 20px;
    }
 
    .tool-box {
      display: flex;
      padding: 10px;
      border-top: 1px solid #ebeef5;
      justify-content: space-between;
 
      .tool-btn {
        display: flex;
        align-items: center;
      }
    }
 
    .audio-play {
      position: absolute;
      top: 0;
      left: 0;
      display: flex;
      width: 100%;
      height: 100%;
      padding: 20px 0;
      line-height: 40px;
      color: #fff;
      background: #000;
      opacity: 0.5;
      align-items: center;
      flex-direction: column;
    }
  }
 
  .template-right {
    position: relative;
    width: 20%;
    background-color: #fff;
    box-shadow: 0 3px 6px rgb(175 175 175 / 16%);
 
    .tabs-1 {
      display: flex;
      justify-content: space-around;
      padding: 10px 30px;
      border-bottom: 1px solid #ebeef5;
 
      .tabs-item {
        width: 30px;
        font-size: 14px;
        text-align: center;
        cursor: pointer;
 
        span {
          display: block;
          width: 30px;
          height: 2px;
          margin-top: 5px;
          background: #409eff;
        }
      }
    }
 
    .tabs-2 {
      display: flex;
      padding: 10px;
      justify-content: space-around;
 
      div {
        width: 60px;
        height: 30px;
        line-height: 30px;
        text-align: center;
        cursor: pointer;
        border-radius: 5px;
      }
 
      .tabs-active {
        color: #fff !important;
        background-color: #409eff;
      }
    }
 
    .apply-all {
      position: absolute;
      bottom: 80px;
      display: flex;
      width: 100%;
      justify-content: center;
    }
 
    .host-list {
      height: 80%;
      overflow-y: auto;
      border-top: 1px solid #ebeef5;
 
      .host-item {
        position: relative;
        display: inline-block;
        width: 45%;
        height: 200px;
        margin: 5px 0;
        margin-left: 10px;
        cursor: pointer;
 
        .background {
          position: absolute;
          top: 0;
          left: 0;
          z-index: 1; /* 背景在底层 */
          width: 100%;
          height: 100%;
          background-color: #f0f1fa; /* 设置底色 */
        }
 
        .host-name {
          position: absolute;
          bottom: 10px;
          left: 5px;
          z-index: 100;
          width: 30px;
          height: 20px;
          font-size: 10px;
          line-height: 20px;
          text-align: center;
          background: rgb(225 225 225 / 70%);
          border-radius: 5px;
        }
 
        .ppt-bg {
          z-index: 2; /* 图片在背景之上 */
          width: 100%;
          height: 100%;
        }
      }
    }
  }
 
  .image-setting {
    padding: 10px 20px;
 
    .img-setting {
      display: flex;
      align-items: center;
      line-height: 40px;
 
      .setting-label {
        width: 120px;
      }
 
      ::v-deep(.el-input) {
        width: 170px;
        margin-left: 10px;
      }
    }
  }
 
  .template-list {
    height: 90%;
    overflow-y: auto;
    border-top: 1px solid #ebeef5;
 
    .template-item {
      position: relative;
      display: inline-block;
      width: 224px;
      height: 126px;
      margin: 5px 0;
      margin-left: 10px;
      cursor: pointer;
      .list-index {
        position: absolute;
        top: 10px;
        left: 10px;
        z-index: 100;
        width: 25px;
        height: 25px;
        line-height: 25px;
        color: #fff;
        text-align: center;
        background: #122121;
        border-radius: 5px;
      }
      .ppt-bg {
        position: absolute;
        z-index: 2; /* 图片在背景之上 */
      }
 
      .human-image {
        position: absolute;
        z-index: 3; /* 图片在背景之上 */
      }
    }
  }
 
  .background {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1; /* 背景在底层 */
    width: 100%;
    height: 100%;
    background-color: #f0f1fa; /* 设置底色 */
  }
 
  .template-tool {
    width: 60px;
    padding: 10px;
    background-color: #fff;
    box-shadow: 0 3px 6px rgb(175 175 175 / 16%);
 
    .tool-item {
      display: flex;
      padding: 10px 20px;
      cursor: pointer;
      flex-direction: column;
      align-items: center;
 
      img {
        width: 32px;
        height: 32px;
      }
 
      .tool-name {
        width: 60px;
        margin-top: 6px;
        font-size: 14px;
        line-height: 10px;
        text-align: center;
      }
    }
  }
}
 
::v-deep(.el-pagination) {
  position: absolute;
  bottom: 0;
}
 
/* 滚动条样式 */
::-webkit-scrollbar {
  width: 4px;
}
 
/* 滑块样式 */
::-webkit-scrollbar-thumb {
  background-color: #888;
  border-radius: 6px;
}
 
/* 滚动条轨道样式 */
::-webkit-scrollbar-track {
  background-color: #f2f2f2;
  border-radius: 6px;
}
 
.voice-card {
  z-index: 1000 !important; // 添加更高的z-index确保在最顶层
}
 
.voice-card :deep(.el-card__body) {
  padding: 0;
}
 
.speech-slider {
  &:deep(.el-slider__bar) {
    display: none;
  }
 
  &:deep(.el-slider__runway) {
    height: 2px;
  }
 
  &:deep(.el-slider__button-wrapper) {
    top: -17px;
  }
 
  &:deep(.el-slider__marks-stop) {
    top: -5px;
    width: 12px;
    height: 12px;
    background-color: #1989fa;
  }
}
</style>