Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tea-resources-web
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
张伯涛
tea-resources-web
Commits
52ea4378
Commit
52ea4378
authored
Jun 28, 2024
by
刘帅阳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
页面30分钟未操作,情况token并退出登录
parent
e05c7098
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
1 deletion
+48
-1
App.vue
src/App.vue
+48
-1
No files found.
src/App.vue
View file @
52ea4378
...
@@ -5,7 +5,54 @@
...
@@ -5,7 +5,54 @@
</
template
>
</
template
>
<
script
>
<
script
>
import
{
handleLogout
}
from
'@/api/login'
export
default
{
export
default
{
name
:
'App'
name
:
'App'
,
data
()
{
return
{
timeout
:
null
}
},
mounted
()
{
this
.
setupAutoLogoutTimer
()
// 页面加载时启动监控用户操作
},
methods
:
{
/** 页面加载时启动监控用户操作*/
setupAutoLogoutTimer
()
{
// 监听用户操作事件
window
.
addEventListener
(
'mousemove'
,
this
.
resetTimer
)
window
.
addEventListener
(
'scroll'
,
this
.
resetTimer
)
window
.
addEventListener
(
'keypress'
,
this
.
resetTimer
)
window
.
addEventListener
(
'click'
,
this
.
resetTimer
)
// 启动定时器
this
.
startTimer
()
},
// 重置定时器
resetTimer
()
{
console
.
log
(
'重置定时器重置定时器重置定时器'
)
clearTimeout
(
this
.
timeout
)
this
.
startTimer
()
},
/** 启动定时器*/
startTimer
()
{
console
.
log
(
'启动定时器启动定时器启动定时器'
,
this
.
$route
.
path
)
if
(
this
.
$route
.
path
!==
'/login'
)
{
// 启动一个30分钟的定时器
this
.
timeout
=
setTimeout
(()
=>
{
// 超时处理逻辑,例如清空token并退出登录
console
.
log
(
'退出退出'
)
handleLogout
().
then
(
res
=>
{
if
(
res
.
code
===
200
)
{
this
.
$message
.
success
(
'退出成功!'
)
this
.
$store
.
dispatch
(
'FedLogOut'
).
then
(()
=>
{
location
.
reload
()
})
}
})
},
30
*
60
*
1000
)
// 30分钟
}
}
}
}
}
</
script
>
</
script
>
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