Commit b4204fda by Liu

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

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