Commit 8537a077 by Liu

fix:分割线展示

parent be60ab98
...@@ -393,21 +393,24 @@ export const TacticsChat: React.FC = () => { ...@@ -393,21 +393,24 @@ export const TacticsChat: React.FC = () => {
const shouldIncludeQuestion = extra?.includeQuestion !== false && !!question const shouldIncludeQuestion = extra?.includeQuestion !== false && !!question
const isReanalyze = extra?.isReanalyze === true const isReanalyze = extra?.isReanalyze === true
// 重新分析时,在添加新记录之前计算分割线位置 // 重新分析时,在添加新记录之前计算分割线位置
// 分割线应该显示在历史记录之后、新记录之前 // 分割线应该显示在已有对话记录之后、新记录之前
// 渲染时使用 divider.index === index + 1 来匹配,所以分割线的 index 应该是新记录的位置 // 渲染时使用 divider.index === index + 1 来匹配,所以分割线的 index 应该是新记录的位置
// 只有当存在历史记录时,才显示分割线 // 判断 allItems 中是否存在除了 system 之外的记录(user 或 ai)
if (isReanalyze && hasHistory === true) { if (isReanalyze) {
// 基于当前 allItems 长度计算分割线位置 const hasExistingRecords = allItems.some(item => item.role !== 'system')
// 分割线会在新添加的第一个记录之前显示(即 prevItems.length + 1) if (hasExistingRecords) {
const nextDividerIndex = allItems.length + 1 // 基于当前 allItems 长度计算分割线位置
const currentTime = formatCurrentTime() // 分割线会在新添加的第一个记录之前显示(即 prevItems.length + 1)
setHistoryDividers((prev) => { const nextDividerIndex = allItems.length + 1
// 避免重复添加相同位置的分割线 const currentTime = formatCurrentTime()
if (prev.some(divider => divider.index === nextDividerIndex)) { setHistoryDividers((prev) => {
return prev // 避免重复添加相同位置的分割线
} if (prev.some(divider => divider.index === nextDividerIndex)) {
return [...prev, { index: nextDividerIndex, time: currentTime }] return prev
}) }
return [...prev, { index: nextDividerIndex, time: currentTime }]
})
}
} }
setAllItems(prevItems => [ setAllItems(prevItems => [
...prevItems, ...prevItems,
......
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