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

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

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