Commit 1ad0fc87 by Liu

fix:换一换调用常见问题接口&&按钮高亮2个逻辑

parent b57c7782
...@@ -398,10 +398,9 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -398,10 +398,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'
......
...@@ -6,6 +6,7 @@ import { useCallback, useEffect, useState } from 'react' ...@@ -6,6 +6,7 @@ import { useCallback, useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import Refresh from '@/assets/svg/refresh.svg?react' import Refresh from '@/assets/svg/refresh.svg?react'
import { type WithAuthProps, withAuth } from '@/auth/withAuth' import { type WithAuthProps, withAuth } from '@/auth/withAuth'
import { fetchEfficiencyQuestionList } from '@/api/home'
import { useAppDispatch, useAppSelector } from '@/store/hook' import { useAppDispatch, useAppSelector } from '@/store/hook'
import { createConversation, setCurrentConversation, setShouldSendQuestion } from '@/store/conversationSlice' import { createConversation, setCurrentConversation, setShouldSendQuestion } from '@/store/conversationSlice'
import { safeSessionStorageGetItem } from '@/lib/utils' import { safeSessionStorageGetItem } from '@/lib/utils'
...@@ -73,6 +74,7 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({ ...@@ -73,6 +74,7 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({
const [isRotating, setIsRotating] = useState(false) const [isRotating, setIsRotating] = useState(false)
const [displayedItems, setDisplayedItems] = useState<string[]>([]) const [displayedItems, setDisplayedItems] = useState<string[]>([])
const [isClicking, setIsClicking] = useState(false) const [isClicking, setIsClicking] = useState(false)
const [fetchedQuestions, setFetchedQuestions] = useState<string[] | null>(null)
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const navigate = useNavigate() const navigate = useNavigate()
const { currentConversationId, conversations, currentToolId } = useAppSelector(state => state.conversation) const { currentConversationId, conversations, currentToolId } = useAppSelector(state => state.conversation)
...@@ -80,15 +82,40 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({ ...@@ -80,15 +82,40 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({
// 根据 isToolBtn 动态设置 displayCount // 根据 isToolBtn 动态设置 displayCount
const actualDisplayCount = isToolBtn ? 6 : 4 const actualDisplayCount = isToolBtn ? 6 : 4
const updateDisplayedItems = useCallback(() => { const updateDisplayedItems = useCallback(
const indices = getRandomIndices(questions.length, Math.min(actualDisplayCount, questions.length)) (customQuestions?: string[]) => {
setDisplayedItems(indices.map(index => questions[index])) const sourceQuestions = (customQuestions && customQuestions.length > 0)
}, [questions, actualDisplayCount]) ? customQuestions
: (fetchedQuestions && fetchedQuestions.length > 0 ? fetchedQuestions : questions)
if (!sourceQuestions.length) {
return
}
const indices = getRandomIndices(sourceQuestions.length, Math.min(actualDisplayCount, sourceQuestions.length))
setDisplayedItems(indices.map(index => sourceQuestions[index]))
},
[questions, fetchedQuestions, actualDisplayCount],
)
const handleRefresh = () => { const handleRefresh = async () => {
setIsRotating(true) setIsRotating(true)
updateDisplayedItems() const toolId = safeSessionStorageGetItem('currentToolId') || ''
setIsRotating(false) try {
const res = await fetchEfficiencyQuestionList({ toolId })
const newQuestions = res?.data?.questions as string[] | undefined
if (newQuestions?.length) {
setFetchedQuestions(newQuestions)
updateDisplayedItems(newQuestions)
return
}
updateDisplayedItems()
}
catch (error) {
console.error('刷新常见问题失败:', error)
updateDisplayedItems()
}
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