Commit 9f3fb994 by Liu

fix:提质增效下新建会话情况历史记录

parent 14c4bc50
......@@ -12,7 +12,8 @@ import { withAuth } from '@/auth/withAuth'
import { NAV_BAR_ITEMS } from '@/config/nav'
import { useAppDispatch, useAppSelector } from '@/store/hook'
import { isMobile } from '@/utils'
import { safeLocalStorageSetItem } from '@/lib/utils'
import { safeLocalStorageSetItem, waitForToken } from '@/lib/utils'
import { fetchUserQaRecordPage } from '@/api/conversation'
// import { User } from './components/User'
interface NavbarProps {
......@@ -137,10 +138,30 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
})
dispatch(clearNavigationFlag())
// 提质增效模式下,创建会话后自动调用提问接口(与 fetchSessionConversationId 后的逻辑保持一致)
// 使用 requestAnimationFrame 确保在下一个渲染周期执行,此时 Chat 组件已经挂载并且 currentIdRef.current 已经更新
if (isQualityImprovement) {
// 使用双重 requestAnimationFrame 确保在 DOM 更新后执行
// 提质增效模式下,创建会话后:
// 1. 使用新会话ID + toolId 主动拉取一次历史记录(与数据助手保持一致)
// 2. 再自动触发一次空问题提问(欢迎语)
if (isQualityImprovement && currentToolId) {
// 1) 拉取历史记录并通过自定义事件交给 Chat 渲染
;(async () => {
try {
await waitForToken()
const qaRes = await fetchUserQaRecordPage(currentConversationId, currentToolId)
window.dispatchEvent(new CustomEvent('toolHistoryLoaded', {
detail: {
conversationId: currentConversationId,
toolId: currentToolId,
// 这里不传 toolName,由 Chat 自己根据 currentToolId 解析名称
qaRecords: qaRes?.data || [],
},
}))
}
catch (error) {
console.error('[Navbar] 提质增效模式 - 创建会话后拉取历史记录失败:', error)
}
})()
// 2) 使用 requestAnimationFrame 确保在下一个渲染周期执行自动提问
requestAnimationFrame(() => {
requestAnimationFrame(() => {
window.dispatchEvent(new CustomEvent('autoSubmitQuestion', {
......
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