Commit 396afeb0 by Liu

feat: 切换工具按钮时调用历史记录接口

parent 579b7852
...@@ -20,8 +20,8 @@ export function fetchCreateConversation<T>(data: T) { ...@@ -20,8 +20,8 @@ export function fetchCreateConversation<T>(data: T) {
* 查询用户问答历史 * 查询用户问答历史
* @params { * } * @params { * }
*/ */
export function fetchUserQaRecordPage(conversationId: string) { export function fetchUserQaRecordPage(conversationId: string, toolId?: string) {
return http.post('/conversation/api/conversation/mobile/v1/query_user_qa_record_list', { conversationId }) return http.post('/conversation/api/conversation/mobile/v1/query_user_qa_record_list', { conversationId, toolId: toolId || '' })
} }
/** /**
......
...@@ -2,7 +2,7 @@ import React, { useEffect, useRef, useState } from 'react' ...@@ -2,7 +2,7 @@ import React, { useEffect, useRef, useState } from 'react'
import { AnimatePresence, motion } from 'framer-motion' import { AnimatePresence, motion } from 'framer-motion'
import { Button, Tooltip } from '@heroui/react' import { Button, Tooltip } from '@heroui/react'
import { useLocalStorageState, useToggle } from 'ahooks' import { useLocalStorageState, useToggle } from 'ahooks'
import { useLocation, useSearchParams } from 'react-router-dom' import { useLocation, useParams, useSearchParams } from 'react-router-dom'
import { LoginModal } from '../LoginModal' import { LoginModal } from '../LoginModal'
import type { RootState } from '@/store' import type { RootState } from '@/store'
import SendIcon from '@/assets/svg/send.svg?react' import SendIcon from '@/assets/svg/send.svg?react'
...@@ -10,6 +10,7 @@ import { type WithAuthProps, withAuth } from '@/auth/withAuth' ...@@ -10,6 +10,7 @@ import { type WithAuthProps, withAuth } from '@/auth/withAuth'
import { useAppDispatch, useAppSelector } from '@/store/hook' import { useAppDispatch, useAppSelector } from '@/store/hook'
import { clearCurrentToolId, setCurrentToolId } from '@/store/conversationSlice' import { clearCurrentToolId, setCurrentToolId } from '@/store/conversationSlice'
import { fetchToolList } from '@/api/home' import { fetchToolList } from '@/api/home'
import { fetchUserQaRecordPage } from '@/api/conversation'
import { getUserRolesForApi, safeSessionStorageGetItem, safeSessionStorageRemoveItem, safeSessionStorageSetItem } from '@/lib/utils' import { getUserRolesForApi, safeSessionStorageGetItem, safeSessionStorageRemoveItem, safeSessionStorageSetItem } from '@/lib/utils'
interface ChatEditorProps { interface ChatEditorProps {
...@@ -40,6 +41,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -40,6 +41,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
const [sessionToolId, setSessionToolId] = useState<string | null>(null) const [sessionToolId, setSessionToolId] = useState<string | null>(null)
const [searchParams, setSearchParams] = useSearchParams() const [searchParams, setSearchParams] = useSearchParams()
const location = useLocation() const location = useLocation()
const { id: conversationId } = useParams<{ id: string }>()
const toolIdFromUrl = searchParams.get('toolId') const toolIdFromUrl = searchParams.get('toolId')
const fromCollect = location.state?.fromCollect const fromCollect = location.state?.fromCollect
...@@ -235,6 +237,15 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -235,6 +237,15 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
newSearchParams.delete('toolId') newSearchParams.delete('toolId')
setSearchParams(newSearchParams, { replace: true }) setSearchParams(newSearchParams, { replace: true })
} }
// 调用接口
if (conversationId) {
try {
await fetchUserQaRecordPage(conversationId, '')
}
catch (error) {
console.error('获取问答记录失败:', error)
}
}
// try { // try {
// await dispatch(createConversation({ // await dispatch(createConversation({
// conversationData: {}, // conversationData: {},
...@@ -264,6 +275,16 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -264,6 +275,16 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
setSessionToolId(tool.toolId) setSessionToolId(tool.toolId)
// 先通知上层更新欢迎语(即便后续接口异常也能生效) // 先通知上层更新欢迎语(即便后续接口异常也能生效)
onToolClick?.(false, tool.toolId, tool.toolName, true) onToolClick?.(false, tool.toolId, tool.toolName, true)
// 调用接口
if (conversationId) {
const toolId = safeSessionStorageGetItem('currentToolId') || ''
try {
await fetchUserQaRecordPage(conversationId, toolId)
}
catch (error) {
console.error('获取问答记录失败:', error)
}
}
// try { // try {
// await dispatch(createConversation({ // await dispatch(createConversation({
// conversationData: { toolId: tool.toolId }, // conversationData: { toolId: tool.toolId },
......
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