Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sys-sdk
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ui
sys-sdk
Commits
8c7bdd80
Commit
8c7bdd80
authored
Dec 20, 2023
by
guang.wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 添加记录最后一次请求时间,超5小时之间跳转登录没超5小时弹窗登录
parent
aa8dc4c5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
6 deletions
+60
-6
http.js
lib/http.js
+30
-5
utils.js
lib/utils.js
+29
-0
package.json
package.json
+1
-1
No files found.
lib/http.js
View file @
8c7bdd80
import
axios
from
'
axios
'
;
import
localStorage
from
'
./localStorage
'
;
import
Bus
from
'
./bus
'
;
import
{
debounce
}
from
'
./utils
'
;
let
CancelToken
=
axios
.
CancelToken
;
// axios中断取消请求
let
httpQueue
=
[];
// 请求队列
...
...
@@ -111,8 +112,32 @@ const openWindow = url => {
return
false
;
};
const
showLoginPopups
=
()
=>
{
if
(
instance
.
_extend
.
modal
)
{
/**
* 验证token是否超过5小时
* **/
const
checkTokenTimeOut5Hours
=
()
=>
{
const
tokenTime
=
+
localStorage
.
get
(
'
token-time
'
);
const
now
=
new
Date
().
getTime
();
return
now
-
tokenTime
>
5
*
60
*
60
*
1000
;
};
/**
* 刷新token时间戳 记录最后一次请求时间
* **/
const
refreshTokenTimeOut
=
debounce
(()
=>
{
const
now
=
new
Date
().
getTime
();
localStorage
.
set
(
'
token-time
'
,
now
);
},
100
);
/**
* token 过期处理函数
* token过期超过5小时,直接跳转登录页
* 未超过5小时,弹窗提示跳转新标签页登录
* **/
const
showLoginPopups
=
debounce
(()
=>
{
if
(
checkTokenTimeOut5Hours
()
||
!
instance
.
_extend
.
modal
)
{
window
.
location
.
href
=
instance
.
_extend
.
loginUrl
+
'
?url=
'
+
window
.
btoa
(
href
);
}
else
{
let
href
=
window
.
location
.
href
;
href
=
href
.
replace
(
/
\?
token=
[
a-z0-9
\-
A-Z
]
+/g
,
''
);
href
=
instance
.
_extend
.
loginUrl
+
'
?url=
'
+
window
.
btoa
(
href
);
...
...
@@ -130,10 +155,8 @@ const showLoginPopups = () => {
return
false
;
},
});
}
else
{
window
.
location
.
href
=
instance
.
_extend
.
loginUrl
+
'
?url=
'
+
window
.
btoa
(
href
);
}
};
}
,
100
)
;
// http request 拦截器
instance
.
interceptors
.
request
.
use
(
...
...
@@ -197,6 +220,8 @@ instance.interceptors.response.use(
const
codeArr
=
[
0
,
'
0
'
,
2000
];
const
code
=
response
.
data
&&
response
.
data
.
code
;
if
(
response
.
data
&&
((
code
===
'
0000
'
&&
response
.
data
.
businessCode
===
'
0000
'
)
||
codeArr
.
includes
(
code
)))
{
// 记录最后一次请求时间
refreshTokenTimeOut
();
if
(
instance
.
_extend
.
dataParseMode
===
'
NOT_PARSE
'
)
{
return
response
.
data
;
}
...
...
lib/utils.js
0 → 100644
View file @
8c7bdd80
/**
* 防抖函数
* @param {Function} fn 需要防抖的函数
* @param {Number} interval 防抖时间间隔
* @param {Boolean} immediate 是否立即执行
* **/
export
function
debounce
(
fn
,
interval
,
immediate
)
{
let
flag
=
true
;
const
time
=
interval
||
1000
;
let
timer
=
null
;
return
function
()
{
if
(
!
immediate
)
{
timer
&&
clearTimeout
(
timer
);
timer
=
setTimeout
(()
=>
{
fn
.
apply
(
this
,
arguments
);
},
time
);
}
else
{
if
(
flag
)
{
fn
.
apply
(
this
,
arguments
);
flag
=
false
;
return
;
}
timer
&&
clearTimeout
(
timer
);
timer
=
setTimeout
(()
=>
{
fn
.
apply
(
this
,
arguments
);
},
time
);
}
};
}
\ No newline at end of file
package.json
View file @
8c7bdd80
{
"name"
:
"@qg/sys-sdk"
,
"version"
:
"1.0.2
1
"
,
"version"
:
"1.0.2
2
"
,
"description"
:
""
,
"main"
:
"index.js"
,
"scripts"
:
{
...
...
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