Commit b1a1257e by Liu

delete:无用代码

parent 1219c383
......@@ -28,27 +28,13 @@ export const Chat: React.FC = () => {
const [searchParams, setSearchParams] = useSearchParams()
// 优先从 URL 查询参数读取 toolId(刷新后仍能保留),其次从 location.state 读取
const rawToolIdFromUrl = searchParams.get('toolId')
// 20251211 调试:记录进入聊天页时 URL 与 state 的 toolId 来源
// eslint-disable-next-line no-console
console.log('20251211 Chat url/state init', {
rawToolIdFromUrl,
locationState: location.state,
})
// 只有在非 SPA 导航(location.state 不存在)且链接携带 toolId 时才清空,避免影响站内点击历史记录
const shouldForceClearUrlToolId = !location.state && Boolean(rawToolIdFromUrl)
const toolIdFromUrl = shouldForceClearUrlToolId ? null : rawToolIdFromUrl
// 添加调试日志,查看 location.state 的实际值
// eslint-disable-next-line no-console
console.log('20251211 [Chat] location.state:', location.state)
const toolIdFromState = (location.state as { toolId?: string | null } | null)?.toolId
// 优先使用 URL 中的 toolId,其次使用 state 中的 toolId
const initialToolId = toolIdFromUrl !== null ? toolIdFromUrl : toolIdFromState
// eslint-disable-next-line no-console
console.log('20251211[Chat] initialToolId:', {
fromUrl: toolIdFromUrl,
fromState: toolIdFromState,
final: initialToolId,
})
const [isLoading, setIsLoading] = useState(false)
const [allItems, setAllItems] = useState<ChatRecord[]>([])
const dispatch = useAppDispatch()
......@@ -66,9 +52,6 @@ export const Chat: React.FC = () => {
// 视为一次新的会话入口:重置为制度活化,清除历史遗留的工具模式状态
useEffect(() => {
if (!location.state && !rawToolIdFromUrl) {
// 20251211 调试:无 URL、无 state 时清除 toolId
// eslint-disable-next-line no-console
console.log('20251211 Chat clear toolId (no state & no url)')
dispatch(clearCurrentToolId())
// sessionStorage.removeItem('currentToolId')
}
......@@ -78,13 +61,6 @@ export const Chat: React.FC = () => {
if (!shouldForceClearUrlToolId)
return
// 20251211 调试:URL 携带 toolId 且需要强制清空
// eslint-disable-next-line no-console
console.log('20251211 Chat force clear url toolId', {
rawToolIdFromUrl,
shouldForceClearUrlToolId,
})
// 1. 清除 Redux 中的 currentToolId
dispatch(clearCurrentToolId())
// 2. 清除 sessionStorage 中的 currentToolId
......@@ -140,13 +116,6 @@ export const Chat: React.FC = () => {
if (initialToolId) {
// 统一转换为字符串,确保类型一致(真实API可能返回数字,需要转换为字符串)
const normalizedToolId = String(initialToolId)
// eslint-disable-next-line no-console
console.log('[Chat] 从路由state设置toolId:', {
originalToolId: initialToolId,
originalType: typeof initialToolId,
normalizedToolId,
normalizedType: typeof normalizedToolId,
})
dispatch(setCurrentToolId(normalizedToolId))
}
else {
......@@ -187,33 +156,6 @@ export const Chat: React.FC = () => {
/** 处理超过最大条数的数据 */
const handleChatMaxCount = (msg: any, question: string) => {
// toast(t => (
// <div className="flex items-center">
// <p className="text-[14px]">⚠️ 超过最大轮数上限!请新建对话 👉🏻</p>
// <Button
// color="primary"
// size="sm"
// variant="light"
// isIconOnly
// onClick={() => {
// dispatch(createConversation({
// conversationData: {},
// shouldNavigate: true,
// shouldSendQuestion: '',
// }))
// toast.dismiss(t.id)
// }}
// >
// <AddNewChat />
// </Button>
// </div>
// ), {
// position: 'bottom-center',
// duration: 0,
// style: {
// marginBottom: '120px',
// },
// })
setAllItems((prevItems) => {
const newItems = [...prevItems] // 创建数组的浅拷贝
const lastIndex = newItems.length - 1
......@@ -350,8 +292,6 @@ export const Chat: React.FC = () => {
try {
// 检测是否从收藏页返回
const fromCollect = location.state?.fromCollect
// eslint-disable-next-line no-console
console.log('[Chat] 开始获取历史记录:', conversationId)
const res = await fetchUserQaRecordPage(conversationId, toolId || '')
const qaRecords = res.data || []
const messages = [{ role: 'system' } as ChatRecord, ...processApiResponse(qaRecords)]
......@@ -384,28 +324,12 @@ export const Chat: React.FC = () => {
? (toolIdFromStateRef.current ? String(toolIdFromStateRef.current) : null)
: undefined
// eslint-disable-next-line no-console
console.log('[Chat] 从历史记录获取 toolId:', {
conversationId,
toolIdFromState,
latestToolIdFromQaRecords: latestToolId,
conversationToolId,
hasQaRecords,
currentToolIdInRedux: currentToolId,
})
// 确定最终使用的 toolId:优先使用从 location.state 传递的,其次使用 qaRecords 中的,最后使用 conversation 中的
// 如果从 location.state 传递了 toolId,直接使用它(最高优先级)
if (toolIdFromState !== undefined) {
if (toolIdFromState) {
// 只有当 Redux 中的 toolId 与最终确定的 toolId 不一致时,才更新
if (currentToolId !== toolIdFromState) {
// eslint-disable-next-line no-console
console.log('[Chat] 使用从路由state传递的 toolId:', {
from: currentToolId,
to: toolIdFromState,
source: 'location.state',
})
dispatch(setCurrentToolId(toolIdFromState))
// 从收藏返回时,同步到 sessionStorage,避免 ChatEditor 清除 toolId
if (fromCollect) {
......@@ -413,9 +337,6 @@ export const Chat: React.FC = () => {
}
}
else {
// eslint-disable-next-line no-console
console.log('[Chat] toolId 已一致,无需更新:', toolIdFromState)
// 从收藏返回时,确保 sessionStorage 中有值
if (fromCollect && !sessionStorage.getItem('currentToolId')) {
sessionStorage.setItem('currentToolId', toolIdFromState)
}
......@@ -424,8 +345,6 @@ export const Chat: React.FC = () => {
else {
// 如果从 location.state 传递的是 null,清除 toolId
if (currentToolId) {
// eslint-disable-next-line no-console
console.log('[Chat] 清除 toolId (从路由state传递null)')
dispatch(clearCurrentToolId())
}
}
......@@ -440,12 +359,6 @@ export const Chat: React.FC = () => {
if (finalToolId) {
// 只有当 Redux 中的 toolId 与最终确定的 toolId 不一致时,才更新
if (currentToolId !== finalToolId) {
// eslint-disable-next-line no-console
console.log('[Chat] 更新 toolId (不一致):', {
from: currentToolId,
to: finalToolId,
source: latestToolId ? 'qaRecords' : 'conversation',
})
dispatch(setCurrentToolId(finalToolId))
// 从收藏返回时,同步到 sessionStorage,避免 ChatEditor 清除 toolId
if (fromCollect) {
......@@ -453,8 +366,6 @@ export const Chat: React.FC = () => {
}
}
else {
// eslint-disable-next-line no-console
console.log('[Chat] toolId 已一致,无需更新:', finalToolId)
// 从收藏返回时,确保 sessionStorage 中有值
if (fromCollect && !sessionStorage.getItem('currentToolId')) {
sessionStorage.setItem('currentToolId', finalToolId)
......@@ -465,16 +376,11 @@ export const Chat: React.FC = () => {
// 如果 qaRecords 和 conversation 中都没有 toolId
// 如果有历史记录但没有 toolId,说明是制度活化,应该清除
if (hasQaRecords && currentToolId) {
// eslint-disable-next-line no-console
console.log('[Chat] 清除 toolId (qaRecords 中有记录但没有 toolId,制度活化)')
dispatch(clearCurrentToolId())
}
// 如果没有历史记录,可能是新会话,但如果 Redux 中已经有 toolId(从 HistoryBarList 设置的),暂时保留
// 因为可能是刚点击历史记录但 API 还没返回,或者 location.state 传递失败但 Redux 中已有正确的值
else if (!hasQaRecords && currentToolId) {
// eslint-disable-next-line no-console
console.log('[Chat] 没有历史记录,保留 Redux 中的 toolId (可能是 location.state 传递失败):', currentToolId)
// 从收藏返回时,确保 sessionStorage 中有值
if (fromCollect && !sessionStorage.getItem('currentToolId')) {
sessionStorage.setItem('currentToolId', currentToolId)
}
......@@ -586,8 +492,6 @@ export const Chat: React.FC = () => {
return (
<div className={styles.scrollView}>
<div className={`${styles.chatPage} relative`}>
{/* <ChatSlogan />
<ChatMaskBar /> */}
<div className={`${styles.content}`}>
{isLoading && (
<div className="w-full h-full flex justify-center items-center">
......
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