Commit e0072bcc by Liu

fix:制度活化提问参数

parent 762d6fff
...@@ -233,11 +233,16 @@ export const Chat: React.FC = () => { ...@@ -233,11 +233,16 @@ export const Chat: React.FC = () => {
conversationId: currentIdRef.current, conversationId: currentIdRef.current,
stream: true, stream: true,
productCode, productCode,
toolId: resolvedToolId, toolId: resolvedToolId ?? '',
} }
// 制度活化:toolId 为空字符串或 undefined
if (!resolvedToolId || resolvedToolId === '') {
requestBody.toolId = ''
requestBody.busiType = '01'
}
// 提质增效:toolId 为 6712395743241 // 提质增效:toolId 为 6712395743241
if (resolvedToolId === '6712395743241') { else if (resolvedToolId === '6712395743241') {
requestBody.busiType = '01' requestBody.busiType = '01'
requestBody.recordType = 'B00' requestBody.recordType = 'B00'
} }
...@@ -296,11 +301,15 @@ export const Chat: React.FC = () => { ...@@ -296,11 +301,15 @@ export const Chat: React.FC = () => {
// 如果从收藏页返回,触发事件通知 HomeNew 刷新问题列表 // 如果从收藏页返回,触发事件通知 HomeNew 刷新问题列表
if (fromCollect) { if (fromCollect) {
const eventToolId = toolId || currentToolId || safeSessionStorageGetItem('currentToolId') || ''
console.log('[Chat] 检测到从收藏页返回 (fromCollect=true) - 准备触发 refreshQuestionsFromCollect 事件')
console.log('[Chat] refreshQuestionsFromCollect - 传递的 toolId:', eventToolId)
window.dispatchEvent(new CustomEvent('refreshQuestionsFromCollect', { window.dispatchEvent(new CustomEvent('refreshQuestionsFromCollect', {
detail: { detail: {
toolId: toolId || currentToolId || safeSessionStorageGetItem('currentToolId') || '', toolId: eventToolId,
}, },
})) }))
console.log('[Chat] refreshQuestionsFromCollect 事件已触发')
} }
const res = await fetchUserQaRecordPage(conversationId, toolId || '') const res = await fetchUserQaRecordPage(conversationId, toolId || '')
console.log('qaRes chatEditor2222222', res) console.log('qaRes chatEditor2222222', res)
......
...@@ -111,6 +111,7 @@ export const Home: React.FC = () => { ...@@ -111,6 +111,7 @@ export const Home: React.FC = () => {
// 刷新问题列表 // 刷新问题列表
const handleRefreshQuestions = useCallback(async () => { const handleRefreshQuestions = useCallback(async () => {
console.log('[HomeNew] handleRefreshQuestions 开始调用 - 刷新常见问题列表')
// 先清空旧数据 // 先清空旧数据
setOtherQuestions((prev: any) => ({ setOtherQuestions((prev: any) => ({
...prev, ...prev,
...@@ -121,24 +122,32 @@ export const Home: React.FC = () => { ...@@ -121,24 +122,32 @@ export const Home: React.FC = () => {
try { try {
// 获取当前的 toolId,只从 sessionStorage 获取 // 获取当前的 toolId,只从 sessionStorage 获取
const sessionToolId = safeSessionStorageGetItem('currentToolId') || '' const sessionToolId = safeSessionStorageGetItem('currentToolId') || ''
console.log('[HomeNew] handleRefreshQuestions - 当前 toolId:', sessionToolId)
// 调用接口重新获取问题列表 // 调用接口重新获取问题列表
console.log('[HomeNew] handleRefreshQuestions - 开始调用 fetchEfficiencyQuestionList 接口')
const res = await fetchEfficiencyQuestionList({ const res = await fetchEfficiencyQuestionList({
toolId: sessionToolId, toolId: sessionToolId,
}) })
console.log('[HomeNew] handleRefreshQuestions - fetchEfficiencyQuestionList 接口返回:', res)
if (res && res.data && res.data.questions) { if (res && res.data && res.data.questions) {
console.log('[HomeNew] handleRefreshQuestions - 获取到问题数量:', res.data.questions.length)
setOtherQuestions((prev: any) => ({ setOtherQuestions((prev: any) => ({
...prev, ...prev,
content: res.data.questions || [], content: res.data.questions || [],
})) }))
} }
else {
console.log('[HomeNew] handleRefreshQuestions - 未获取到问题数据')
}
} }
catch (error) { catch (error) {
console.error('刷新问题列表失败:', error) console.error('[HomeNew] handleRefreshQuestions - 刷新问题列表失败:', error)
throw error // 抛出错误,让 QuestionList 组件处理 throw error // 抛出错误,让 QuestionList 组件处理
} }
finally { finally {
setIsDataLoaded(true) // 无论成功失败都标记为已加载 setIsDataLoaded(true) // 无论成功失败都标记为已加载
console.log('[HomeNew] handleRefreshQuestions - 调用完成')
} }
}, [location.search]) }, [location.search])
...@@ -219,12 +228,16 @@ export const Home: React.FC = () => { ...@@ -219,12 +228,16 @@ export const Home: React.FC = () => {
// 监听从收藏返回时刷新问题列表的事件 // 监听从收藏返回时刷新问题列表的事件
useEffect(() => { useEffect(() => {
const handleRefreshQuestionsFromCollect = (event: CustomEvent) => { const handleRefreshQuestionsFromCollect = (event: CustomEvent) => {
console.log('[HomeNew] 监听到 refreshQuestionsFromCollect 事件 - 从收藏页面返回')
const { toolId } = event.detail const { toolId } = event.detail
console.log('[HomeNew] refreshQuestionsFromCollect - 接收到的 toolId:', toolId)
// 如果传递了 toolId,先更新 sessionStorage,确保刷新时使用正确的 toolId // 如果传递了 toolId,先更新 sessionStorage,确保刷新时使用正确的 toolId
if (toolId) { if (toolId) {
console.log('[HomeNew] refreshQuestionsFromCollect - 更新 sessionStorage 中的 currentToolId:', toolId)
safeSessionStorageSetItem('currentToolId', toolId) safeSessionStorageSetItem('currentToolId', toolId)
} }
// 刷新问题列表,会调用 generate_question 接口 // 刷新问题列表,会调用 generate_question 接口
console.log('[HomeNew] refreshQuestionsFromCollect - 开始调用 handleRefreshQuestions')
handleRefreshQuestions() handleRefreshQuestions()
} }
window.addEventListener('refreshQuestionsFromCollect', handleRefreshQuestionsFromCollect as EventListener) window.addEventListener('refreshQuestionsFromCollect', handleRefreshQuestionsFromCollect as EventListener)
...@@ -402,12 +415,18 @@ export const Home: React.FC = () => { ...@@ -402,12 +415,18 @@ export const Home: React.FC = () => {
const currentPath = location.pathname const currentPath = location.pathname
const prevPath = prevPathRef.current const prevPath = prevPathRef.current
console.log('[HomeNew] 路径变化检测 - 当前路径:', currentPath, '上一路径:', prevPath)
// 检测从收藏页面返回到首页(避免首次挂载误触发) // 检测从收藏页面返回到首页(避免首次挂载误触发)
if (prevPath && prevPath !== currentPath && prevPath === '/collect' && (currentPath === '/' || currentPath === '/home')) { if (prevPath && prevPath !== currentPath && prevPath === '/collect' && (currentPath === '/' || currentPath === '/home')) {
console.log('[HomeNew] 检测到从收藏页面返回 - 从 /collect 返回到首页')
// 确保已登录后再调用接口 // 确保已登录后再调用接口
if (token) { if (token) {
console.log('[HomeNew] 已登录,开始调用 handleRefreshQuestions')
handleRefreshQuestions() handleRefreshQuestions()
} }
else {
console.log('[HomeNew] 未登录,跳过刷新问题列表')
}
} }
// 更新上一次路径 // 更新上一次路径
......
...@@ -62,12 +62,16 @@ export const createConversation = createAsyncThunk< ...@@ -62,12 +62,16 @@ export const createConversation = createAsyncThunk<
{ state: { conversation: ConversationState } } { state: { conversation: ConversationState } }
>( >(
'conversation/createConversation', 'conversation/createConversation',
async ({ conversationData, shouldNavigate, shouldSendQuestion }, { dispatch, getState }) => { async ({ conversationData, shouldNavigate, shouldSendQuestion }, { dispatch }) => {
const state = getState() // 从缓存中获取 toolId 作为 busiId
const resolvedToolId = conversationData.toolId ?? state.conversation.currentToolId const cachedToolId = typeof window !== 'undefined' ? sessionStorage.getItem('currentToolId') : null
const busiId = cachedToolId || ''
// 排除 toolId 字段,只传递 busiId 和 busiType
const { toolId, ...restConversationData } = conversationData
const requestPayload = { const requestPayload = {
...conversationData, ...restConversationData,
...(resolvedToolId ? { toolId: resolvedToolId } : {}), busiId,
busiType: '01',
} }
const response = await fetchCreateConversation(requestPayload) const response = await fetchCreateConversation(requestPayload)
const newConversation = response.data const newConversation = response.data
......
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