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
9584dd6c
Commit
9584dd6c
authored
Nov 20, 2023
by
guang.wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 添加token过期新标签页登录功能
parent
d61ab8eb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
6 deletions
+51
-6
http.js
lib/http.js
+51
-6
No files found.
lib/http.js
View file @
9584dd6c
...
...
@@ -17,6 +17,7 @@ const instance = axios.create(Object.assign({}, config));
// 挂载扩展配置
instance
.
_extend
=
{
notice
:
''
,
modal
:
''
,
// modal组件
loginUrl
:
''
,
refresTokenHost
:
''
,
dataParseMode
:
'
default
'
...
...
@@ -86,6 +87,54 @@ function clearRequest() {
}
httpQueue
=
[];
}
const
showLoginResultPopups
=
()
=>
{
window
.
modalPopup
=
instance
.
_extend
.
modal
;
instance
.
_extend
.
modal
.
info
({
title
:
'
温馨提示
'
,
content
:
'
登录完成
'
,
okText
:
'
关闭
'
,
});
};
const
openWindow
=
url
=>
{
let
a
=
document
.
createElement
(
'
a
'
);
document
.
body
.
appendChild
(
a
);
a
.
addEventListener
(
'
click
'
,
function
(){
o
=
window
.
open
();
o
.
focus
();
showLoginResultPopups
();
o
.
location
.
href
=
url
;
});
a
.
click
();
document
.
body
.
removeChild
(
a
);
return
false
;
};
const
showLoginPopups
=
()
=>
{
if
(
instance
.
_extend
.
modal
)
{
let
href
=
window
.
location
.
href
;
href
=
href
.
replace
(
/
\?
token=
[
a-z0-9
\-
A-Z
]
+/g
,
''
);
href
=
instance
.
_extend
.
loginUrl
+
'
?url=
'
+
window
.
btoa
(
href
);
instance
.
_extend
.
modal
.
confirm
({
title
:
'
会话过期
'
,
content
:
'
当前会话已过期,请重新登录。
'
,
okText
:
'
登录
'
,
cancelText
:
'
关闭
'
,
onOk
:
function
()
{
instance
.
_extend
.
modal
.
remove
();
openWindow
(
href
);
setTimeout
(()
=>
{
showLoginResultPopups
();
},
1000
);
return
false
;
},
});
}
else
{
window
.
location
.
href
=
instance
.
_extend
.
loginUrl
+
'
?url=
'
+
window
.
btoa
(
href
);
}
};
// http request 拦截器
instance
.
interceptors
.
request
.
use
(
config
=>
{
...
...
@@ -163,9 +212,7 @@ instance.interceptors.response.use(
return
refreshRequest
(
response
.
config
);
}
if
(
+
code
===
4010
||
+
code
===
4011
)
{
let
href
=
window
.
location
.
href
;
href
=
href
.
replace
(
/
\?
token=
[
a-z0-9
\-
A-Z
]
+/g
,
''
);
window
.
location
.
href
=
instance
.
_extend
.
loginUrl
+
'
?url=
'
+
window
.
btoa
(
href
);
showLoginPopups
();
return
;
}
instance
.
_extend
.
notice
.
error
({
...
...
@@ -190,9 +237,7 @@ instance.interceptors.response.use(
switch
(
error
.
response
.
status
)
{
case
401
:
// todo: 系统中有3处处理401的地方
let
href
=
window
.
location
.
href
;
href
=
href
.
replace
(
/
\?
token=
[
a-z0-9
\-
A-Z
]
+/g
,
''
);
window
.
location
.
href
=
instance
.
_extend
.
loginUrl
+
'
?url=
'
+
window
.
btoa
(
href
);
showLoginPopups
();
return
;
}
}
...
...
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