提交 00e25eb6 authored 作者: 王鹏飞's avatar 王鹏飞

refactor: simplify chapter selection logic in book sections and remove '天工' AI option.

上级 b17c3bae
...@@ -8,7 +8,7 @@ export function useAI() { ...@@ -8,7 +8,7 @@ export function useAI() {
{ label: '文心一言', value: 'yiyan' }, { label: '文心一言', value: 'yiyan' },
{ label: 'DeepSeek', value: 'deepseek' }, { label: 'DeepSeek', value: 'deepseek' },
{ label: '通义千问', value: 'qwen' }, { label: '通义千问', value: 'qwen' },
{ label: '天工', value: 'tiangong' }, // { label: '天工', value: 'tiangong' },
] ]
const [ai, setAI] = useState(localStorage.getItem('ai') || 'yiyan') const [ai, setAI] = useState(localStorage.getItem('ai') || 'yiyan')
......
...@@ -156,54 +156,40 @@ const Examine = () => { ...@@ -156,54 +156,40 @@ const Examine = () => {
const onExpand = expandedKeys => { const onExpand = expandedKeys => {
setExpandedKeys(expandedKeys) setExpandedKeys(expandedKeys)
} }
const handleSelect = async (checkedKeys, info) => { const handleSelect = async (selectedKeys, info) => {
const { key } = info.node if (!info.node) return
const childInKey = findTreeElementByKey(gData, 'key', key) const { key, title } = info.node
if (childInKey.children && childInKey.children.length > 0) { // 保持选中状态,防止重复点击导致选中状态消失
clearInterval(saveInterRef.current) setCheckedKeys([key])
// 进行展开操作
const tempExpandeds = JSON.parse(JSON.stringify(expandedKeys)) // 如果点击的是当前已经选中的章节,且没有发生章节切换,则直接返回
let newExpand = '' if (key === chapterId) {
if (expandedKeys.includes(key)) {
newExpand = tempExpandeds.filter(item => parseInt(item) !== parseInt(key))
} else {
newExpand = [...tempExpandeds, key]
}
setExpandedKeys(newExpand)
setCheckedKeys([key])
return return
} else { }
const { key, title } = info.node
if (info.selected === false) {
setLoading(true)
setChapterId(key)
setCheckedKeys([key])
setNowTitle(title)
setLoading(false)
} else {
setLoading(true)
clearInterval(saveInterRef.current)
await saveContent()
if (key !== chapterId) { setLoading(true)
editorRef.current.editor.clear() // 切换章节前清理保存定时器并执行一次保存
} clearInterval(saveInterRef.current)
setLoading(true) await saveContent()
setChapterId(checkedKeys[0])
setCheckedKeys([checkedKeys[0]]) // 清理旧内容
setNowTitle(info.node.title) if (editorRef.current && editorRef.current.editor) {
setLoading(false) editorRef.current.editor.clear()
}
} }
// 设置新章节 ID,触发 useEffect 加载数据
setChapterId(key)
setNowTitle(title)
setLoading(false)
} }
useEffect(() => { useEffect(() => {
getChapterTreeList() getChapterTreeList()
}, []) }, [])
useEffect(() => { useEffect(() => {
if (chapterId) { if (chapterId) {
setCheckedKeys([chapterId])
getChapterVal() getChapterVal()
} }
}, [chapterId]) }, [chapterId])
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论