diff --git a/frontend/src/pages/Chapters.tsx b/frontend/src/pages/Chapters.tsx index 7f95fe9..4e4b5a2 100644 --- a/frontend/src/pages/Chapters.tsx +++ b/frontend/src/pages/Chapters.tsx @@ -14,8 +14,37 @@ import ChapterReader from '../components/ChapterReader'; const { TextArea } = Input; +// localStorage 缓存键名 +const WORD_COUNT_CACHE_KEY = 'chapter_default_word_count'; +const DEFAULT_WORD_COUNT = 3000; + +// 从 localStorage 读取缓存的字数 +const getCachedWordCount = (): number => { + try { + const cached = localStorage.getItem(WORD_COUNT_CACHE_KEY); + if (cached) { + const value = parseInt(cached, 10); + if (!isNaN(value) && value >= 500 && value <= 10000) { + return value; + } + } + } catch (error) { + console.warn('读取字数缓存失败:', error); + } + return DEFAULT_WORD_COUNT; +}; + +// 保存字数到 localStorage +const setCachedWordCount = (value: number): void => { + try { + localStorage.setItem(WORD_COUNT_CACHE_KEY, String(value)); + } catch (error) { + console.warn('保存字数缓存失败:', error); + } +}; + export default function Chapters() { - const { currentProject, chapters, setCurrentChapter, setCurrentProject } = useStore(); + const { currentProject, chapters, outlines, setCurrentChapter, setCurrentProject } = useStore(); const [modal, contextHolder] = Modal.useModal(); const [isModalOpen, setIsModalOpen] = useState(false); const [isEditorOpen, setIsEditorOpen] = useState(false); @@ -28,7 +57,7 @@ export default function Chapters() { const contentTextAreaRef = useRef(null); const [writingStyles, setWritingStyles] = useState([]); const [selectedStyleId, setSelectedStyleId] = useState(); - const [targetWordCount, setTargetWordCount] = useState(3000); + const [targetWordCount, setTargetWordCount] = useState(getCachedWordCount); const [availableModels, setAvailableModels] = useState>([]); const [selectedModel, setSelectedModel] = useState(); const [batchSelectedModel, setBatchSelectedModel] = useState(); // 批量生成的模型选择 @@ -940,13 +969,13 @@ export default function Chapters() { // 设置批量生成的模型选择状态 setBatchSelectedModel(defaultModel || undefined); - // 重置表单并设置初始值 + // 重置表单并设置初始值(使用缓存的字数) batchForm.setFieldsValue({ startChapterNumber: firstIncompleteChapter.chapter_number, count: 5, enableAnalysis: false, styleId: selectedStyleId, - targetWordCount: 3000, + targetWordCount: getCachedWordCount(), }); setBatchGenerateVisible(true); @@ -997,27 +1026,14 @@ export default function Chapters() { tooltip="one-to-many模式下,章节必须关联到大纲" > @@ -1555,7 +1571,7 @@ export default function Chapters() { {!isMobile && ( {currentProject.outline_mode === 'one-to-one' - ? '传统模式:章节由大纲一对一管理,请在大纲页面操作' + ? '传统模式:章节由大纲管理,请在大纲页面操作' : '细化模式:章节可在大纲页面展开'} )} @@ -1993,7 +2009,7 @@ export default function Chapters() { name="title" tooltip={ currentProject.outline_mode === 'one-to-one' - ? "章节标题由大纲管理,建议在大纲页面统一修改" + ? "章节标题由大纲管理,请在大纲页面修改" : "一对多模式下可以修改章节标题" } rules={ @@ -2011,7 +2027,7 @@ export default function Chapters() { @@ -2161,7 +2177,7 @@ export default function Chapters() { }}> setTargetWordCount(value || 3000)} + onChange={(value) => { + const newValue = value || DEFAULT_WORD_COUNT; + setTargetWordCount(newValue); + setCachedWordCount(newValue); + }} disabled={isGenerating} style={{ width: '100%' }} formatter={(value) => `${value} 字`} @@ -2353,7 +2373,7 @@ export default function Chapters() { count: 5, enableAnalysis: true, // 强制启用同步分析 styleId: selectedStyleId, - targetWordCount: 3000, + targetWordCount: getCachedWordCount(), model: selectedModel, }} > @@ -2425,7 +2445,7 @@ export default function Chapters() { `${value} 字`} parser={(value) => value?.replace(' 字', '') as any} + onChange={(value) => { + if (value) { + setCachedWordCount(value); + } + }} />
- 建议范围:500-10000字,默认3000字 + 建议范围:500-10000字(修改后自动记住)