Commit be60ab98 by Liu

fix:清空记录时不展示分割线

parent 80e91beb
......@@ -392,8 +392,23 @@ export const TacticsChat: React.FC = () => {
// 一次性添加用户问题和空的AI回答;如果不需要问题(自动触发场景),只添加 AI 占位
const shouldIncludeQuestion = extra?.includeQuestion !== false && !!question
const isReanalyze = extra?.isReanalyze === true
// 同步计算分割线位置(基于当前 allItems 长度)
const nextDividerIndex = isReanalyze ? allItems.length + (shouldIncludeQuestion ? 2 : 1) : null
// 重新分析时,在添加新记录之前计算分割线位置
// 分割线应该显示在历史记录之后、新记录之前
// 渲染时使用 divider.index === index + 1 来匹配,所以分割线的 index 应该是新记录的位置
// 只有当存在历史记录时,才显示分割线
if (isReanalyze && hasHistory === true) {
// 基于当前 allItems 长度计算分割线位置
// 分割线会在新添加的第一个记录之前显示(即 prevItems.length + 1)
const nextDividerIndex = allItems.length + 1
const currentTime = formatCurrentTime()
setHistoryDividers((prev) => {
// 避免重复添加相同位置的分割线
if (prev.some(divider => divider.index === nextDividerIndex)) {
return prev
}
return [...prev, { index: nextDividerIndex, time: currentTime }]
})
}
setAllItems(prevItems => [
...prevItems,
...(shouldIncludeQuestion
......@@ -409,10 +424,6 @@ export const TacticsChat: React.FC = () => {
answerList: [{ answer: '' }],
} as ChatRecord,
])
if (isReanalyze && nextDividerIndex !== null) {
const currentTime = formatCurrentTime()
setHistoryDividers(prev => [...prev, { index: nextDividerIndex, time: currentTime }])
}
// 创建新的 AbortController
abortControllerRef.current = new AbortController()
......@@ -560,7 +571,9 @@ export const TacticsChat: React.FC = () => {
}
return processedMessages
})
setHasCleared(false)
// 如果是清除记录创建的新会话且没有历史记录,保持 hasCleared 为 true
setHasCleared(createdFromClearRef.current && !hasHistoryFlag)
setHistoryDividers([])
setHasHistory(hasHistoryFlag)
}
catch {
......@@ -576,7 +589,8 @@ export const TacticsChat: React.FC = () => {
}
return [{ role: 'system' } as ChatRecord]
})
setHasCleared(false)
// 如果是清除记录创建的新会话,保持 hasCleared 为 true
setHasCleared(createdFromClearRef.current)
setHistoryDividers([])
// 拉取失败时视为无历史记录,后续可按需触发自动提问
setHasHistory(false)
......@@ -605,7 +619,7 @@ export const TacticsChat: React.FC = () => {
// 清空对话列表,只保留欢迎语
setAllItems([{ role: 'system' } as ChatRecord])
setHasCleared(true)
setHistoryDividers([])
setHistoryDividers(() => [])
// 标记接下来创建的新会话来源于「清空记录」,用于阻止自动触发一次提问
createdFromClearRef.current = true
dispatch(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment