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
0526f0f1
Commit
0526f0f1
authored
Dec 31, 2025
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:策略&&用户部分多次调用sso_login接口
parent
fae4ab5f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
114 deletions
+14
-114
src/pages/ChatTactics/TacticsChat.tsx
+6
-56
src/pages/ChatTactics/TacticsHome.tsx
+8
-58
No files found.
src/pages/ChatTactics/TacticsChat.tsx
View file @
0526f0f1
...
...
@@ -16,7 +16,6 @@ import { TacticsChatEditor } from '@/components/TacticsChatEditor'
import
type
{
ChatRecord
}
from
'@/types/chat'
import
{
fetchTacticsQaRecordPage
}
from
'@/api/tactics'
import
{
fetchCheckTokenApi
,
fetchStreamResponse
}
from
'@/api/chat'
import
{
fetchLoginByToken
,
fetchLoginByUid
}
from
'@/api/common'
import
{
clearTacticsNavigationFlag
,
clearTacticsShouldSendQuestion
,
createTacticsConversation
,
deleteTacticsConversations
,
fetchTacticsConversations
}
from
'@/store/tacticsSlice'
import
type
{
RootState
}
from
'@/store'
import
{
useAppDispatch
,
useAppSelector
}
from
'@/store/hook'
...
...
@@ -42,7 +41,6 @@ export const TacticsChat: React.FC = () => {
useEffect
(()
=>
{
logFullUrl
(
'mount or location change'
)
},
[
logFullUrl
])
const
viteOutputObj
=
import
.
meta
.
env
.
VITE_OUTPUT_OBJ
||
'open'
const
[
isLoading
,
setIsLoading
]
=
useState
(
false
)
const
[
allItems
,
setAllItems
]
=
useState
<
ChatRecord
[]
>
([])
const
[
historyDividers
,
setHistoryDividers
]
=
useState
<
{
index
:
number
,
time
:
string
}[]
>
([])
...
...
@@ -60,10 +58,9 @@ export const TacticsChat: React.FC = () => {
}
=
useAppSelector
((
state
:
RootState
)
=>
state
.
tactics
)
const
isAsking
=
useAppSelector
((
state
:
RootState
)
=>
state
.
chat
.
isAsking
)
const
[
searchParams
]
=
useSearchParams
()
const
hasFetched
=
useRef
(
false
)
const
showToast
=
useToast
()
// 使用 useLocalStorageState 管理 token,与原有逻辑保持一致
const
[
token
,
setToken
]
=
useLocalStorageState
<
string
|
undefined
>
(
'__TOKEN__'
,
{
const
[
token
]
=
useLocalStorageState
<
string
|
undefined
>
(
'__TOKEN__'
,
{
defaultValue
:
''
,
})
// 优先从 location.state 获取,其次从 Redux state 获取
...
...
@@ -174,55 +171,6 @@ export const TacticsChat: React.FC = () => {
return
`
${
date
.
getFullYear
()}
-
${
pad
(
date
.
getMonth
()
+
1
)}
-
${
pad
(
date
.
getDate
())}
${
pad
(
date
.
getHours
())}
:
${
pad
(
date
.
getMinutes
())}
:
${
pad
(
date
.
getSeconds
())}
`
}
// 登录逻辑(复用原有逻辑,与 TacticsHome.tsx 保持一致)
const
login
=
useCallback
(
async
()
=>
{
if
(
hasFetched
.
current
)
{
return
}
hasFetched
.
current
=
true
const
url
=
new
URL
(
window
.
location
.
href
)
const
searchParams
=
new
URLSearchParams
(
url
.
search
)
const
_loginCode
=
searchParams
.
get
(
'loginCode'
)
let
res
=
{}
as
any
if
(
viteOutputObj
===
'inner'
)
{
if
(
_loginCode
)
{
res
=
await
fetchLoginByToken
(
_loginCode
)
if
(
res
.
data
)
{
setToken
(
res
.
data
.
token
)
window
.
dispatchEvent
(
new
StorageEvent
(
'storage'
,
{
key
:
'__TOKEN__'
,
oldValue
:
token
,
newValue
:
res
.
data
.
token
,
url
:
window
.
location
.
href
,
storageArea
:
localStorage
,
}),
)
dispatch
(
fetchTacticsConversations
())
}
}
else
{
dispatch
(
fetchTacticsConversations
())
}
}
else
{
res
=
await
fetchLoginByUid
(
'123123'
)
if
(
res
.
data
)
{
setToken
(
res
.
data
.
token
)
window
.
dispatchEvent
(
new
StorageEvent
(
'storage'
,
{
key
:
'__TOKEN__'
,
oldValue
:
token
,
newValue
:
res
.
data
.
token
,
url
:
window
.
location
.
href
,
storageArea
:
localStorage
,
}),
)
dispatch
(
fetchTacticsConversations
())
}
}
},
[
setToken
,
dispatch
,
token
,
viteOutputObj
])
/** 处理正常stream的数据 */
const
handleStreamMesageData
=
(
msg
:
any
,
question
:
string
)
=>
{
setAllItems
((
prevItems
)
=>
{
...
...
@@ -705,10 +653,12 @@ export const TacticsChat: React.FC = () => {
}
},
[
id
,
getUserQaRecordPage
,
dispatch
])
//
初始化时调用登录(登录成功后会自动创建会话)
//
当 token 存在时,获取会话列表
useEffect
(()
=>
{
login
()
},
[
login
])
if
(
token
)
{
dispatch
(
fetchTacticsConversations
())
}
},
[
token
,
dispatch
])
// 进入会话后自动触发一次提交,默认 question 为“策略分析”,busiType 02 / recordType A02
const
hasAutoSubmittedRef
=
useRef
(
false
)
...
...
src/pages/ChatTactics/TacticsHome.tsx
View file @
0526f0f1
// 问答功能独立首页
import
type
React
from
'react'
import
{
useCallback
,
useEffect
,
useMemo
,
useRef
}
from
'react'
import
{
useCallback
,
useEffect
,
useMemo
}
from
'react'
import
{
useLocation
,
useNavigate
,
useSearchParams
}
from
'react-router-dom'
import
{
useLocalStorageState
}
from
'ahooks'
import
styles
from
'../Home/Home.module.less'
...
...
@@ -8,20 +8,17 @@ import { TacticsWelcome } from './components/TacticsWelcome'
import
{
clearTacticsNavigationFlag
,
createTacticsConversation
,
fetchTacticsConversations
}
from
'@/store/tacticsSlice'
import
{
useAppDispatch
,
useAppSelector
}
from
'@/store/hook'
import
type
{
RootState
}
from
'@/store'
import
{
fetchLoginByToken
,
fetchLoginByUid
}
from
'@/api/common'
import
{
getUserRolesFromRoute
}
from
'@/lib/utils'
import
{
TacticsChatEditor
}
from
'@/components/TacticsChatEditor'
export
const
TacticsHome
:
React
.
FC
=
()
=>
{
const
viteOutputObj
=
import
.
meta
.
env
.
VITE_OUTPUT_OBJ
||
'open'
const
dispatch
=
useAppDispatch
()
const
location
=
useLocation
()
const
navigate
=
useNavigate
()
const
[
searchParams
]
=
useSearchParams
()
const
hasFetched
=
useRef
(
false
)
const
{
shouldNavigateToNewConversation
,
currentConversationId
,
shouldSendQuestion
}
=
useAppSelector
((
state
:
RootState
)
=>
state
.
tactics
)
const
[
token
,
setToken
]
=
useLocalStorageState
<
string
|
undefined
>
(
'__TOKEN__'
,
{
const
[
token
]
=
useLocalStorageState
<
string
|
undefined
>
(
'__TOKEN__'
,
{
defaultValue
:
''
,
})
...
...
@@ -144,65 +141,18 @@ export const TacticsHome: React.FC = () => {
}
},
[
shouldNavigateToNewConversation
,
currentConversationId
,
shouldSendQuestion
,
navigate
,
dispatch
,
location
.
search
])
const
login
=
useCallback
(
async
()
=>
{
if
(
hasFetched
.
current
)
{
return
}
hasFetched
.
current
=
true
const
url
=
new
URL
(
window
.
location
.
href
)
const
searchParams
=
new
URLSearchParams
(
url
.
search
)
const
_loginCode
=
searchParams
.
get
(
'loginCode'
)
let
res
=
{}
as
any
if
(
viteOutputObj
===
'inner'
)
{
if
(
_loginCode
)
{
res
=
await
fetchLoginByToken
(
_loginCode
)
if
(
res
.
data
)
{
setToken
(
res
.
data
.
token
)
window
.
dispatchEvent
(
new
StorageEvent
(
'storage'
,
{
key
:
'__TOKEN__'
,
oldValue
:
token
,
newValue
:
res
.
data
.
token
,
url
:
window
.
location
.
href
,
storageArea
:
localStorage
,
}),
)
initTacticsConversation
()
dispatch
(
fetchTacticsConversations
())
}
}
else
{
initTacticsConversation
()
dispatch
(
fetchTacticsConversations
())
}
}
else
{
res
=
await
fetchLoginByUid
(
'123123'
)
if
(
res
.
data
)
{
setToken
(
res
.
data
.
token
)
window
.
dispatchEvent
(
new
StorageEvent
(
'storage'
,
{
key
:
'__TOKEN__'
,
oldValue
:
token
,
newValue
:
res
.
data
.
token
,
url
:
window
.
location
.
href
,
storageArea
:
localStorage
,
}),
)
initTacticsConversation
()
dispatch
(
fetchTacticsConversations
())
}
}
},
[
setToken
,
dispatch
,
token
])
// 监听路由参数变化
useEffect
(()
=>
{
getUserRolesFromRoute
()
},
[
location
.
search
])
// 当 token 存在时,初始化会话和获取会话列表
useEffect
(()
=>
{
login
()
},
[])
if
(
token
)
{
initTacticsConversation
()
dispatch
(
fetchTacticsConversations
())
}
},
[
token
,
dispatch
])
return
(
<
div
...
...
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