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
f7abcbf9
Commit
f7abcbf9
authored
Dec 18, 2025
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:更新接口传参方式,不存入sesstionStorage
parent
13311e18
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
146 deletions
+20
-146
src/pages/ChatTactics/TacticsChat.tsx
+9
-46
src/pages/ChatTactics/TacticsHome.tsx
+8
-61
src/routes/RouteChangeHandler.tsx
+3
-39
No files found.
src/pages/ChatTactics/TacticsChat.tsx
View file @
f7abcbf9
...
...
@@ -73,17 +73,15 @@ export const TacticsChat: React.FC = () => {
const
createdFromClearRef
=
useRef
(
false
)
const
lastSentQuestionRef
=
useRef
<
string
>
(
''
)
const
abortControllerRef
=
useRef
<
AbortController
|
null
>
(
null
)
// 读取 from=tactics 的额外参数
const
tacticsMetaFromState
=
(
location
.
state
as
{
tacticsMeta
?:
any
}
|
null
)?.
tacticsMeta
const
tacticsMetaFromQuery
=
useMemo
(()
=>
{
// 读取 from=tactics 的额外参数(直接从 query 读取,不再使用 sessionStorage)
const
tacticsMeta
=
useMemo
(()
=>
{
const
from
=
searchParams
.
get
(
'from'
)
const
version
=
searchParams
.
get
(
'version'
)
if
(
from
!==
'tactics'
)
{
return
undefined
}
const
taskId
=
searchParams
.
get
(
'taskId'
)
||
undefined
return
{
version
,
version
:
searchParams
.
get
(
'version'
)
,
taskId
,
pinBeginTime
:
searchParams
.
get
(
'pinBeginTime'
)
||
undefined
,
pinEndTime
:
searchParams
.
get
(
'pinEndTime'
)
||
undefined
,
...
...
@@ -95,25 +93,9 @@ export const TacticsChat: React.FC = () => {
busiId
:
taskId
,
}
},
[
searchParams
])
const
tacticsMetaFromStorage
=
useMemo
(()
=>
{
const
raw
=
sessionStorage
.
getItem
(
'tacticsMeta'
)
if
(
!
raw
)
{
return
undefined
}
try
{
const
parsed
=
JSON
.
parse
(
raw
)
return
parsed
}
catch
{
// ignore
}
return
undefined
},
[])
const
tacticsMeta
=
useMemo
(()
=>
tacticsMetaFromState
||
tacticsMetaFromQuery
||
tacticsMetaFromStorage
,
[
tacticsMetaFromState
,
tacticsMetaFromQuery
,
tacticsMetaFromStorage
])
// 读取 place=user 时的 userMeta 参数
const
userMetaFromState
=
(
location
.
state
as
{
userMeta
?:
any
}
|
null
)?.
userMeta
const
userMetaFromQuery
=
useMemo
(()
=>
{
// 读取 place=user 时的 userMeta 参数(直接从 query 读取,不再使用 sessionStorage)
const
userMeta
=
useMemo
(()
=>
{
const
place
=
searchParams
.
get
(
'place'
)
if
(
place
!==
'user'
)
{
return
undefined
...
...
@@ -125,23 +107,6 @@ export const TacticsChat: React.FC = () => {
numberType
:
searchParams
.
get
(
'numberType'
)
||
undefined
,
}
},
[
searchParams
])
const
userMetaFromStorage
=
useMemo
(()
=>
{
const
raw
=
sessionStorage
.
getItem
(
'userMeta'
)
if
(
!
raw
)
{
return
undefined
}
try
{
const
parsed
=
JSON
.
parse
(
raw
)
if
(
parsed
?.
place
===
'user'
)
{
return
parsed
}
}
catch
{
// ignore
}
return
undefined
},
[])
const
userMeta
=
useMemo
(()
=>
userMetaFromState
||
userMetaFromQuery
||
userMetaFromStorage
,
[
userMetaFromState
,
userMetaFromQuery
,
userMetaFromStorage
])
// 仅用于创建会话的额外参数(create_conversation)
const
getConversationExtra
=
useCallback
(()
=>
{
...
...
@@ -688,9 +653,9 @@ export const TacticsChat: React.FC = () => {
await
dispatch
(
fetchTacticsConversations
())
if
(
currentIdRef
.
current
)
{
logFullUrl
(
'before navigate reanalyze'
)
navigate
(
`/tactics/chat/
${
currentIdRef
.
current
}
`
)
navigate
(
`/tactics/chat/
${
currentIdRef
.
current
}
${
location
.
search
}
`
)
}
},
[
dispatch
,
navigate
,
handleSubmitQuestion
,
userMeta
,
getNumberTypeWithUserMeta
,
isLoading
,
isAsking
,
logFullUrl
])
},
[
dispatch
,
navigate
,
handleSubmitQuestion
,
userMeta
,
getNumberTypeWithUserMeta
,
isLoading
,
isAsking
,
logFullUrl
,
location
.
search
])
const
handleCancelClear
=
useCallback
(()
=>
{
setShowClearConfirm
(
false
)
...
...
@@ -792,17 +757,15 @@ export const TacticsChat: React.FC = () => {
useEffect
(()
=>
{
if
(
shouldNavigateToNewConversation
&&
currentConversationId
)
{
logFullUrl
(
'before navigate create new conversation'
)
navigate
(
`/tactics/chat/
${
currentConversationId
}
`
,
{
navigate
(
`/tactics/chat/
${
currentConversationId
}
${
location
.
search
}
`
,
{
state
:
{
shouldSendQuestion
:
shouldSendQuestionFromState
,
tacticsMeta
,
userMeta
,
},
replace
:
true
,
})
dispatch
(
clearTacticsNavigationFlag
())
}
},
[
shouldNavigateToNewConversation
,
currentConversationId
,
navigate
,
dispatch
,
shouldSendQuestionFromState
,
tacticsMeta
,
userMeta
,
logFullUrl
])
},
[
shouldNavigateToNewConversation
,
currentConversationId
,
navigate
,
dispatch
,
shouldSendQuestionFromState
,
location
.
search
,
logFullUrl
])
// 处理shouldSendQuestion的变化 - 自动发送问题
useEffect
(()
=>
{
...
...
src/pages/ChatTactics/TacticsHome.tsx
View file @
f7abcbf9
...
...
@@ -25,8 +25,8 @@ export const TacticsHome: React.FC = () => {
defaultValue
:
''
,
})
// from=tactics 时读取
并缓存额外参数(无论 version 是否为 2),用于新建会话
const
tacticsMeta
FromSearch
=
useMemo
(()
=>
{
// from=tactics 时读取
额外参数,用于新建会话(直接从 query 读取,不再使用 sessionStorage)
const
tacticsMeta
=
useMemo
(()
=>
{
const
from
=
searchParams
.
get
(
'from'
)
if
(
from
!==
'tactics'
)
{
return
undefined
...
...
@@ -45,26 +45,9 @@ export const TacticsHome: React.FC = () => {
busiId
:
taskId
,
}
},
[
searchParams
])
const
tacticsMetaFromStorage
=
useMemo
(()
=>
{
const
raw
=
sessionStorage
.
getItem
(
'tacticsMeta'
)
if
(
!
raw
)
{
return
undefined
}
try
{
const
parsed
=
JSON
.
parse
(
raw
)
if
(
parsed
?.
from
===
'tactics'
)
{
return
parsed
}
}
catch
{
// ignore
}
return
undefined
},
[])
const
tacticsMeta
=
useMemo
(()
=>
tacticsMetaFromSearch
||
tacticsMetaFromStorage
,
[
tacticsMetaFromSearch
,
tacticsMetaFromStorage
])
// 读取 place=user 时的 userMeta 参数
const
userMeta
FromSearch
=
useMemo
(()
=>
{
// 读取 place=user 时的 userMeta 参数
(直接从 query 读取,不再使用 sessionStorage)
const
userMeta
=
useMemo
(()
=>
{
const
place
=
searchParams
.
get
(
'place'
)
if
(
place
!==
'user'
)
{
return
undefined
...
...
@@ -78,23 +61,6 @@ export const TacticsHome: React.FC = () => {
busiId
:
searchParams
.
get
(
'userId'
)
||
undefined
,
}
},
[
searchParams
])
const
userMetaFromStorage
=
useMemo
(()
=>
{
const
raw
=
sessionStorage
.
getItem
(
'userMeta'
)
if
(
!
raw
)
{
return
undefined
}
try
{
const
parsed
=
JSON
.
parse
(
raw
)
if
(
parsed
?.
place
===
'user'
)
{
return
parsed
}
}
catch
{
// ignore
}
return
undefined
},
[])
const
userMeta
=
useMemo
(()
=>
userMetaFromSearch
||
userMetaFromStorage
,
[
userMetaFromSearch
,
userMetaFromStorage
])
// 仅用于创建会话的额外参数(对应 create_conversation)
const
getConversationExtra
=
useCallback
(()
=>
{
...
...
@@ -113,20 +79,6 @@ export const TacticsHome: React.FC = () => {
return
{}
},
[
tacticsMeta
,
userMeta
])
// 同步到 sessionStorage,便于跳转后读取;仅在有 meta 时写入,避免覆盖重定向缓存
useEffect
(()
=>
{
if
(
tacticsMeta
)
{
sessionStorage
.
setItem
(
'tacticsMeta'
,
JSON
.
stringify
(
tacticsMeta
))
}
},
[
tacticsMeta
])
// 同步 userMeta 到 sessionStorage
useEffect
(()
=>
{
if
(
userMeta
)
{
sessionStorage
.
setItem
(
'userMeta'
,
JSON
.
stringify
(
userMeta
))
}
},
[
userMeta
])
const
initTacticsConversation
=
()
=>
{
const
fromCollect
=
location
.
state
?.
fromCollect
// 只有在访问问答首页时才创建新对话
...
...
@@ -161,11 +113,9 @@ export const TacticsHome: React.FC = () => {
const
handleCreateConversation
=
useCallback
(
async
(
question
:
string
)
=>
{
// 如果已有会话,直接调用 submit 接口提交问题,然后跳转到聊天页面
if
(
currentConversationId
)
{
navigate
(
`/tactics/chat/
${
currentConversationId
}
`
,
{
navigate
(
`/tactics/chat/
${
currentConversationId
}
${
location
.
search
}
`
,
{
state
:
{
shouldSendQuestion
:
question
,
tacticsMeta
,
userMeta
,
},
})
return
...
...
@@ -178,23 +128,20 @@ export const TacticsHome: React.FC = () => {
shouldSendQuestion
:
question
,
}),
)
},
[
dispatch
,
currentConversationId
,
navigate
,
tacticsMeta
,
userMeta
,
getConversationExtra
])
},
[
dispatch
,
currentConversationId
,
navigate
,
location
.
search
,
getConversationExtra
])
// 监听导航到新对话
useEffect
(()
=>
{
if
(
shouldNavigateToNewConversation
&&
currentConversationId
)
{
const
url
=
`/tactics/chat/
${
currentConversationId
}
`
navigate
(
url
,
{
navigate
(
`/tactics/chat/
${
currentConversationId
}${
location
.
search
}
`
,
{
state
:
{
shouldSendQuestion
,
tacticsMeta
,
userMeta
,
},
replace
:
true
,
})
dispatch
(
clearTacticsNavigationFlag
())
}
},
[
shouldNavigateToNewConversation
,
currentConversationId
,
shouldSendQuestion
,
navigate
,
dispatch
,
tacticsMeta
,
userMeta
])
},
[
shouldNavigateToNewConversation
,
currentConversationId
,
shouldSendQuestion
,
navigate
,
dispatch
,
location
.
search
])
const
login
=
useCallback
(
async
()
=>
{
if
(
hasFetched
.
current
)
{
...
...
src/routes/RouteChangeHandler.tsx
View file @
f7abcbf9
...
...
@@ -22,46 +22,10 @@ export function withRouteChangeHandler(WrappedComponent: React.ComponentType) {
if
(
location
.
pathname
===
'/home'
)
{
const
searchParams
=
new
URLSearchParams
(
location
.
search
)
const
from
=
searchParams
.
get
(
'from'
)
// 获取place参数值
const
place
=
searchParams
.
get
(
'place'
)
if
(
from
===
'tactics'
)
{
// 在重定向前缓存查询参数,供 /tactics 页读取(避免 from 被清理导致丢失)
try
{
if
(
place
)
{
const
userMeta
=
{
cstId
:
searchParams
.
get
(
'cstId'
)
??
undefined
,
userId
:
searchParams
.
get
(
'userId'
)
??
undefined
,
numberType
:
searchParams
.
get
(
'numberType'
)
??
undefined
,
place
,
busiType
:
'02'
,
busiId
:
searchParams
.
get
(
'userId'
)
??
undefined
,
}
sessionStorage
.
setItem
(
'userMeta'
,
JSON
.
stringify
(
userMeta
))
}
else
{
const
meta
=
{
version
:
searchParams
.
get
(
'version'
)
||
undefined
,
taskId
:
searchParams
.
get
(
'taskId'
)
||
undefined
,
pinBeginTime
:
searchParams
.
get
(
'pinBeginTime'
)
||
undefined
,
pinEndTime
:
searchParams
.
get
(
'pinEndTime'
)
||
undefined
,
partOrAll
:
searchParams
.
get
(
'partOrAll'
)
||
undefined
,
channel
:
searchParams
.
get
(
'channel'
)
||
undefined
,
channelName
:
searchParams
.
get
(
'channelName'
)
||
undefined
,
from
,
busiType
:
'02'
,
busiId
:
searchParams
.
get
(
'taskId'
)
||
undefined
,
}
sessionStorage
.
setItem
(
'tacticsMeta'
,
JSON
.
stringify
(
meta
))
}
}
catch
{
// ignore
}
// 重定向到 /tactics,保留其他查询参数
const
newSearchParams
=
new
URLSearchParams
(
location
.
search
)
newSearchParams
.
delete
(
'from'
)
const
newSearch
=
newSearchParams
.
toString
()
navigate
(
`/tactics
${
newSearch
?
`?
${
newSearch
}
`
:
''
}
`
,
{
replace
:
true
})
// 重定向到 /tactics,保留所有查询参数(不再使用 sessionStorage)
const
newSearch
=
location
.
search
navigate
(
`/tactics
${
newSearch
}
`
,
{
replace
:
true
})
return
}
}
...
...
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