Commit b94fe07a by Liu

Merge branch 'test01' into test-tactics

# Conflicts:
#	src/pages/Home/HomeNew.tsx
parents a7da634c 407bb3c3
...@@ -149,7 +149,8 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -149,7 +149,8 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
const storedToolId = safeSessionStorageGetItem('currentToolId') const storedToolId = safeSessionStorageGetItem('currentToolId')
// 如果 currentToolId 是空字符串,视为 null,确保通用模式能正确高亮 // 如果 currentToolId 是空字符串,视为 null,确保通用模式能正确高亮
setSessionToolId(storedToolId && storedToolId.trim() ? storedToolId : null) setSessionToolId(storedToolId && storedToolId.trim() ? storedToolId : null)
}, [toolIdFromUrl]) // 当路由切换(如点击历史记录)时,同步最新的 sessionStorage,避免同标签页删除后状态不同步
}, [toolIdFromUrl, location.pathname])
const startAnimation = () => { const startAnimation = () => {
intervalRef.current = setInterval(() => { intervalRef.current = setInterval(() => {
...@@ -403,10 +404,9 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -403,10 +404,9 @@ 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)
const isSelectedByUrl = !selectedToolId && !sessionToolId && toolIdFromUrl && toolIdStr === String(toolIdFromUrl)
// 通用模式高亮:路由内没有 toolId 或 toolId 为空时默认高亮,点击后也要高亮 // 通用模式高亮:路由内没有 toolId 或 toolId 为空时默认高亮,点击后也要高亮
const isGeneralMode = tool.toolName === '通用模式' && isToolBtnActive && !selectedToolId && !sessionToolId && !toolIdFromUrl const isGeneralMode = tool.toolName === '通用模式' && isToolBtnActive && !selectedToolId && !sessionToolId && !toolIdFromUrl
const isSelected = isSelectedByState || isSelectedBySession || isSelectedByUrl || isGeneralMode const isSelected = isSelectedByState || isSelectedBySession || isGeneralMode
const baseBtnClass const baseBtnClass
= 'w-auto h-[32px] px-3 rounded-full shadow-none text-[12px] flex items-center gap-2 transition-all duration-200 border' = 'w-auto h-[32px] px-3 rounded-full shadow-none text-[12px] flex items-center gap-2 transition-all duration-200 border'
......
...@@ -33,8 +33,6 @@ export const HistoryBarList: React.FC<HistoryBarListProps> = ({ searchValue, onS ...@@ -33,8 +33,6 @@ export const HistoryBarList: React.FC<HistoryBarListProps> = ({ searchValue, onS
}) })
if (conversation.toolId) { if (conversation.toolId) {
sessionStorage.setItem('currentToolId', conversation.toolId) sessionStorage.setItem('currentToolId', conversation.toolId)
// eslint-disable-next-line no-console
console.log('889999999999:', conversation.toolId)
dispatch(setCurrentToolId(conversation.toolId)) dispatch(setCurrentToolId(conversation.toolId))
} }
else { else {
......
...@@ -12,8 +12,7 @@ import { ChatEditor } from '@/components/ChatEditor' ...@@ -12,8 +12,7 @@ import { ChatEditor } from '@/components/ChatEditor'
import type { ChatRecord } from '@/types/chat' import type { ChatRecord } from '@/types/chat'
import { fetchUserQaRecordPage } from '@/api/conversation' import { fetchUserQaRecordPage } from '@/api/conversation'
import { fetchCheckTokenApi, fetchStreamResponse } from '@/api/chat' import { fetchCheckTokenApi, fetchStreamResponse } from '@/api/chat'
import { fetchEfficiencyQuestionList, fetchToolList } from '@/api/home' import { fetchToolList } from '@/api/home'
// import { mockFetchToolList } from '@/api/mock/home'
import { clearCurrentToolId, clearShouldSendQuestion, fetchConversations, setCurrentToolId } from '@/store/conversationSlice' import { clearCurrentToolId, clearShouldSendQuestion, fetchConversations, setCurrentToolId } from '@/store/conversationSlice'
import { getUserRolesForApi } from '@/lib/utils' import { getUserRolesForApi } from '@/lib/utils'
import type { RootState } from '@/store' import type { RootState } from '@/store'
...@@ -93,23 +92,6 @@ export const Chat: React.FC = () => { ...@@ -93,23 +92,6 @@ export const Chat: React.FC = () => {
sessionToolId: null, sessionToolId: null,
}) })
// 首次进入 /chat/:id 时,拉取一次通用模式下的常见问题(toolId: ''),后续仍按现有逻辑走
useEffect(() => {
;(async () => {
try {
// 仅在本标签页首次进入时调用一次
if (sessionStorage.getItem('__INITIAL_FAQ_LOADED__'))
return
sessionStorage.setItem('__INITIAL_FAQ_LOADED__', 'true')
const sessionToolId = sessionStorage.getItem('currentToolId') || ''
await fetchEfficiencyQuestionList({ toolId: sessionToolId })
}
catch (error) {
console.error('初始化通用模式常见问题失败:', error)
}
})()
}, [])
// 进入聊天页时,同步当前链接和缓存中的 toolId 到页面上展示 // 进入聊天页时,同步当前链接和缓存中的 toolId 到页面上展示
useEffect(() => { useEffect(() => {
try { try {
...@@ -238,7 +220,9 @@ export const Chat: React.FC = () => { ...@@ -238,7 +220,9 @@ export const Chat: React.FC = () => {
/** 提交问题 */ /** 提交问题 */
const handleSubmitQuestion = async (question: string, productCode?: string, toolId?: string) => { const handleSubmitQuestion = async (question: string, productCode?: string, toolId?: string) => {
const resolvedToolId = toolId ?? currentToolId ?? undefined // 优先读取缓存中的 toolId,再回退到传参或 Redux
const sessionToolId = sessionStorage.getItem('currentToolId') ?? undefined
const resolvedToolId = toolId ?? sessionToolId ?? currentToolId ?? undefined
// 停止之前的请求 // 停止之前的请求
if (abortControllerRef.current) { if (abortControllerRef.current) {
abortControllerRef.current.abort() abortControllerRef.current.abort()
......
...@@ -22,6 +22,7 @@ interface QuestionListProps { ...@@ -22,6 +22,7 @@ interface QuestionListProps {
height?: string height?: string
isToolBtn?: boolean isToolBtn?: boolean
isLoaded?: boolean isLoaded?: boolean
onRefresh?: () => Promise<void>
} }
const containerVariants = { const containerVariants = {
hidden: {}, hidden: {},
...@@ -69,6 +70,7 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({ ...@@ -69,6 +70,7 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({
displayCount: _displayCount = 6, displayCount: _displayCount = 6,
isToolBtn = false, isToolBtn = false,
isLoaded = false, isLoaded = false,
onRefresh,
}) => { }) => {
const [isRotating, setIsRotating] = useState(false) const [isRotating, setIsRotating] = useState(false)
const [displayedItems, setDisplayedItems] = useState<string[]>([]) const [displayedItems, setDisplayedItems] = useState<string[]>([])
...@@ -85,10 +87,24 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({ ...@@ -85,10 +87,24 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({
setDisplayedItems(indices.map(index => questions[index])) setDisplayedItems(indices.map(index => questions[index]))
}, [questions, actualDisplayCount]) }, [questions, actualDisplayCount])
const handleRefresh = () => { const handleRefresh = async () => {
// 如果没有提供 onRefresh 回调,则不执行任何操作
if (!onRefresh) {
return
}
setIsRotating(true) setIsRotating(true)
updateDisplayedItems() try {
setIsRotating(false) // 重新调用接口获取新问题
await onRefresh()
}
catch (error) {
console.error('刷新问题列表失败:', error)
// 接口调用失败时不回退到随机选择,保持当前状态
}
finally {
setIsRotating(false)
}
} }
const handleClick = (item: string) => { const handleClick = (item: string) => {
if (checkAuth() && !isClicking) { if (checkAuth() && !isClicking) {
......
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