update:1.更新支持编辑章节概要内容
This commit is contained in:
+23
-13
@@ -2856,11 +2856,11 @@ async def update_chapter_expansion_plan(
|
||||
db: AsyncSession = Depends(get_db)
|
||||
):
|
||||
"""
|
||||
更新章节的展开规划信息
|
||||
更新章节的展开规划信息和情节概要
|
||||
|
||||
Args:
|
||||
chapter_id: 章节ID
|
||||
expansion_plan: 规划信息更新数据
|
||||
expansion_plan: 规划信息更新数据(包含summary和expansion_plan字段)
|
||||
|
||||
Returns:
|
||||
更新后的章节规划信息
|
||||
@@ -2881,18 +2881,27 @@ async def update_chapter_expansion_plan(
|
||||
# 准备更新数据(排除None值)
|
||||
plan_data = expansion_plan.model_dump(exclude_unset=True, exclude_none=True)
|
||||
|
||||
# 如果已有规划,合并更新;否则创建新规划
|
||||
if chapter.expansion_plan:
|
||||
try:
|
||||
existing_plan = json.loads(chapter.expansion_plan)
|
||||
# 合并更新
|
||||
existing_plan.update(plan_data)
|
||||
chapter.expansion_plan = json.dumps(existing_plan, ensure_ascii=False)
|
||||
except json.JSONDecodeError:
|
||||
logger.warning(f"章节 {chapter_id} 的expansion_plan格式错误,将覆盖")
|
||||
# 分离summary和expansion_plan数据
|
||||
summary_value = plan_data.pop('summary', None)
|
||||
|
||||
# 更新summary字段(如果提供)
|
||||
if summary_value is not None:
|
||||
chapter.summary = summary_value
|
||||
logger.info(f"更新章节概要: {chapter_id}")
|
||||
|
||||
# 更新expansion_plan字段(如果有其他字段)
|
||||
if plan_data:
|
||||
if chapter.expansion_plan:
|
||||
try:
|
||||
existing_plan = json.loads(chapter.expansion_plan)
|
||||
# 合并更新
|
||||
existing_plan.update(plan_data)
|
||||
chapter.expansion_plan = json.dumps(existing_plan, ensure_ascii=False)
|
||||
except json.JSONDecodeError:
|
||||
logger.warning(f"章节 {chapter_id} 的expansion_plan格式错误,将覆盖")
|
||||
chapter.expansion_plan = json.dumps(plan_data, ensure_ascii=False)
|
||||
else:
|
||||
chapter.expansion_plan = json.dumps(plan_data, ensure_ascii=False)
|
||||
else:
|
||||
chapter.expansion_plan = json.dumps(plan_data, ensure_ascii=False)
|
||||
|
||||
await db.commit()
|
||||
await db.refresh(chapter)
|
||||
@@ -2904,6 +2913,7 @@ async def update_chapter_expansion_plan(
|
||||
|
||||
return {
|
||||
"id": chapter.id,
|
||||
"summary": chapter.summary,
|
||||
"expansion_plan": updated_plan,
|
||||
"message": "规划信息更新成功"
|
||||
}
|
||||
|
||||
@@ -130,6 +130,7 @@ class SceneData(BaseModel):
|
||||
|
||||
class ExpansionPlanUpdate(BaseModel):
|
||||
"""章节规划更新模型"""
|
||||
summary: Optional[str] = Field(None, description="章节情节概要")
|
||||
key_events: Optional[List[str]] = Field(None, description="关键事件列表")
|
||||
character_focus: Optional[List[str]] = Field(None, description="涉及角色列表")
|
||||
emotional_tone: Optional[str] = Field(None, description="情感基调")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Modal, Form, Input, InputNumber, Select, Tag, Space, Button, message } from 'antd';
|
||||
import { Modal, Form, Input, InputNumber, Select, Tag, Space, Button, message, Divider } from 'antd';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import { useState, useEffect } from 'react';
|
||||
import type { ExpansionPlanData, Character } from '../types';
|
||||
@@ -9,14 +9,16 @@ const { TextArea } = Input;
|
||||
interface ExpansionPlanEditorProps {
|
||||
visible: boolean;
|
||||
planData: ExpansionPlanData | null;
|
||||
chapterSummary: string | null;
|
||||
projectId: string;
|
||||
onSave: (data: ExpansionPlanData) => Promise<void>;
|
||||
onSave: (data: ExpansionPlanData & { summary?: string }) => Promise<void>;
|
||||
onCancel: () => void;
|
||||
}
|
||||
|
||||
export default function ExpansionPlanEditor({
|
||||
visible,
|
||||
planData,
|
||||
chapterSummary,
|
||||
projectId,
|
||||
onSave,
|
||||
onCancel
|
||||
@@ -69,24 +71,29 @@ export default function ExpansionPlanEditor({
|
||||
}
|
||||
};
|
||||
|
||||
// 当planData变化时更新状态
|
||||
// 当planData或chapterSummary变化时更新状态
|
||||
useEffect(() => {
|
||||
if (planData) {
|
||||
setKeyEvents(planData.key_events || []);
|
||||
setCharacters(planData.character_focus || []);
|
||||
form.setFieldsValue({
|
||||
emotional_tone: planData.emotional_tone,
|
||||
narrative_goal: planData.narrative_goal,
|
||||
conflict_type: planData.conflict_type,
|
||||
estimated_words: planData.estimated_words
|
||||
});
|
||||
} else {
|
||||
// 重置状态
|
||||
setKeyEvents([]);
|
||||
setCharacters([]);
|
||||
form.resetFields();
|
||||
if (visible) {
|
||||
if (planData) {
|
||||
setKeyEvents(planData.key_events || []);
|
||||
setCharacters(planData.character_focus || []);
|
||||
form.setFieldsValue({
|
||||
summary: chapterSummary || '',
|
||||
emotional_tone: planData.emotional_tone,
|
||||
narrative_goal: planData.narrative_goal,
|
||||
conflict_type: planData.conflict_type,
|
||||
estimated_words: planData.estimated_words
|
||||
});
|
||||
} else {
|
||||
// 重置状态
|
||||
setKeyEvents([]);
|
||||
setCharacters([]);
|
||||
form.setFieldsValue({
|
||||
summary: chapterSummary || ''
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [planData, form, visible]);
|
||||
}, [planData, chapterSummary, form, visible]);
|
||||
|
||||
const handleAddKeyEvent = () => {
|
||||
if (keyEventInput.trim()) {
|
||||
@@ -120,7 +127,8 @@ export default function ExpansionPlanEditor({
|
||||
return;
|
||||
}
|
||||
|
||||
const updatedPlan: ExpansionPlanData = {
|
||||
const updatedPlan: ExpansionPlanData & { summary?: string } = {
|
||||
summary: values.summary,
|
||||
key_events: keyEvents,
|
||||
character_focus: characters,
|
||||
emotional_tone: values.emotional_tone,
|
||||
@@ -173,8 +181,24 @@ export default function ExpansionPlanEditor({
|
||||
estimated_words: 3000
|
||||
}}
|
||||
>
|
||||
{/* 情节概要 */}
|
||||
<Form.Item
|
||||
label="情节概要"
|
||||
name="summary"
|
||||
tooltip="简要描述本章的主要情节和故事走向"
|
||||
>
|
||||
<TextArea
|
||||
rows={3}
|
||||
placeholder="简要描述本章的主要情节,例如:主角遇到意外事件,开始了一段新的冒险..."
|
||||
maxLength={500}
|
||||
showCount
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Divider orientation="left">详细规划</Divider>
|
||||
|
||||
{/* 关键事件 */}
|
||||
<Form.Item
|
||||
<Form.Item
|
||||
label="关键事件"
|
||||
tooltip="至少添加一个关键事件"
|
||||
required
|
||||
|
||||
@@ -2045,6 +2045,7 @@ export default function Chapters() {
|
||||
<ExpansionPlanEditor
|
||||
visible={planEditorVisible}
|
||||
planData={parsedPlanData}
|
||||
chapterSummary={editingPlanChapter.summary || null}
|
||||
projectId={currentProject.id}
|
||||
onSave={handleSavePlan}
|
||||
onCancel={() => {
|
||||
|
||||
Reference in New Issue
Block a user