Commit 66a4eb6f by Liu

feat:没有记录时不允许清空

parent f72a780f
......@@ -23,6 +23,7 @@ import { useAppDispatch, useAppSelector } from '@/store/hook'
import ScrollBtoIcon from '@/assets/svg/scrollBto.svg?react'
import { setIsAsking } from '@/store/chatSlice'
import SdreamLoading from '@/components/SdreamLoading'
import useToast from '@/hooks/useToast'
export const TacticsChat: React.FC = () => {
const { id } = useParams<{ id: string }>()
......@@ -60,6 +61,7 @@ export const TacticsChat: React.FC = () => {
const isAsking = useAppSelector((state: RootState) => state.chat.isAsking)
const [searchParams] = useSearchParams()
const hasFetched = useRef(false)
const showToast = useToast()
// 使用 useLocalStorageState 管理 token,与原有逻辑保持一致
const [token, setToken] = useLocalStorageState<string | undefined>('__TOKEN__', {
defaultValue: '',
......@@ -664,8 +666,18 @@ export const TacticsChat: React.FC = () => {
}, [])
const handleOpenClearConfirm = useCallback(() => {
// 检查是否有对话记录(排除 system 角色)
const hasConversationRecords = allItems.some(item => item.role !== 'system')
// 检查是否有历史记录
const hasHistoryRecords = hasHistory === true
// 如果两者都没有,显示提示并返回
if (!hasConversationRecords && !hasHistoryRecords) {
showToast('暂无记录', 'default')
return
}
// 有记录时正常打开确认弹窗
setShowClearConfirm(true)
}, [])
}, [allItems, hasHistory, showToast])
useEffect(() => {
if (id) {
......
......@@ -204,8 +204,6 @@ export const TacticsHome: React.FC = () => {
login()
}, [])
// 处理清除记录
return (
<div
className={styles.homePage}
......
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