Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sdream-ai-fe
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
侯明涛
sdream-ai-fe
Commits
b1a1257e
Commit
b1a1257e
authored
Dec 31, 2025
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
delete:无用代码
parent
1219c383
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
96 deletions
+0
-96
src/pages/Chat/Chat.tsx
+0
-96
No files found.
src/pages/Chat/Chat.tsx
View file @
b1a1257e
...
@@ -28,27 +28,13 @@ export const Chat: React.FC = () => {
...
@@ -28,27 +28,13 @@ export const Chat: React.FC = () => {
const
[
searchParams
,
setSearchParams
]
=
useSearchParams
()
const
[
searchParams
,
setSearchParams
]
=
useSearchParams
()
// 优先从 URL 查询参数读取 toolId(刷新后仍能保留),其次从 location.state 读取
// 优先从 URL 查询参数读取 toolId(刷新后仍能保留),其次从 location.state 读取
const
rawToolIdFromUrl
=
searchParams
.
get
(
'toolId'
)
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 时才清空,避免影响站内点击历史记录
// 只有在非 SPA 导航(location.state 不存在)且链接携带 toolId 时才清空,避免影响站内点击历史记录
const
shouldForceClearUrlToolId
=
!
location
.
state
&&
Boolean
(
rawToolIdFromUrl
)
const
shouldForceClearUrlToolId
=
!
location
.
state
&&
Boolean
(
rawToolIdFromUrl
)
const
toolIdFromUrl
=
shouldForceClearUrlToolId
?
null
:
rawToolIdFromUrl
const
toolIdFromUrl
=
shouldForceClearUrlToolId
?
null
:
rawToolIdFromUrl
// 添加调试日志,查看 location.state 的实际值
// 添加调试日志,查看 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
const
toolIdFromState
=
(
location
.
state
as
{
toolId
?:
string
|
null
}
|
null
)?.
toolId
// 优先使用 URL 中的 toolId,其次使用 state 中的 toolId
// 优先使用 URL 中的 toolId,其次使用 state 中的 toolId
const
initialToolId
=
toolIdFromUrl
!==
null
?
toolIdFromUrl
:
toolIdFromState
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
[
isLoading
,
setIsLoading
]
=
useState
(
false
)
const
[
allItems
,
setAllItems
]
=
useState
<
ChatRecord
[]
>
([])
const
[
allItems
,
setAllItems
]
=
useState
<
ChatRecord
[]
>
([])
const
dispatch
=
useAppDispatch
()
const
dispatch
=
useAppDispatch
()
...
@@ -66,9 +52,6 @@ export const Chat: React.FC = () => {
...
@@ -66,9 +52,6 @@ export const Chat: React.FC = () => {
// 视为一次新的会话入口:重置为制度活化,清除历史遗留的工具模式状态
// 视为一次新的会话入口:重置为制度活化,清除历史遗留的工具模式状态
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
!
location
.
state
&&
!
rawToolIdFromUrl
)
{
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
())
dispatch
(
clearCurrentToolId
())
// sessionStorage.removeItem('currentToolId')
// sessionStorage.removeItem('currentToolId')
}
}
...
@@ -78,13 +61,6 @@ export const Chat: React.FC = () => {
...
@@ -78,13 +61,6 @@ export const Chat: React.FC = () => {
if
(
!
shouldForceClearUrlToolId
)
if
(
!
shouldForceClearUrlToolId
)
return
return
// 20251211 调试:URL 携带 toolId 且需要强制清空
// eslint-disable-next-line no-console
console
.
log
(
'20251211 Chat force clear url toolId'
,
{
rawToolIdFromUrl
,
shouldForceClearUrlToolId
,
})
// 1. 清除 Redux 中的 currentToolId
// 1. 清除 Redux 中的 currentToolId
dispatch
(
clearCurrentToolId
())
dispatch
(
clearCurrentToolId
())
// 2. 清除 sessionStorage 中的 currentToolId
// 2. 清除 sessionStorage 中的 currentToolId
...
@@ -140,13 +116,6 @@ export const Chat: React.FC = () => {
...
@@ -140,13 +116,6 @@ export const Chat: React.FC = () => {
if
(
initialToolId
)
{
if
(
initialToolId
)
{
// 统一转换为字符串,确保类型一致(真实API可能返回数字,需要转换为字符串)
// 统一转换为字符串,确保类型一致(真实API可能返回数字,需要转换为字符串)
const
normalizedToolId
=
String
(
initialToolId
)
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
))
dispatch
(
setCurrentToolId
(
normalizedToolId
))
}
}
else
{
else
{
...
@@ -187,33 +156,6 @@ export const Chat: React.FC = () => {
...
@@ -187,33 +156,6 @@ export const Chat: React.FC = () => {
/** 处理超过最大条数的数据 */
/** 处理超过最大条数的数据 */
const
handleChatMaxCount
=
(
msg
:
any
,
question
:
string
)
=>
{
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
)
=>
{
setAllItems
((
prevItems
)
=>
{
const
newItems
=
[...
prevItems
]
// 创建数组的浅拷贝
const
newItems
=
[...
prevItems
]
// 创建数组的浅拷贝
const
lastIndex
=
newItems
.
length
-
1
const
lastIndex
=
newItems
.
length
-
1
...
@@ -350,8 +292,6 @@ export const Chat: React.FC = () => {
...
@@ -350,8 +292,6 @@ export const Chat: React.FC = () => {
try
{
try
{
// 检测是否从收藏页返回
// 检测是否从收藏页返回
const
fromCollect
=
location
.
state
?.
fromCollect
const
fromCollect
=
location
.
state
?.
fromCollect
// eslint-disable-next-line no-console
console
.
log
(
'[Chat] 开始获取历史记录:'
,
conversationId
)
const
res
=
await
fetchUserQaRecordPage
(
conversationId
,
toolId
||
''
)
const
res
=
await
fetchUserQaRecordPage
(
conversationId
,
toolId
||
''
)
const
qaRecords
=
res
.
data
||
[]
const
qaRecords
=
res
.
data
||
[]
const
messages
=
[{
role
:
'system'
}
as
ChatRecord
,
...
processApiResponse
(
qaRecords
)]
const
messages
=
[{
role
:
'system'
}
as
ChatRecord
,
...
processApiResponse
(
qaRecords
)]
...
@@ -384,28 +324,12 @@ export const Chat: React.FC = () => {
...
@@ -384,28 +324,12 @@ export const Chat: React.FC = () => {
?
(
toolIdFromStateRef
.
current
?
String
(
toolIdFromStateRef
.
current
)
:
null
)
?
(
toolIdFromStateRef
.
current
?
String
(
toolIdFromStateRef
.
current
)
:
null
)
:
undefined
:
undefined
// eslint-disable-next-line no-console
console
.
log
(
'[Chat] 从历史记录获取 toolId:'
,
{
conversationId
,
toolIdFromState
,
latestToolIdFromQaRecords
:
latestToolId
,
conversationToolId
,
hasQaRecords
,
currentToolIdInRedux
:
currentToolId
,
})
// 确定最终使用的 toolId:优先使用从 location.state 传递的,其次使用 qaRecords 中的,最后使用 conversation 中的
// 确定最终使用的 toolId:优先使用从 location.state 传递的,其次使用 qaRecords 中的,最后使用 conversation 中的
// 如果从 location.state 传递了 toolId,直接使用它(最高优先级)
// 如果从 location.state 传递了 toolId,直接使用它(最高优先级)
if
(
toolIdFromState
!==
undefined
)
{
if
(
toolIdFromState
!==
undefined
)
{
if
(
toolIdFromState
)
{
if
(
toolIdFromState
)
{
// 只有当 Redux 中的 toolId 与最终确定的 toolId 不一致时,才更新
// 只有当 Redux 中的 toolId 与最终确定的 toolId 不一致时,才更新
if
(
currentToolId
!==
toolIdFromState
)
{
if
(
currentToolId
!==
toolIdFromState
)
{
// eslint-disable-next-line no-console
console
.
log
(
'[Chat] 使用从路由state传递的 toolId:'
,
{
from
:
currentToolId
,
to
:
toolIdFromState
,
source
:
'location.state'
,
})
dispatch
(
setCurrentToolId
(
toolIdFromState
))
dispatch
(
setCurrentToolId
(
toolIdFromState
))
// 从收藏返回时,同步到 sessionStorage,避免 ChatEditor 清除 toolId
// 从收藏返回时,同步到 sessionStorage,避免 ChatEditor 清除 toolId
if
(
fromCollect
)
{
if
(
fromCollect
)
{
...
@@ -413,9 +337,6 @@ export const Chat: React.FC = () => {
...
@@ -413,9 +337,6 @@ export const Chat: React.FC = () => {
}
}
}
}
else
{
else
{
// eslint-disable-next-line no-console
console
.
log
(
'[Chat] toolId 已一致,无需更新:'
,
toolIdFromState
)
// 从收藏返回时,确保 sessionStorage 中有值
if
(
fromCollect
&&
!
sessionStorage
.
getItem
(
'currentToolId'
))
{
if
(
fromCollect
&&
!
sessionStorage
.
getItem
(
'currentToolId'
))
{
sessionStorage
.
setItem
(
'currentToolId'
,
toolIdFromState
)
sessionStorage
.
setItem
(
'currentToolId'
,
toolIdFromState
)
}
}
...
@@ -424,8 +345,6 @@ export const Chat: React.FC = () => {
...
@@ -424,8 +345,6 @@ export const Chat: React.FC = () => {
else
{
else
{
// 如果从 location.state 传递的是 null,清除 toolId
// 如果从 location.state 传递的是 null,清除 toolId
if
(
currentToolId
)
{
if
(
currentToolId
)
{
// eslint-disable-next-line no-console
console
.
log
(
'[Chat] 清除 toolId (从路由state传递null)'
)
dispatch
(
clearCurrentToolId
())
dispatch
(
clearCurrentToolId
())
}
}
}
}
...
@@ -440,12 +359,6 @@ export const Chat: React.FC = () => {
...
@@ -440,12 +359,6 @@ export const Chat: React.FC = () => {
if
(
finalToolId
)
{
if
(
finalToolId
)
{
// 只有当 Redux 中的 toolId 与最终确定的 toolId 不一致时,才更新
// 只有当 Redux 中的 toolId 与最终确定的 toolId 不一致时,才更新
if
(
currentToolId
!==
finalToolId
)
{
if
(
currentToolId
!==
finalToolId
)
{
// eslint-disable-next-line no-console
console
.
log
(
'[Chat] 更新 toolId (不一致):'
,
{
from
:
currentToolId
,
to
:
finalToolId
,
source
:
latestToolId
?
'qaRecords'
:
'conversation'
,
})
dispatch
(
setCurrentToolId
(
finalToolId
))
dispatch
(
setCurrentToolId
(
finalToolId
))
// 从收藏返回时,同步到 sessionStorage,避免 ChatEditor 清除 toolId
// 从收藏返回时,同步到 sessionStorage,避免 ChatEditor 清除 toolId
if
(
fromCollect
)
{
if
(
fromCollect
)
{
...
@@ -453,8 +366,6 @@ export const Chat: React.FC = () => {
...
@@ -453,8 +366,6 @@ export const Chat: React.FC = () => {
}
}
}
}
else
{
else
{
// eslint-disable-next-line no-console
console
.
log
(
'[Chat] toolId 已一致,无需更新:'
,
finalToolId
)
// 从收藏返回时,确保 sessionStorage 中有值
// 从收藏返回时,确保 sessionStorage 中有值
if
(
fromCollect
&&
!
sessionStorage
.
getItem
(
'currentToolId'
))
{
if
(
fromCollect
&&
!
sessionStorage
.
getItem
(
'currentToolId'
))
{
sessionStorage
.
setItem
(
'currentToolId'
,
finalToolId
)
sessionStorage
.
setItem
(
'currentToolId'
,
finalToolId
)
...
@@ -465,16 +376,11 @@ export const Chat: React.FC = () => {
...
@@ -465,16 +376,11 @@ export const Chat: React.FC = () => {
// 如果 qaRecords 和 conversation 中都没有 toolId
// 如果 qaRecords 和 conversation 中都没有 toolId
// 如果有历史记录但没有 toolId,说明是制度活化,应该清除
// 如果有历史记录但没有 toolId,说明是制度活化,应该清除
if
(
hasQaRecords
&&
currentToolId
)
{
if
(
hasQaRecords
&&
currentToolId
)
{
// eslint-disable-next-line no-console
console
.
log
(
'[Chat] 清除 toolId (qaRecords 中有记录但没有 toolId,制度活化)'
)
dispatch
(
clearCurrentToolId
())
dispatch
(
clearCurrentToolId
())
}
}
// 如果没有历史记录,可能是新会话,但如果 Redux 中已经有 toolId(从 HistoryBarList 设置的),暂时保留
// 如果没有历史记录,可能是新会话,但如果 Redux 中已经有 toolId(从 HistoryBarList 设置的),暂时保留
// 因为可能是刚点击历史记录但 API 还没返回,或者 location.state 传递失败但 Redux 中已有正确的值
// 因为可能是刚点击历史记录但 API 还没返回,或者 location.state 传递失败但 Redux 中已有正确的值
else
if
(
!
hasQaRecords
&&
currentToolId
)
{
else
if
(
!
hasQaRecords
&&
currentToolId
)
{
// eslint-disable-next-line no-console
console
.
log
(
'[Chat] 没有历史记录,保留 Redux 中的 toolId (可能是 location.state 传递失败):'
,
currentToolId
)
// 从收藏返回时,确保 sessionStorage 中有值
if
(
fromCollect
&&
!
sessionStorage
.
getItem
(
'currentToolId'
))
{
if
(
fromCollect
&&
!
sessionStorage
.
getItem
(
'currentToolId'
))
{
sessionStorage
.
setItem
(
'currentToolId'
,
currentToolId
)
sessionStorage
.
setItem
(
'currentToolId'
,
currentToolId
)
}
}
...
@@ -586,8 +492,6 @@ export const Chat: React.FC = () => {
...
@@ -586,8 +492,6 @@ export const Chat: React.FC = () => {
return
(
return
(
<
div
className=
{
styles
.
scrollView
}
>
<
div
className=
{
styles
.
scrollView
}
>
<
div
className=
{
`${styles.chatPage} relative`
}
>
<
div
className=
{
`${styles.chatPage} relative`
}
>
{
/* <ChatSlogan />
<ChatMaskBar /> */
}
<
div
className=
{
`${styles.content}`
}
>
<
div
className=
{
`${styles.content}`
}
>
{
isLoading
&&
(
{
isLoading
&&
(
<
div
className=
"w-full h-full flex justify-center items-center"
>
<
div
className=
"w-full h-full flex justify-center items-center"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment