Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cs_vsofpm
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wuhao
cs_vsofpm
Commits
dd6cf76f
Commit
dd6cf76f
authored
Nov 14, 2025
by
左玲玲
😬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
token免登录
parent
884176e4
Pipeline
#8436
failed with stages
in 35 minutes and 37 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
23 deletions
+28
-23
AccountPopover.jsx
src/layouts/dashboard/header/AccountPopover.jsx
+1
-0
index.jsx
src/layouts/index.jsx
+27
-23
No files found.
src/layouts/dashboard/header/AccountPopover.jsx
View file @
dd6cf76f
...
...
@@ -121,6 +121,7 @@ export default function AccountPopover() {
if
(
path
===
"/user/login"
)
{
doFetch
({
url
:
"/system/logout"
,
params
:
{}
}).
then
((
res
)
=>
{
if
(
res
?.
code
===
"0000"
)
{
localStorage
.
clear
();
path
&&
navigate
(
path
);
}
});
...
...
src/layouts/index.jsx
View file @
dd6cf76f
...
...
@@ -7,6 +7,7 @@ import Snackbar from "@mui/material/Snackbar";
import
*
as
Sentry
from
"@sentry/react"
;
import
{
Outlet
,
useModel
,
useNavigate
,
useLocation
}
from
"@umijs/max"
;
import
{
ConfigProvider
}
from
"antd"
;
import
{
doFetch
}
from
"@/utils/doFetch"
;
import
locale
from
"antd/locale/zh_CN"
;
import
"dayjs/locale/zh-cn"
;
import
ThemeProvider
from
"./theme"
;
...
...
@@ -75,36 +76,39 @@ function App() {
// ---------- 初始化时检查 token ----------
useEffect
(()
=>
{
// 获取 URL 参数
const
url
=
new
URL
(
window
.
location
.
href
);
const
token
=
url
.
searchParams
.
get
(
'token'
)
||
new
URLSearchParams
(
window
.
location
.
hash
.
split
(
'?'
)[
1
]
||
''
).
get
(
'token'
);
if
(
!
localStorage
.
getItem
(
"TOKENES"
))
{
// 获取 URL 参数
const
url
=
new
URL
(
window
.
location
.
href
);
const
token
=
url
.
searchParams
.
get
(
'token'
)
||
new
URLSearchParams
(
window
.
location
.
hash
.
split
(
'?'
)[
1
]
||
''
).
get
(
'token'
);
if
(
token
)
{
localStorage
.
setItem
(
"TOKENES"
,
token
);
// ✅ 清理 URL 中的 token 参数
const
newUrl
=
window
.
location
.
origin
+
'/#'
+
window
.
location
.
hash
.
split
(
'#'
)[
1
];
window
.
history
.
replaceState
(
null
,
''
,
newUrl
);
(
async
()
=>
{
try
{
let
user
=
await
fetchUserInfo
();
if
(
user
)
{
navigate
(
"/work"
,
{
replace
:
true
});
}
else
{
if
(
token
)
{
localStorage
.
setItem
(
"TOKENES"
,
token
);
// ✅ 清理 URL 中的 token 参数
const
newUrl
=
window
.
location
.
origin
+
'/#'
+
window
.
location
.
hash
.
split
(
'#'
)[
1
];
window
.
history
.
replaceState
(
null
,
''
,
newUrl
);
(
async
()
=>
{
try
{
let
user
=
await
doFetch
({
url
:
"/system/me"
,
});
if
(
user
?.
code
===
"0000"
)
{
localStorage
.
setItem
(
"ID"
,
user
?.
data
?.
data
?.
id
);
navigate
(
"/work"
,
{
replace
:
true
});
}
else
{
localStorage
.
clear
();
navigate
(
"/user/login"
,
{
replace
:
true
});
}
}
catch
(
err
)
{
localStorage
.
clear
();
navigate
(
"/user/login"
,
{
replace
:
true
});
}
}
catch
(
err
)
{
})();
}
else
{
// 没有 token,若不在登录页则跳转
if
(
!
location
.
pathname
.
startsWith
(
"/user"
))
{
localStorage
.
clear
();
navigate
(
"/user/login"
,
{
replace
:
true
});
}
})();
}
else
{
// 没有 token,若不在登录页则跳转
if
(
!
location
.
pathname
.
startsWith
(
"/user"
))
{
localStorage
.
clear
();
navigate
(
"/user/login"
,
{
replace
:
true
});
}
}
},
[]);
...
...
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