|
@@ -834,17 +834,12 @@ const ProjectDetail = () => {
|
834
|
834
|
return null;
|
835
|
835
|
};
|
836
|
836
|
|
837
|
|
- // 添加回一键生成所有分镜图片函数(重构版)
|
|
837
|
+ /**
|
|
838
|
+ * 生成所有分镜图片
|
|
839
|
+ */
|
838
|
840
|
const generateAllImages = async (isForceRedraw = false) => {
|
839
|
|
- // 如果已经在生成中,直接返回
|
840
|
|
- if (isGenerating) {
|
841
|
|
- console.log('已经在进行绘画任务,请等待完成或先暂停');
|
842
|
|
- return;
|
843
|
|
- }
|
844
|
|
-
|
845
|
|
- // 检查是否有有效的Coze API token
|
846
|
|
- if (!hasValidToken()) {
|
847
|
|
- toast.error('未配置Coze API Token,请先在首页点击"配置Coze API"按钮进行设置');
|
|
841
|
+ if (generatingImages) {
|
|
842
|
+ toast.info('正在绘制图片中,请等待当前操作完成');
|
848
|
843
|
return;
|
849
|
844
|
}
|
850
|
845
|
|
|
@@ -860,6 +855,14 @@ const ProjectDetail = () => {
|
860
|
855
|
// 获取需要处理的分镜
|
861
|
856
|
let segmentsToProcess = [];
|
862
|
857
|
|
|
858
|
+ // 计算已经完成的图片数量
|
|
859
|
+ const existingCompletedCount = segments.filter(
|
|
860
|
+ segment => segment.image_path && segment.draw_status === 2
|
|
861
|
+ ).length;
|
|
862
|
+
|
|
863
|
+ console.log(`当前已完成的图片数量: ${existingCompletedCount}`);
|
|
864
|
+ setCompletedDrawings(existingCompletedCount);
|
|
865
|
+
|
863
|
866
|
if (isForceRedraw) {
|
864
|
867
|
// 重绘:处理所有有描述词的分镜
|
865
|
868
|
const segmentsToRedraw = segments.filter(
|
|
@@ -1031,23 +1034,27 @@ const ProjectDetail = () => {
|
1031
|
1034
|
console.log(`分镜ID ${segment.id} 的图片生成成功: ${imagePath}`);
|
1032
|
1035
|
successCount++;
|
1033
|
1036
|
|
1034
|
|
- // 更新处理进度
|
1035
|
|
- const newCompleted = completedDrawings + 1;
|
1036
|
|
- setCompletedDrawings(newCompleted);
|
1037
|
|
-
|
1038
|
|
- // 更新进度UI
|
1039
|
|
- setImageGenerationProgress({
|
1040
|
|
- current: newCompleted,
|
1041
|
|
- total: totalSegmentsToProcess
|
|
1037
|
+ // 更新处理进度 - 修复进度计算问题
|
|
1038
|
+ setCompletedDrawings(prevCount => {
|
|
1039
|
+ const newCount = prevCount + 1;
|
|
1040
|
+ console.log(`已完成图片数量更新:${prevCount} -> ${newCount}`);
|
|
1041
|
+
|
|
1042
|
+ // 更新进度UI
|
|
1043
|
+ setImageGenerationProgress({
|
|
1044
|
+ current: newCount,
|
|
1045
|
+ total: totalSegmentsToProcess
|
|
1046
|
+ });
|
|
1047
|
+
|
|
1048
|
+ // 保存进度到localStorage
|
|
1049
|
+ localStorage.setItem(`project_${projectId}_image_generation`, JSON.stringify({
|
|
1050
|
+ progress: { current: newCount, total: totalSegmentsToProcess },
|
|
1051
|
+ timestamp: new Date().getTime(),
|
|
1052
|
+ isPaused: false
|
|
1053
|
+ }));
|
|
1054
|
+
|
|
1055
|
+ return newCount;
|
1042
|
1056
|
});
|
1043
|
1057
|
|
1044
|
|
- // 保存进度到localStorage
|
1045
|
|
- localStorage.setItem(`project_${projectId}_image_generation`, JSON.stringify({
|
1046
|
|
- progress: { current: newCompleted, total: totalSegmentsToProcess },
|
1047
|
|
- timestamp: new Date().getTime(),
|
1048
|
|
- isPaused: false
|
1049
|
|
- }));
|
1050
|
|
-
|
1051
|
1058
|
// 实时更新UI
|
1052
|
1059
|
setSegments(prevSegments =>
|
1053
|
1060
|
prevSegments.map(seg =>
|
|
@@ -1252,7 +1259,20 @@ const ProjectDetail = () => {
|
1252
|
1259
|
draw_status: 0 // 排队状态
|
1253
|
1260
|
})
|
1254
|
1261
|
));
|
1255
|
|
-
|
|
1262
|
+
|
|
1263
|
+ // 计算已完成的图片数量
|
|
1264
|
+ const completedCount = allSegments.filter(segment =>
|
|
1265
|
+ segment.draw_status === 2 && segment.image_path
|
|
1266
|
+ ).length;
|
|
1267
|
+
|
|
1268
|
+ console.log(`恢复时已完成图片数量: ${completedCount}`);
|
|
1269
|
+ setCompletedDrawings(completedCount);
|
|
1270
|
+
|
|
1271
|
+ // 计算总数量(有描述词的分镜总数)
|
|
1272
|
+ const totalCount = allSegments.filter(segment =>
|
|
1273
|
+ segment.description && segment.description.trim() !== ''
|
|
1274
|
+ ).length;
|
|
1275
|
+
|
1256
|
1276
|
// 4. 更新UI状态
|
1257
|
1277
|
setIsPaused(false);
|
1258
|
1278
|
setSegments(prevSegments =>
|
|
@@ -1263,12 +1283,17 @@ const ProjectDetail = () => {
|
1263
|
1283
|
)
|
1264
|
1284
|
);
|
1265
|
1285
|
|
|
1286
|
+ // 更新进度显示
|
|
1287
|
+ setImageGenerationProgress({
|
|
1288
|
+ current: completedCount,
|
|
1289
|
+ total: totalCount
|
|
1290
|
+ });
|
|
1291
|
+
|
1266
|
1292
|
// 5. 更新localStorage中的暂停状态
|
1267
|
1293
|
const storageItem = localStorage.getItem(`project_${projectId}_image_generation`);
|
1268
|
1294
|
if (storageItem) {
|
1269
|
|
- const data = JSON.parse(storageItem);
|
1270
|
1295
|
localStorage.setItem(`project_${projectId}_image_generation`, JSON.stringify({
|
1271
|
|
- ...data,
|
|
1296
|
+ progress: { current: completedCount, total: totalCount },
|
1272
|
1297
|
isPaused: false,
|
1273
|
1298
|
timestamp: new Date().getTime()
|
1274
|
1299
|
}));
|
|
@@ -1321,10 +1346,10 @@ const ProjectDetail = () => {
|
1321
|
1346
|
setIsPaused(false);
|
1322
|
1347
|
|
1323
|
1348
|
// 重新计算并设置进度,可以看出所有任务都已完成
|
1324
|
|
- const completedCount = allSegments.filter(segment =>
|
|
1349
|
+ const completedCount = allSegments.filter(segment =>
|
1325
|
1350
|
segment.draw_status === 2 && segment.image_path
|
1326
|
1351
|
).length;
|
1327
|
|
-
|
|
1352
|
+
|
1328
|
1353
|
// 在取消状态下,只计算已完成的分镜,因为其他都已被设置为完成状态
|
1329
|
1354
|
setImageGenerationProgress({
|
1330
|
1355
|
current: completedCount,
|
|
@@ -1559,8 +1584,8 @@ const ProjectDetail = () => {
|
1559
|
1584
|
// 更新本地存储,标记为暂停状态
|
1560
|
1585
|
const completedCount = segmentsData.filter(
|
1561
|
1586
|
segment => segment.draw_status === 2 && segment.image_path
|
1562
|
|
- ).length;
|
1563
|
|
-
|
|
1587
|
+ ).length;
|
|
1588
|
+
|
1564
|
1589
|
const totalCount = segmentsData.filter(segment =>
|
1565
|
1590
|
segment.description && segment.description.trim() !== '' && (
|
1566
|
1591
|
segment.draw_status === -1 ||
|
|
@@ -1572,8 +1597,8 @@ const ProjectDetail = () => {
|
1572
|
1597
|
|
1573
|
1598
|
localStorage.setItem(`project_${projectId}_image_generation`, JSON.stringify({
|
1574
|
1599
|
progress: {
|
1575
|
|
- current: completedCount,
|
1576
|
|
- total: totalCount
|
|
1600
|
+ current: completedCount,
|
|
1601
|
+ total: totalCount
|
1577
|
1602
|
},
|
1578
|
1603
|
timestamp: new Date().getTime(),
|
1579
|
1604
|
isPaused: true
|