Commit 749ccdec by Liu

fix:欢迎语

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