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
884176e4
Commit
884176e4
authored
Nov 13, 2025
by
左玲玲
😬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
如果路径带token那就直接进入系统,否则跳转到登录页
parent
48c3bc17
Pipeline
#8428
failed with stages
in 33 minutes and 53 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
10 deletions
+41
-10
app.jsx
src/app.jsx
+2
-1
index.jsx
src/layouts/index.jsx
+39
-6
Welcome.jsx
src/pages/Welcome.jsx
+0
-3
No files found.
src/app.jsx
View file @
884176e4
...
...
@@ -17,6 +17,7 @@ const loginPath = "/user/login";
* @see https://umijs.org/zh-CN/plugins/plugin-initial-state
* */
export
async
function
getInitialState
()
{
let
token
=
localStorage
.
getItem
(
'TOKENES'
);
const
fetchUserInfo
=
async
()
=>
{
try
{
const
msg
=
await
doFetch
({
...
...
@@ -31,7 +32,7 @@ export async function getInitialState() {
};
// 如果不是登录页面,执行
const
{
location
}
=
history
;
if
(
!
location
.
pathname
.
includes
(
"user"
))
{
if
(
!
location
.
pathname
.
includes
(
"user"
)
&&
token
)
{
const
currentUser
=
await
fetchUserInfo
();
localStorage
.
setItem
(
"ID"
,
currentUser
?.
id
);
return
{
...
...
src/layouts/index.jsx
View file @
884176e4
import
React
,
{
useEffect
}
from
"react"
;
import
{
AlertTitle
}
from
"@mui/material"
;
import
MuiAlert
from
"@mui/material/Alert"
;
import
CssBaseline
from
"@mui/material/CssBaseline"
;
import
Slide
from
"@mui/material/Slide"
;
import
Snackbar
from
"@mui/material/Snackbar"
;
import
*
as
Sentry
from
"@sentry/react"
;
import
{
Outlet
,
useModel
}
from
"@umijs/max"
;
import
{
Outlet
,
useModel
,
useNavigate
,
useLocation
}
from
"@umijs/max"
;
import
{
ConfigProvider
}
from
"antd"
;
import
locale
from
"antd/locale/zh_CN"
;
import
"dayjs/locale/zh-cn"
;
import
React
from
"react"
;
import
ThemeProvider
from
"./theme"
;
// 自定义主题
...
...
@@ -60,6 +60,9 @@ const Alert = React.forwardRef(function Alert(props, ref) {
});
function
App
()
{
const
{
initialState
:
{
message
,
fetchUserInfo
},
setInitialState
}
=
useModel
(
"@@initialState"
);
const
navigate
=
useNavigate
();
const
location
=
useLocation
();
const
handleClose
=
(
event
)
=>
{
setInitialState
((
s
)
=>
({
...
s
,
...
...
@@ -70,11 +73,41 @@ function App() {
}));
};
const
{
initialState
:
{
message
},
setInitialState
,
}
=
useModel
(
"@@initialState"
);
// ---------- 初始化时检查 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
(
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
{
localStorage
.
clear
();
navigate
(
"/user/login"
,
{
replace
:
true
});
}
}
catch
(
err
)
{
localStorage
.
clear
();
navigate
(
"/user/login"
,
{
replace
:
true
});
}
})();
}
else
{
// 没有 token,若不在登录页则跳转
if
(
!
location
.
pathname
.
startsWith
(
"/user"
))
{
localStorage
.
clear
();
navigate
(
"/user/login"
,
{
replace
:
true
});
}
}
},
[]);
return
(
<
ConfigProvider
locale=
{
locale
}
>
<
ThemeProvider
>
...
...
src/pages/Welcome.jsx
View file @
884176e4
...
...
@@ -112,9 +112,6 @@ export default function Welcome() {
}
});
},
[
data
,
currentUser
?.
type
,
menuNum
]);
console
.
log
(
navConfigs
,
currentUser
);
return
(
<
Box
p=
{
2
}
>
<
Typography
component=
{
"h1"
}
align=
"center"
fontSize=
{
24
}
>
...
...
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