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
4f7feaa7
Commit
4f7feaa7
authored
Dec 11, 2025
by
Liu
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'test01' into test-tactics
parents
b94fe07a
096be30e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
19 deletions
+42
-19
src/layouts/Navbar/Navbar.tsx
+4
-1
src/pages/Chat/Chat.tsx
+18
-2
src/pages/Home/HomeNew.tsx
+20
-14
src/pages/Home/components/QuestionList/QuestionList.tsx
+0
-2
No files found.
src/layouts/Navbar/Navbar.tsx
View file @
4f7feaa7
...
@@ -25,8 +25,11 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
...
@@ -25,8 +25,11 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
const
{
currentConversationId
,
shouldNavigateToNewConversation
,
currentToolId
}
=
useAppSelector
(
state
=>
state
.
conversation
)
const
{
currentConversationId
,
shouldNavigateToNewConversation
,
currentToolId
}
=
useAppSelector
(
state
=>
state
.
conversation
)
const
handleCreateConversation
=
()
=>
{
const
handleCreateConversation
=
()
=>
{
const
sessionToolId
=
sessionStorage
.
getItem
(
'currentToolId'
)
||
undefined
dispatch
(
createConversation
({
dispatch
(
createConversation
({
conversationData
:
{},
conversationData
:
{
...(
sessionToolId
?
{
toolId
:
sessionToolId
}
:
{}),
},
shouldNavigate
:
true
,
shouldNavigate
:
true
,
shouldSendQuestion
:
''
,
shouldSendQuestion
:
''
,
}))
}))
...
...
src/pages/Chat/Chat.tsx
View file @
4f7feaa7
...
@@ -27,17 +27,23 @@ export const Chat: React.FC = () => {
...
@@ -27,17 +27,23 @@ 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
// eslint-disable-next-line no-console
console
.
log
(
'[Chat] location.state:'
,
location
.
state
)
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
// eslint-disable-next-line no-console
console
.
log
(
'[Chat] initialToolId:'
,
{
console
.
log
(
'
20251211
[Chat] initialToolId:'
,
{
fromUrl
:
toolIdFromUrl
,
fromUrl
:
toolIdFromUrl
,
fromState
:
toolIdFromState
,
fromState
:
toolIdFromState
,
final
:
initialToolId
,
final
:
initialToolId
,
...
@@ -59,6 +65,9 @@ export const Chat: React.FC = () => {
...
@@ -59,6 +65,9 @@ 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')
}
}
...
@@ -68,6 +77,13 @@ export const Chat: React.FC = () => {
...
@@ -68,6 +77,13 @@ 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
...
...
src/pages/Home/HomeNew.tsx
View file @
4f7feaa7
...
@@ -90,15 +90,12 @@ export const Home: React.FC = () => {
...
@@ -90,15 +90,12 @@ export const Home: React.FC = () => {
setIsDataLoaded
(
false
)
// 重置加载状态
setIsDataLoaded
(
false
)
// 重置加载状态
try
{
try
{
// 获取当前的 toolId,
优先从 sessionStorage 获取,其次从 Redux
获取
// 获取当前的 toolId,
只从 sessionStorage
获取
const
sessionToolId
=
safeSessionStorageGetItem
(
'currentToolId'
)
||
''
const
sessionToolId
=
safeSessionStorageGetItem
(
'currentToolId'
)
||
''
const
searchParams
=
new
URLSearchParams
(
location
.
search
)
const
urlToolId
=
searchParams
.
get
(
'toolId'
)
||
''
const
finalToolId
=
sessionToolId
||
urlToolId
// 调用接口重新获取问题列表
// 调用接口重新获取问题列表
const
res
=
await
fetchEfficiencyQuestionList
({
const
res
=
await
fetchEfficiencyQuestionList
({
toolId
:
final
ToolId
,
toolId
:
session
ToolId
,
})
})
if
(
res
&&
res
.
data
&&
res
.
data
.
questions
)
{
if
(
res
&&
res
.
data
&&
res
.
data
.
questions
)
{
setOtherQuestions
((
prev
:
any
)
=>
({
setOtherQuestions
((
prev
:
any
)
=>
({
...
@@ -128,10 +125,15 @@ export const Home: React.FC = () => {
...
@@ -128,10 +125,15 @@ export const Home: React.FC = () => {
setIsDataLoaded
(
false
)
// 重置加载状态
setIsDataLoaded
(
false
)
// 重置加载状态
try
{
try
{
const
storedToolId
=
safeSessionStorageGetItem
(
'currentToolId'
)
||
''
const
storedToolId
=
safeSessionStorageGetItem
(
'currentToolId'
)
||
''
const
searchParams
=
new
URLSearchParams
(
location
.
search
)
// eslint-disable-next-line no-console
console
.
log
(
'20251211 _handleToolClick before calc'
,
{
isToolBtn
,
toolId
,
ignoreUrlToolId
,
storedToolId
,
})
// 首页初始化加载常见问题时,允许忽略路由中的 toolId,避免带入上一次的工具 ID
// 首页初始化加载常见问题时,允许忽略路由中的 toolId,避免带入上一次的工具 ID
const
urlToolId
=
ignoreUrlToolId
?
''
:
(
searchParams
.
get
(
'toolId'
)
||
''
)
const
shouldForceClearToolId
=
!
storedToolId
const
shouldForceClearToolId
=
!
storedToolId
&&
!
urlToolId
let
finalToolId
=
toolId
||
''
let
finalToolId
=
toolId
||
''
...
@@ -145,11 +147,18 @@ export const Home: React.FC = () => {
...
@@ -145,11 +147,18 @@ export const Home: React.FC = () => {
}
}
else
if
(
!
finalToolId
&&
!
isToolBtn
)
{
else
if
(
!
finalToolId
&&
!
isToolBtn
)
{
// 仅在工具模式下才使用回退逻辑,避免通用模式误用上一次的 toolId
// 仅在工具模式下才使用回退逻辑,避免通用模式误用上一次的 toolId
finalToolId
=
storedToolId
||
urlToolId
finalToolId
=
storedToolId
}
}
// 调用真实 API 获取常见问题列表,优先使用 sessionStorage 中的 currentToolId
// 调用真实 API 获取常见问题列表,优先使用 sessionStorage 中的 currentToolId
const
sessionToolId
=
safeSessionStorageGetItem
(
'currentToolId'
)
||
''
const
sessionToolId
=
safeSessionStorageGetItem
(
'currentToolId'
)
||
''
// 调试:记录最终用于请求的 toolId
// 20251211 调试:记录最终用于请求的 toolId
// eslint-disable-next-line no-console
console
.
log
(
'20251211 _handleToolClick fetch'
,
{
sessionToolId
,
finalToolId
,
})
const
res
=
await
fetchEfficiencyQuestionList
({
const
res
=
await
fetchEfficiencyQuestionList
({
toolId
:
sessionToolId
||
finalToolId
,
toolId
:
sessionToolId
||
finalToolId
,
})
})
...
@@ -217,7 +226,7 @@ export const Home: React.FC = () => {
...
@@ -217,7 +226,7 @@ export const Home: React.FC = () => {
if
(
res
.
data
)
{
if
(
res
.
data
)
{
// 登录成功后先打印完整的原始链接(删除之前)
// 登录成功后先打印完整的原始链接(删除之前)
// eslint-disable-next-line no-console
// eslint-disable-next-line no-console
console
.
log
(
'登录成功,删除前完整链接:'
,
window
.
location
.
href
)
console
.
log
(
'
20251211
登录成功,删除前完整链接:'
,
window
.
location
.
href
)
// 登录成功后先清理旧状态,避免沿用上一次的工具模式
// 登录成功后先清理旧状态,避免沿用上一次的工具模式
dispatch
(
clearCurrentToolId
())
dispatch
(
clearCurrentToolId
())
safeSessionStorageRemoveItem
(
'currentToolId'
)
safeSessionStorageRemoveItem
(
'currentToolId'
)
...
@@ -229,7 +238,7 @@ export const Home: React.FC = () => {
...
@@ -229,7 +238,7 @@ export const Home: React.FC = () => {
}
}
// 删除后打印链接
// 删除后打印链接
// eslint-disable-next-line no-console
// eslint-disable-next-line no-console
console
.
log
(
'登录成功,删除后完整链接:'
,
window
.
location
.
href
)
console
.
log
(
'
20251211
登录成功,删除后完整链接:'
,
window
.
location
.
href
)
setToken
(
res
.
data
.
token
)
setToken
(
res
.
data
.
token
)
// 主动触发 storage 事件,确保其他组件能监听到变化
// 主动触发 storage 事件,确保其他组件能监听到变化
window
.
dispatchEvent
(
window
.
dispatchEvent
(
...
@@ -293,9 +302,6 @@ export const Home: React.FC = () => {
...
@@ -293,9 +302,6 @@ export const Home: React.FC = () => {
// 首页首次挂载时重置为通用模式:
// 首页首次挂载时重置为通用模式:
// 1. 清除 Redux 中的 currentToolId
// 1. 清除 Redux 中的 currentToolId
dispatch
(
clearCurrentToolId
())
dispatch
(
clearCurrentToolId
())
// 2. 清除 sessionStorage 中可能残留的 currentToolId,避免沿用上一次工具模式
// sessionStorage.removeItem('currentToolId')
// 3. 首页首次挂载时强制忽略路由中的 toolId,只按通用模式拉常见问题(toolId: '')
_handleToolClick
(
false
,
''
,
true
)
_handleToolClick
(
false
,
''
,
true
)
},
[])
// 依赖数组为空,只在组件挂载时执行一次
},
[])
// 依赖数组为空,只在组件挂载时执行一次
...
...
src/pages/Home/components/QuestionList/QuestionList.tsx
View file @
4f7feaa7
...
@@ -126,8 +126,6 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({
...
@@ -126,8 +126,6 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({
}
}
else
{
else
{
// 如果没有现有会话,仍然创建新会话(向后兼容)
// 如果没有现有会话,仍然创建新会话(向后兼容)
// 这里可以改为提示用户,或者保持创建新会话的逻辑
// 为了最小修改,暂时保持创建新会话的逻辑
dispatch
(
dispatch
(
createConversation
({
createConversation
({
conversationData
:
{},
conversationData
:
{},
...
...
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