Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
csbr-daop
/
fe-data-trusted-space
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
52690beb
authored
2025-04-21 16:12:51 +0800
by
lihua
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
尝试解决登录成功后又报token过期重新登录的问题
1 parent
f21ee3e6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
6 deletions
src/App.vue
src/store/modules/user.ts
src/App.vue
View file @
52690be
...
...
@@ -56,14 +56,22 @@ onMounted(() => {
hotkeys
(
'alt+i'
,
()
=>
{
eventBus
.
emit
(
'global-system-info-toggle'
)
})
//判断token的过期时间。
if
(
!
route
.
fullPath
?.
includes
(
'?code='
))
{
if
(
!
window
.
location
?.
href
?.
includes
(
'?code='
))
{
userStore
.
refreshUserToken
();
}
else
{
localStorage
.
setItem
(
'token'
,
''
);
localStorage
.
setItem
(
'code'
,
''
);
localStorage
.
setItem
(
'state'
,
''
);
localStorage
.
setItem
(
'refresh_token'
,
""
);
localStorage
.
setItem
(
'expiresIn'
,
''
);
}
})
import
.
meta
.
env
.
VITE_APP_DEBUG_TOOL
===
'eruda'
&&
eruda
.
init
()
onUnmounted
(()
=>
{
window
.
onresize
=
null
})
</
script
>
<
template
>
...
...
src/store/modules/user.ts
View file @
52690be
...
...
@@ -81,9 +81,9 @@ const useUserStore = defineStore(
});
}
function
refreshUserToken
(
isExec
=
true
)
{
async
function
refreshUserToken
(
isExec
=
true
)
{
let
expiresIn
=
localStorage
.
getItem
(
'expiresIn'
);
if
(
!
expiresIn
||
(
parseInt
(
expiresIn
)
-
Date
.
now
())
<
-
170000
0
)
{
if
(
!
expiresIn
||
(
parseInt
(
expiresIn
)
-
Date
.
now
())
<
0
)
{
return
;
}
const
process
=
async
()
=>
{
...
...
@@ -97,7 +97,9 @@ const useUserStore = defineStore(
}
}
}
isExec
&&
process
();
if
(
isExec
)
{
await
process
();
}
/** 轮询是否需要刷新token。如果是同步多个调用,则不处理错误的信息。 */
setInterval
(
async
()
=>
{
process
();
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment