From 6e603ee1a94c4a9b82bed2ecc56af188575000d6 Mon Sep 17 00:00:00 2001 From: xiamuceer Date: Mon, 5 Jan 2026 14:26:58 +0800 Subject: [PATCH] =?UTF-8?q?update:1.=E4=BF=AE=E5=A4=8D1-N=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=EF=BC=8C=E6=89=8B=E5=8A=A8=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=A4=A7=E7=BA=B2=E5=90=8E=EF=BC=8C=E5=86=8D=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E7=AB=A0=E8=8A=82=E6=97=A0=E6=B3=95=E6=89=BE?= =?UTF-8?q?=E5=88=B0=E5=A4=A7=E7=BA=B2=E9=97=AE=E9=A2=98=202.=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E7=AB=A0=E8=8A=82=E7=AE=A1=E7=90=86-=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=86=85=E5=AE=B9/=E6=89=B9=E9=87=8F=E7=94=9F?= =?UTF-8?q?=E6=88=90=20=E5=A2=9E=E5=8A=A0=E9=BB=98=E8=AE=A4=E5=AD=97?= =?UTF-8?q?=E6=95=B0=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/Chapters.tsx | 87 +++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 31 deletions(-) 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字(修改后自动记住)