Commit 66a4eb6f by Liu

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

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