fix:1.根据建议生成内容后没有自动更新章节内容

This commit is contained in:
xiamuceer
2025-11-21 17:29:15 +08:00
parent a5c1192809
commit 45bdcabca5
3 changed files with 156 additions and 35 deletions
+121 -18
View File
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react';
import { Modal, Progress, Spin, Alert, Tabs, Card, Tag, List, Empty, Statistic, Row, Col, Button } from 'antd';
import { Modal, Spin, Alert, Tabs, Card, Tag, List, Empty, Statistic, Row, Col, Button } from 'antd';
import {
ThunderboltOutlined,
BulbOutlined,
@@ -192,28 +192,112 @@ export default function ChapterAnalysis({ chapterId, visible, onClose }: Chapter
if (!task || task.status === 'completed') return null;
return (
<div style={{ padding: '24px' }}>
<div style={{ display: 'flex', alignItems: 'center', marginBottom: 16 }}>
<div style={{
padding: '40px',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
minHeight: '300px'
}}>
{/* 标题和图标 */}
<div style={{
textAlign: 'center',
marginBottom: 32
}}>
{renderStatusIcon()}
<span style={{ marginLeft: 8, fontSize: 16 }}>
<div style={{
fontSize: 20,
fontWeight: 'bold',
marginTop: 16,
color: task.status === 'failed' ? '#ff4d4f' : '#262626'
}}>
{task.status === 'pending' && '等待分析...'}
{task.status === 'running' && 'AI正在分析中...'}
{task.status === 'failed' && '分析失败'}
</span>
</div>
</div>
<Progress
percent={task.progress}
status={task.status === 'failed' ? 'exception' : 'active'}
/>
{/* 进度条 */}
<div style={{
width: '100%',
maxWidth: '500px',
marginBottom: 16
}}>
<div style={{
height: 12,
background: '#f0f0f0',
borderRadius: 6,
overflow: 'hidden',
marginBottom: 12
}}>
<div style={{
height: '100%',
background: task.status === 'failed'
? 'linear-gradient(90deg, #ff4d4f 0%, #ff7875 100%)'
: task.progress === 100
? 'linear-gradient(90deg, #52c41a 0%, #73d13d 100%)'
: 'linear-gradient(90deg, #1890ff 0%, #40a9ff 100%)',
width: `${task.progress}%`,
transition: 'all 0.3s ease',
borderRadius: 6,
boxShadow: task.progress > 0 && task.status !== 'failed'
? '0 0 10px rgba(24, 144, 255, 0.3)'
: 'none'
}} />
</div>
{/* 进度百分比 */}
<div style={{
textAlign: 'center',
fontSize: 32,
fontWeight: 'bold',
color: task.status === 'failed' ? '#ff4d4f' :
task.progress === 100 ? '#52c41a' : '#1890ff',
marginBottom: 8
}}>
{task.progress}%
</div>
</div>
{/* 状态消息 */}
<div style={{
textAlign: 'center',
fontSize: 16,
color: '#595959',
minHeight: 24,
marginBottom: 16
}}>
{task.status === 'pending' && '分析任务已创建,正在队列中...'}
{task.status === 'running' && '正在提取关键信息和记忆片段...'}
</div>
{/* 错误信息 */}
{task.status === 'failed' && task.error_message && (
<Alert
message="分析失败"
description={task.error_message}
type="error"
showIcon
style={{ marginTop: 16 }}
<Alert
message="分析失败"
description={task.error_message}
type="error"
showIcon
style={{
marginTop: 16,
maxWidth: '500px',
width: '100%'
}}
/>
)}
{/* 提示文字 */}
{task.status !== 'failed' && (
<div style={{
textAlign: 'center',
fontSize: 13,
color: '#8c8c8c',
marginTop: 16
}}>
</div>
)}
</div>
);
};
@@ -646,9 +730,28 @@ export default function ChapterAnalysis({ chapterId, visible, onClose }: Chapter
originalContent={chapterInfo.content}
newContent={newGeneratedContent}
wordCount={newContentWordCount}
onApply={() => {
// 应用新内容后刷新章节信息
fetchAnalysisStatus();
onApply={async () => {
// 应用新内容后刷新章节信息和分析
setChapterInfo(null);
setAnalysis(null);
// 重新加载章节内容
try {
const chapterResponse = await fetch(`/api/chapters/${chapterId}`);
if (chapterResponse.ok) {
const chapterData = await chapterResponse.json();
setChapterInfo({
title: chapterData.title,
chapter_number: chapterData.chapter_number,
content: chapterData.content || ''
});
}
} catch (error) {
console.error('重新加载章节失败:', error);
}
// 刷新分析状态
await fetchAnalysisStatus();
}}
onDiscard={() => {
// 放弃新内容,清空状态
@@ -50,28 +50,32 @@ const ChapterContentComparison: React.FC<ChapterContentComparisonProps> = ({
throw new Error('应用新内容失败');
}
message.success('新内容已应用!正在触发章节分析...');
message.success('新内容已应用!');
// 触发章节分析
try {
const analysisResponse = await fetch(`/api/chapters/${chapterId}/analyze`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
});
// 先调用 onApply 通知父组件刷新
onApply();
// 延迟触发章节分析,给父组件时间刷新
setTimeout(async () => {
try {
const analysisResponse = await fetch(`/api/chapters/${chapterId}/analyze`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
});
if (analysisResponse.ok) {
message.success('章节分析已开始,请稍后查看结果');
} else {
if (analysisResponse.ok) {
message.success('章节分析已开始,请稍后查看结果');
} else {
message.warning('章节分析触发失败,您可以手动触发分析');
}
} catch (analysisError) {
console.error('触发分析失败:', analysisError);
message.warning('章节分析触发失败,您可以手动触发分析');
}
} catch (analysisError) {
console.error('触发分析失败:', analysisError);
message.warning('章节分析触发失败,您可以手动触发分析');
}
}, 500);
onApply();
onClose();
} catch (error: any) {
message.error(error.message || '应用失败');
+14
View File
@@ -1358,6 +1358,20 @@ export default function Chapters() {
onClose={() => {
setAnalysisVisible(false);
// 刷新章节列表以显示最新内容
refreshChapters();
// 刷新项目信息以更新字数统计
if (currentProject) {
projectApi.getProject(currentProject.id)
.then(updatedProject => {
setCurrentProject(updatedProject);
})
.catch(error => {
console.error('刷新项目信息失败:', error);
});
}
// 延迟500ms后刷新该章节的分析状态,给后端足够时间完成数据库写入
if (analysisChapterId) {
const chapterIdToRefresh = analysisChapterId;