Commit d2762443 by Liu

fix:常见问题初始渲染

parent 0b968cbd
......@@ -110,6 +110,34 @@ export const Home: React.FC = () => {
}
}, [location.search])
// 首页首次挂载时拉取常见问题(强制 toolId 为空,避免带入历史值)
const handleInitialQuestions = useCallback(async () => {
// eslint-disable-next-line no-console
console.log('handleInitialQuestions: 首次挂载/登录后初始化常见问题,强制 toolId 为空')
setOtherQuestions((prev: any) => ({
...prev,
content: [],
}))
setIsDataLoaded(false)
try {
const res = await fetchEfficiencyQuestionList({
toolId: '',
})
if (res && res.data && res.data.questions) {
setOtherQuestions((prev: any) => ({
...prev,
content: res.data.questions || [],
}))
}
}
catch (error) {
console.error('首页初始化常见问题失败:', error)
}
finally {
setIsDataLoaded(true)
}
}, [])
// 处理工具按钮点击
const _handleToolClick = useCallback(async (isToolBtn: boolean, toolId?: string, ignoreUrlToolId?: boolean) => {
// 提质增效模式 / 数据助手 / 通用模式:都先清空数据,重新拉常见问题
......@@ -234,6 +262,8 @@ export const Home: React.FC = () => {
window.dispatchEvent(new CustomEvent('forceResetToGeneralMode'))
initConversation()
dispatch(fetchConversations())
// 登录成功后再拉取一次常见问题,强制 toolId 为空
handleInitialQuestions()
}
}
else {
......@@ -281,9 +311,11 @@ export const Home: React.FC = () => {
window.dispatchEvent(new CustomEvent('forceResetToGeneralMode'))
initConversation()
dispatch(fetchConversations())
// 登录成功后再拉取一次常见问题,强制 toolId 为空
handleInitialQuestions()
}
}
}, [setToken, dispatch])
}, [setToken, dispatch, handleInitialQuestions])
// 监听路由参数变化,提取 userRoles(确保路由参数被正确解析)
useEffect(() => {
......@@ -297,9 +329,9 @@ export const Home: React.FC = () => {
dispatch(clearCurrentToolId())
// 2. 清除 sessionStorage 中可能残留的 currentToolId,避免沿用上一次工具模式
// sessionStorage.removeItem('currentToolId')
// 3. 首页首次挂载时强制忽略路由中的 toolId,只按通用模式拉常见问题(toolId: '')
_handleToolClick(false, '', true)
}, []) // 依赖数组为空,只在组件挂载时执行一次
// 3. 首页首次挂载时仅使用空 toolId 拉取常见问题
handleInitialQuestions()
}, [handleInitialQuestions]) // 依赖数组为空,只在组件挂载时执行一次
return (
<div className={styles.homePage}>
......
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