Commit 1ad0fc87 by Liu

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

parent b57c7782
......@@ -398,10 +398,9 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
const toolIdStr = String(tool.toolId)
const isSelectedByState = selectedToolId && toolIdStr === String(selectedToolId)
const isSelectedBySession = !selectedToolId && sessionToolId && toolIdStr === String(sessionToolId)
const isSelectedByUrl = !selectedToolId && !sessionToolId && toolIdFromUrl && toolIdStr === String(toolIdFromUrl)
// 通用模式高亮:路由内没有 toolId 或 toolId 为空时默认高亮,点击后也要高亮
const isGeneralMode = tool.toolName === '通用模式' && isToolBtnActive && !selectedToolId && !sessionToolId && !toolIdFromUrl
const isSelected = isSelectedByState || isSelectedBySession || isSelectedByUrl || isGeneralMode
const isSelected = isSelectedByState || isSelectedBySession || isGeneralMode
const baseBtnClass
= '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'
import { useNavigate } from 'react-router-dom'
import Refresh from '@/assets/svg/refresh.svg?react'
import { type WithAuthProps, withAuth } from '@/auth/withAuth'
import { fetchEfficiencyQuestionList } from '@/api/home'
import { useAppDispatch, useAppSelector } from '@/store/hook'
import { createConversation, setCurrentConversation, setShouldSendQuestion } from '@/store/conversationSlice'
import { safeSessionStorageGetItem } from '@/lib/utils'
......@@ -73,6 +74,7 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({
const [isRotating, setIsRotating] = useState(false)
const [displayedItems, setDisplayedItems] = useState<string[]>([])
const [isClicking, setIsClicking] = useState(false)
const [fetchedQuestions, setFetchedQuestions] = useState<string[] | null>(null)
const dispatch = useAppDispatch()
const navigate = useNavigate()
const { currentConversationId, conversations, currentToolId } = useAppSelector(state => state.conversation)
......@@ -80,16 +82,41 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({
// 根据 isToolBtn 动态设置 displayCount
const actualDisplayCount = isToolBtn ? 6 : 4
const updateDisplayedItems = useCallback(() => {
const indices = getRandomIndices(questions.length, Math.min(actualDisplayCount, questions.length))
setDisplayedItems(indices.map(index => questions[index]))
}, [questions, actualDisplayCount])
const updateDisplayedItems = useCallback(
(customQuestions?: string[]) => {
const sourceQuestions = (customQuestions && customQuestions.length > 0)
? 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)
const toolId = safeSessionStorageGetItem('currentToolId') || ''
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) => {
if (checkAuth() && !isClicking) {
setIsClicking(true)
......
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