Commit 749ccdec by Liu

fix:欢迎语

parent 276e093c
...@@ -40,14 +40,13 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -40,14 +40,13 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
const [searchParams, setSearchParams] = useSearchParams() const [searchParams, setSearchParams] = useSearchParams()
const location = useLocation() const location = useLocation()
const toolIdFromUrl = searchParams.get('toolId') const toolIdFromUrl = searchParams.get('toolId')
const fromCollect = location.state?.fromCollect
// 获取工具列表 // 获取工具列表
const getToolList = async () => { const getToolList = async () => {
try { try {
// 从路由中获取 userRoles 参数 // 从路由中获取 userRoles 参数
const userRoles = getUserRolesForApi() const userRoles = getUserRolesForApi()
// eslint-disable-next-line no-console
console.log('[ChatEditor] 获取到的 userRoles 参数:', userRoles, '类型:', Array.isArray(userRoles) ? 'array' : typeof userRoles)
// 调用真实 API 获取工具列表 // 调用真实 API 获取工具列表
const res = await fetchToolList({ userRoles }) const res = await fetchToolList({ userRoles })
if (res?.data && Array.isArray(res.data) && res.data.length > 0) { if (res?.data && Array.isArray(res.data) && res.data.length > 0) {
...@@ -61,7 +60,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -61,7 +60,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
// 根据 currentToolId 以及 sessionStorage 中的记录决定高亮逻辑 // 根据 currentToolId 以及 sessionStorage 中的记录决定高亮逻辑
useEffect(() => { useEffect(() => {
if (currentToolId && !sessionToolId) { if (currentToolId && !sessionToolId && !fromCollect) {
// 清除过期的 Redux 值 // 清除过期的 Redux 值
dispatch(clearCurrentToolId()) dispatch(clearCurrentToolId())
// 如果 URL 中还有 toolId,也清除它 // 如果 URL 中还有 toolId,也清除它
...@@ -108,7 +107,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -108,7 +107,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
setSelectedToolId(null) setSelectedToolId(null)
setIsToolBtnActive(true) setIsToolBtnActive(true)
} }
}, [currentToolId, sessionToolId, toolIdFromUrl, searchParams, setSearchParams]) }, [currentToolId, sessionToolId, toolIdFromUrl, searchParams, setSearchParams, fromCollect])
// 监听 sessionStorage 中的 currentToolId(历史点击时写入)来辅助高亮逻辑 // 监听 sessionStorage 中的 currentToolId(历史点击时写入)来辅助高亮逻辑
useEffect(() => { useEffect(() => {
...@@ -226,6 +225,8 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -226,6 +225,8 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
safeSessionStorageRemoveItem('currentToolId') safeSessionStorageRemoveItem('currentToolId')
setSessionToolId(null) setSessionToolId(null)
setShowToolQuestion(false) setShowToolQuestion(false)
// 先通知上层更新欢迎语(即便后续接口异常也能生效)
onToolClick?.(true, undefined, '通用模式', false)
// 清空路由中的 toolId 参数 // 清空路由中的 toolId 参数
if (toolIdFromUrl) { if (toolIdFromUrl) {
const newSearchParams = new URLSearchParams(searchParams) const newSearchParams = new URLSearchParams(searchParams)
...@@ -238,7 +239,6 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -238,7 +239,6 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
shouldNavigate: true, shouldNavigate: true,
shouldSendQuestion: '', shouldSendQuestion: '',
})).unwrap() })).unwrap()
onToolClick?.(true, undefined, '通用模式', false)
} }
catch (error) { catch (error) {
console.error('创建会话失败:', error) console.error('创建会话失败:', error)
...@@ -260,13 +260,14 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -260,13 +260,14 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
setIsToolBtnActive(false) setIsToolBtnActive(false)
safeSessionStorageSetItem('currentToolId', tool.toolId) safeSessionStorageSetItem('currentToolId', tool.toolId)
setSessionToolId(tool.toolId) setSessionToolId(tool.toolId)
// 先通知上层更新欢迎语(即便后续接口异常也能生效)
onToolClick?.(false, tool.toolId, tool.toolName, true)
try { try {
await dispatch(createConversation({ await dispatch(createConversation({
conversationData: { toolId: tool.toolId }, conversationData: { toolId: tool.toolId },
shouldNavigate: true, shouldNavigate: true,
shouldSendQuestion: '', shouldSendQuestion: '',
})).unwrap() })).unwrap()
onToolClick?.(false, tool.toolId, tool.toolName, true)
} }
catch (error) { catch (error) {
console.error('创建会话失败:', error) console.error('创建会话失败:', error)
...@@ -422,13 +423,14 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -422,13 +423,14 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
// 处理后端返回的 base64 图标 // 处理后端返回的 base64 图标
const getToolIconSrc = () => { const getToolIconSrc = () => {
if (!tool.toolIcon) const icon = tool.toolIcon
if (!icon)
return '' return ''
// 如果已经是完整的 data URL,直接返回 // 已经是完整的 data URL 或 http 链接时直接返回
if (tool.toolIcon.startsWith('data:')) if (icon.startsWith('data:') || icon.startsWith('http'))
return tool.toolIcon return icon
// 否则拼接为 base64 图片格式 // 否则拼接为 base64 图片格式
return `data:image/png;base64,${tool.toolIcon}` return `data:image/png;base64,${icon}`
} }
return ( return (
......
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