Commit b4204fda by Liu

fix:工具按钮将“通用模型”改为“制度活化”&&按钮顺序

parent 6d1bb26e
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
// }, // },
// { // {
// toolId: 'general-mode', // toolId: 'general-mode',
// toolName: '通用模式', // toolName: '制度活化',
// toolContent: 'https://sit-wechat.guominpension.com/underwrite', // toolContent: 'https://sit-wechat.guominpension.com/underwrite',
// toolIcon: 'http://p-cf-co-1255000025.cos.bj.csyun001.ccbcos.co/tool-normal.svg', // toolIcon: 'http://p-cf-co-1255000025.cos.bj.csyun001.ccbcos.co/tool-normal.svg',
// toolType: '01', // toolType: '01',
......
...@@ -114,13 +114,13 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -114,13 +114,13 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
useEffect(() => { useEffect(() => {
const syncSessionToolId = () => { const syncSessionToolId = () => {
const storedToolId = safeSessionStorageGetItem('currentToolId') const storedToolId = safeSessionStorageGetItem('currentToolId')
// 如果 currentToolId 是空字符串,视为 null,确保通用模式能正确高亮 // 如果 currentToolId 是空字符串,视为 null,确保制度活化能正确高亮
setSessionToolId(storedToolId && storedToolId.trim() ? storedToolId : null) setSessionToolId(storedToolId && storedToolId.trim() ? storedToolId : null)
} }
syncSessionToolId() syncSessionToolId()
window.addEventListener('storage', syncSessionToolId) window.addEventListener('storage', syncSessionToolId)
// 监听强制重置为通用模式的事件(登录成功后触发) // 监听强制重置为制度活化的事件(登录成功后触发)
const handleForceReset = () => { const handleForceReset = () => {
// 强制同步 sessionStorage(此时应该已经被清除了) // 强制同步 sessionStorage(此时应该已经被清除了)
syncSessionToolId() syncSessionToolId()
...@@ -128,7 +128,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -128,7 +128,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
if (currentToolId) { if (currentToolId) {
dispatch(clearCurrentToolId()) dispatch(clearCurrentToolId())
} }
// 强制设置为通用模式 // 强制设置为制度活化
setSelectedToolId(null) setSelectedToolId(null)
setIsToolBtnActive(true) setIsToolBtnActive(true)
} }
...@@ -143,7 +143,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -143,7 +143,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
// 当路由变化时,同步更新 sessionToolId(因为 storage 事件不会在同标签页触发) // 当路由变化时,同步更新 sessionToolId(因为 storage 事件不会在同标签页触发)
useEffect(() => { useEffect(() => {
const storedToolId = safeSessionStorageGetItem('currentToolId') const storedToolId = safeSessionStorageGetItem('currentToolId')
// 如果 currentToolId 是空字符串,视为 null,确保通用模式能正确高亮 // 如果 currentToolId 是空字符串,视为 null,确保制度活化能正确高亮
setSessionToolId(storedToolId && storedToolId.trim() ? storedToolId : null) setSessionToolId(storedToolId && storedToolId.trim() ? storedToolId : null)
// 当路由切换(如点击历史记录)时,同步最新的 sessionStorage,避免同标签页删除后状态不同步 // 当路由切换(如点击历史记录)时,同步最新的 sessionStorage,避免同标签页删除后状态不同步
}, [toolIdFromUrl, location.pathname]) }, [toolIdFromUrl, location.pathname])
...@@ -176,7 +176,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -176,7 +176,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
return return
if (checkAuth()) { if (checkAuth()) {
if (content.trim()) { if (content.trim()) {
// 只在提质增效模式下传递 toolId,通用模式不传 // 只在提质增效模式下传递 toolId,制度活化不传
let toolId: string | undefined let toolId: string | undefined
if (selectedToolId) { if (selectedToolId) {
...@@ -184,7 +184,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -184,7 +184,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
toolId = selectedToolId toolId = selectedToolId
} }
else { else {
// 通用模式:不传递 toolId // 制度活化:不传递 toolId
toolId = undefined toolId = undefined
} }
onSubmit?.(content.trim(), toolId) onSubmit?.(content.trim(), toolId)
...@@ -214,7 +214,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -214,7 +214,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
document.execCommand('insertText', false, text) document.execCommand('insertText', false, text)
} }
// 处理通用模式按钮点击:先创建新会话 // 处理制度活化按钮点击:先创建新会话
const handleGeneralClick = async () => { const handleGeneralClick = async () => {
if (!checkAuth()) if (!checkAuth())
return return
...@@ -228,7 +228,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -228,7 +228,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
setSessionToolId(null) setSessionToolId(null)
setShowToolQuestion(false) setShowToolQuestion(false)
// 先通知上层更新欢迎语(即便后续接口异常也能生效) // 先通知上层更新欢迎语(即便后续接口异常也能生效)
onToolClick?.(true, undefined, '通用模式', false) onToolClick?.(true, undefined, '制度活化', false)
// 清空路由中的 toolId 参数 // 清空路由中的 toolId 参数
if (toolIdFromUrl) { if (toolIdFromUrl) {
const newSearchParams = new URLSearchParams(searchParams) const newSearchParams = new URLSearchParams(searchParams)
...@@ -402,8 +402,8 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -402,8 +402,8 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
const toolIdStr = String(tool.toolId) const toolIdStr = String(tool.toolId)
const isSelectedByState = selectedToolId && toolIdStr === String(selectedToolId) const isSelectedByState = selectedToolId && toolIdStr === String(selectedToolId)
const isSelectedBySession = !selectedToolId && sessionToolId && toolIdStr === String(sessionToolId) const isSelectedBySession = !selectedToolId && sessionToolId && toolIdStr === String(sessionToolId)
// 通用模式高亮:路由内没有 toolId 或 toolId 为空时默认高亮,点击后也要高亮 // 制度活化高亮:路由内没有 toolId 或 toolId 为空时默认高亮,点击后也要高亮
const isGeneralMode = tool.toolName === '通用模式' && isToolBtnActive && !selectedToolId && !sessionToolId && !toolIdFromUrl const isGeneralMode = tool.toolName === '制度活化' && isToolBtnActive && !selectedToolId && !sessionToolId && !toolIdFromUrl
const isSelected = isSelectedByState || isSelectedBySession || isGeneralMode const isSelected = isSelectedByState || isSelectedBySession || isGeneralMode
const baseBtnClass const baseBtnClass
...@@ -418,7 +418,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -418,7 +418,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
// 高亮状态直接返回,避免重复触发 // 高亮状态直接返回,避免重复触发
if (isSelected) if (isSelected)
return return
if (tool.toolName === '通用模式') if (tool.toolName === '制度活化')
await handleGeneralClick() await handleGeneralClick()
else else
await handleToolClick(tool) await handleToolClick(tool)
......
...@@ -53,7 +53,7 @@ export const HistoryBarList: React.FC<HistoryBarListProps> = ({ searchValue, onS ...@@ -53,7 +53,7 @@ export const HistoryBarList: React.FC<HistoryBarListProps> = ({ searchValue, onS
// 通知首页根据对应 toolId 重新拉取常见问题(与底部工具按钮保持一致逻辑) // 通知首页根据对应 toolId 重新拉取常见问题(与底部工具按钮保持一致逻辑)
window.dispatchEvent(new CustomEvent('toolButtonClick', { window.dispatchEvent(new CustomEvent('toolButtonClick', {
detail: { detail: {
// 有 toolId 表示工具模式,没 toolId 表示通用模式 // 有 toolId 表示工具模式,没 toolId 表示制度活化
isToolBtn: !conversation.toolId, isToolBtn: !conversation.toolId,
toolId: conversation.toolId || '', toolId: conversation.toolId || '',
toolName: '', toolName: '',
......
...@@ -63,7 +63,7 @@ export const Chat: React.FC = () => { ...@@ -63,7 +63,7 @@ export const Chat: React.FC = () => {
const toolIdFromStateRef = useRef<string | null | undefined>(undefined) const toolIdFromStateRef = useRef<string | null | undefined>(undefined)
// 当外部系统直接以 /chat/:id 链接进入(没有 location.state,且 URL 中也没有 toolId)时, // 当外部系统直接以 /chat/:id 链接进入(没有 location.state,且 URL 中也没有 toolId)时,
// 视为一次新的会话入口:重置为通用模式,清除历史遗留的工具模式状态 // 视为一次新的会话入口:重置为制度活化,清除历史遗留的工具模式状态
useEffect(() => { useEffect(() => {
if (!location.state && !rawToolIdFromUrl) { if (!location.state && !rawToolIdFromUrl) {
// 20251211 调试:无 URL、无 state 时清除 toolId // 20251211 调试:无 URL、无 state 时清除 toolId
...@@ -95,7 +95,7 @@ export const Chat: React.FC = () => { ...@@ -95,7 +95,7 @@ export const Chat: React.FC = () => {
currentUrl.searchParams.delete('toolId') currentUrl.searchParams.delete('toolId')
window.history.replaceState({}, '', currentUrl.toString()) window.history.replaceState({}, '', currentUrl.toString())
} }
// 4. 触发自定义事件,通知 ChatEditor 强制重置为通用模式 // 4. 触发自定义事件,通知 ChatEditor 强制重置为制度活化
window.dispatchEvent(new CustomEvent('forceResetToGeneralMode')) window.dispatchEvent(new CustomEvent('forceResetToGeneralMode'))
// 同步 react-router 的 searchParams 状态 // 同步 react-router 的 searchParams 状态
...@@ -450,10 +450,10 @@ export const Chat: React.FC = () => { ...@@ -450,10 +450,10 @@ export const Chat: React.FC = () => {
} }
else { else {
// 如果 qaRecords 和 conversation 中都没有 toolId // 如果 qaRecords 和 conversation 中都没有 toolId
// 如果有历史记录但没有 toolId,说明是通用模式,应该清除 // 如果有历史记录但没有 toolId,说明是制度活化,应该清除
if (hasQaRecords && currentToolId) { if (hasQaRecords && currentToolId) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log('[Chat] 清除 toolId (qaRecords 中有记录但没有 toolId,通用模式)') console.log('[Chat] 清除 toolId (qaRecords 中有记录但没有 toolId,制度活化)')
dispatch(clearCurrentToolId()) dispatch(clearCurrentToolId())
} }
// 如果没有历史记录,可能是新会话,但如果 Redux 中已经有 toolId(从 HistoryBarList 设置的),暂时保留 // 如果没有历史记录,可能是新会话,但如果 Redux 中已经有 toolId(从 HistoryBarList 设置的),暂时保留
...@@ -536,8 +536,8 @@ export const Chat: React.FC = () => { ...@@ -536,8 +536,8 @@ export const Chat: React.FC = () => {
} }
} }
else { else {
// 通用模式 // 制度活化
setCurrentToolName('通用模式') setCurrentToolName('制度活化')
} }
} }
getToolNameFromToolId() getToolNameFromToolId()
...@@ -555,7 +555,7 @@ export const Chat: React.FC = () => { ...@@ -555,7 +555,7 @@ export const Chat: React.FC = () => {
dispatch(setCurrentToolId(toolId)) dispatch(setCurrentToolId(toolId))
} }
else { else {
// 通用模式,清除 toolId // 制度活化,清除 toolId
dispatch(clearCurrentToolId()) dispatch(clearCurrentToolId())
} }
} }
......
...@@ -112,7 +112,7 @@ export const Home: React.FC = () => { ...@@ -112,7 +112,7 @@ export const Home: React.FC = () => {
// 处理工具按钮点击 // 处理工具按钮点击
const _handleToolClick = useCallback(async (isToolBtn: boolean, toolId?: string, ignoreUrlToolId?: boolean) => { const _handleToolClick = useCallback(async (isToolBtn: boolean, toolId?: string, ignoreUrlToolId?: boolean) => {
// 提质增效模式 / 数据助手 / 通用模式:都先清空数据,重新拉常见问题 // 提质增效模式 / 数据助手 / 制度活化:都先清空数据,重新拉常见问题
setOtherQuestions((prev: any) => ({ setOtherQuestions((prev: any) => ({
...prev, ...prev,
content: [], content: [],
...@@ -132,7 +132,7 @@ export const Home: React.FC = () => { ...@@ -132,7 +132,7 @@ export const Home: React.FC = () => {
let finalToolId = toolId || '' let finalToolId = toolId || ''
// 场景:首页首次挂载(ignoreUrlToolId === true)且为通用模式(!isToolBtn && !toolId) // 场景:首页首次挂载(ignoreUrlToolId === true)且为制度活化(!isToolBtn && !toolId)
// 此时无论 sessionStorage 中是否残留上一次的 toolId,都强制使用空字符串,避免带入历史工具 ID // 此时无论 sessionStorage 中是否残留上一次的 toolId,都强制使用空字符串,避免带入历史工具 ID
if (ignoreUrlToolId && !isToolBtn && !toolId) { if (ignoreUrlToolId && !isToolBtn && !toolId) {
finalToolId = '' finalToolId = ''
...@@ -141,7 +141,7 @@ export const Home: React.FC = () => { ...@@ -141,7 +141,7 @@ export const Home: React.FC = () => {
finalToolId = '' finalToolId = ''
} }
else if (!finalToolId && !isToolBtn) { else if (!finalToolId && !isToolBtn) {
// 仅在工具模式下才使用回退逻辑,避免通用模式误用上一次的 toolId // 仅在工具模式下才使用回退逻辑,避免制度活化误用上一次的 toolId
finalToolId = storedToolId finalToolId = storedToolId
} }
...@@ -186,7 +186,7 @@ export const Home: React.FC = () => { ...@@ -186,7 +186,7 @@ export const Home: React.FC = () => {
dispatch(setCurrentToolId(toolId)) dispatch(setCurrentToolId(toolId))
} }
else { else {
// 通用模式,清除 toolId // 制度活化,清除 toolId
dispatch(clearCurrentToolId()) dispatch(clearCurrentToolId())
} }
...@@ -242,7 +242,7 @@ export const Home: React.FC = () => { ...@@ -242,7 +242,7 @@ export const Home: React.FC = () => {
storageArea: localStorage, storageArea: localStorage,
}), }),
) )
// 触发自定义事件,通知 ChatEditor 强制重置为通用模式 // 触发自定义事件,通知 ChatEditor 强制重置为制度活化
window.dispatchEvent(new CustomEvent('forceResetToGeneralMode')) window.dispatchEvent(new CustomEvent('forceResetToGeneralMode'))
initConversation() initConversation()
dispatch(fetchConversations()) dispatch(fetchConversations())
...@@ -278,7 +278,7 @@ export const Home: React.FC = () => { ...@@ -278,7 +278,7 @@ export const Home: React.FC = () => {
storageArea: localStorage, storageArea: localStorage,
}), }),
) )
// 触发自定义事件,通知 ChatEditor 强制重置为通用模式 // 触发自定义事件,通知 ChatEditor 强制重置为制度活化
window.dispatchEvent(new CustomEvent('forceResetToGeneralMode')) window.dispatchEvent(new CustomEvent('forceResetToGeneralMode'))
initConversation() initConversation()
dispatch(fetchConversations()) dispatch(fetchConversations())
...@@ -301,7 +301,7 @@ export const Home: React.FC = () => { ...@@ -301,7 +301,7 @@ export const Home: React.FC = () => {
// 只有登录成功(拿到 token)后才拉业务接口 // 只有登录成功(拿到 token)后才拉业务接口
if (!token) if (!token)
return return
// 首页首次挂载时重置为通用模式 // 首页首次挂载时重置为制度活化
// 1. 清除 Redux 中的 currentToolId // 1. 清除 Redux 中的 currentToolId
dispatch(clearCurrentToolId()) dispatch(clearCurrentToolId())
}, [token, dispatch, _handleToolClick]) }, [token, dispatch, _handleToolClick])
......
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