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
411171c8
Commit
411171c8
authored
Aug 11, 2023
by
guang.wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 兼容返回值类型blob
parent
3b4b4681
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
25 deletions
+20
-25
http.js
lib/http.js
+19
-24
package.json
package.json
+1
-1
No files found.
lib/http.js
View file @
411171c8
...
@@ -31,7 +31,7 @@ const onAccessTokenFetched = () => {
...
@@ -31,7 +31,7 @@ const onAccessTokenFetched = () => {
subscriber
=
[];
subscriber
=
[];
};
};
const
refresh
t
oken
=
async
()
=>
{
const
refresh
T
oken
=
async
()
=>
{
return
instance
.
get
(
`
${
instance
.
_extend
.
refresTokenHost
}
/oauth/refreshtoken?refreshtoken=
${
localStorage
.
get
(
'
refreshToken
'
)}
`
);
return
instance
.
get
(
`
${
instance
.
_extend
.
refresTokenHost
}
/oauth/refreshtoken?refreshtoken=
${
localStorage
.
get
(
'
refreshToken
'
)}
`
);
};
};
...
@@ -43,7 +43,7 @@ const refreshRequest = async options => {
...
@@ -43,7 +43,7 @@ const refreshRequest = async options => {
if
(
isRefreshing
)
{
if
(
isRefreshing
)
{
isRefreshing
=
false
;
isRefreshing
=
false
;
await
wait
(
500
);
await
wait
(
500
);
const
data
=
await
refresh
t
oken
();
const
data
=
await
refresh
T
oken
();
localStorage
.
set
(
'
token
'
,
data
.
accessToken
);
localStorage
.
set
(
'
token
'
,
data
.
accessToken
);
onAccessTokenFetched
();
onAccessTokenFetched
();
isRefreshing
=
true
;
isRefreshing
=
true
;
...
@@ -68,7 +68,7 @@ function afterRequest(model, isLoading = true) {
...
@@ -68,7 +68,7 @@ function afterRequest(model, isLoading = true) {
if
(
!
isLoading
)
return
;
if
(
!
isLoading
)
return
;
if
(
!
model
)
model
=
'
common
'
;
if
(
!
model
)
model
=
'
common
'
;
clearTimeout
(
loadingTimeOut
);
clearTimeout
(
loadingTimeOut
);
var
index
=
httpQueue
.
indexOf
(
model
);
const
index
=
httpQueue
.
indexOf
(
model
);
if
(
index
>
-
1
)
{
if
(
index
>
-
1
)
{
httpQueue
.
splice
(
index
,
1
);
httpQueue
.
splice
(
index
,
1
);
}
}
...
@@ -81,8 +81,8 @@ function afterRequest(model, isLoading = true) {
...
@@ -81,8 +81,8 @@ function afterRequest(model, isLoading = true) {
}
}
function
clearRequest
()
{
function
clearRequest
()
{
let
modelArr
=
Array
.
from
(
new
Set
(
httpQueue
));
let
modelArr
=
Array
.
from
(
new
Set
(
httpQueue
));
for
(
let
i
=
0
;
i
<
modelArr
.
length
;
i
++
)
{
for
(
const
model
of
modelArr
)
{
Bus
.
$emit
(
`
${
model
Arr
[
i
]
}
HideLoading`
);
Bus
.
$emit
(
`
${
model
}
HideLoading`
);
}
}
httpQueue
=
[];
httpQueue
=
[];
}
}
...
@@ -119,18 +119,12 @@ instance.interceptors.request.use(
...
@@ -119,18 +119,12 @@ instance.interceptors.request.use(
}
}
}
}
// todo: 某些接口不支持operator参数的话,需要排除
//普通的get请求
if
(
config
.
method
===
'
post
'
||
config
.
method
===
'
get
'
)
{
// TODO: 某些接口不支持operator参数的话,需要排除
if
(
typeof
config
.
data
===
'
object
'
)
{
if
(
config
.
method
===
'
get
'
&&
config
.
url
.
indexOf
(
'
offline_record
'
)
!==
-
1
)
{
}
else
if
(
typeof
config
.
data
===
'
string
'
&&
config
.
method
===
'
post
'
)
{
}
else
if
(
config
.
method
===
'
get
'
)
{
// //普通的get请求
if
(
config
.
url
.
indexOf
(
'
offline_record
'
)
!==
-
1
)
{
config
.
data
=
true
;
config
.
data
=
true
;
config
.
headers
.
common
[
'
content-type
'
]
=
'
application/x-www-form-urlencoded
'
;
config
.
headers
.
common
[
'
content-type
'
]
=
'
application/x-www-form-urlencoded
'
;
}
}
}
}
return
config
;
return
config
;
},
},
error
=>
{
error
=>
{
...
@@ -144,7 +138,7 @@ instance.interceptors.response.use(
...
@@ -144,7 +138,7 @@ instance.interceptors.response.use(
if
(
response
.
headers
[
'
content-type
'
]
===
'
application/octet-stream
'
||
(
response
.
headers
[
'
content-type
'
]
===
'
application/vnd.ms-excel;charset=UTF-8
'
&&
response
.
data
.
byteLength
!==
'
undefied
'
))
{
if
(
response
.
headers
[
'
content-type
'
]
===
'
application/octet-stream
'
||
(
response
.
headers
[
'
content-type
'
]
===
'
application/vnd.ms-excel;charset=UTF-8
'
&&
response
.
data
.
byteLength
!==
'
undefied
'
))
{
return
response
.
data
;
return
response
.
data
;
}
}
if
(
response
.
config
.
responseType
===
'
arraybuffer
'
)
{
if
(
[
'
blob
'
,
'
arraybuffer
'
].
includes
(
response
.
config
.
responseType
)
)
{
return
response
.
data
;
return
response
.
data
;
}
}
...
@@ -152,23 +146,24 @@ instance.interceptors.response.use(
...
@@ -152,23 +146,24 @@ instance.interceptors.response.use(
// 200 - 300 之间的都是正常响应
// 200 - 300 之间的都是正常响应
if
(
response
.
status
>
200
||
response
.
status
<
300
)
{
if
(
response
.
status
>
200
||
response
.
status
<
300
)
{
const
codeArr
=
[
0
,
'
0
'
,
2000
];
const
codeArr
=
[
0
,
'
0
'
,
2000
];
if
(
response
.
data
&&
((
response
.
data
.
code
===
'
0000
'
&&
response
.
data
.
businessCode
===
'
0000
'
)
||
codeArr
.
includes
(
response
.
data
.
code
)))
{
const
code
=
response
.
data
&&
response
.
data
.
code
;
if
(
response
.
data
&&
((
code
===
'
0000
'
&&
response
.
data
.
businessCode
===
'
0000
'
)
||
codeArr
.
includes
(
code
)))
{
if
(
instance
.
_extend
.
dataParseMode
===
'
NOT_PARSE
'
)
{
if
(
instance
.
_extend
.
dataParseMode
===
'
NOT_PARSE
'
)
{
return
response
.
data
;
return
response
.
data
;
}
}
if
(
instance
.
_extend
.
dataParseMode
===
'
PARSE_BODY
'
&&
response
.
data
.
code
===
0
)
{
if
(
instance
.
_extend
.
dataParseMode
===
'
PARSE_BODY
'
&&
code
===
0
)
{
return
response
.
data
.
body
;
return
response
.
data
.
body
;
}
}
return
response
.
data
.
data
||
response
.
data
;
return
response
.
data
.
data
||
response
.
data
;
}
}
if
(
response
.
data
.
code
===
4033
)
{
if
(
+
code
===
4033
)
{
// token过期;
// token过期;
return
refreshRequest
(
response
.
config
);
return
refreshRequest
(
response
.
config
);
}
}
if
(
response
.
data
.
code
===
4010
||
response
.
data
.
code
===
4011
)
{
if
(
+
code
===
4010
||
+
code
===
4011
)
{
var
href
=
window
.
location
.
href
;
let
href
=
window
.
location
.
href
;
href
=
href
.
replace
(
/
\?
token=
[
a-z0-9
\-
A-Z
]
+/g
,
''
);
href
=
href
.
replace
(
/
\?
token=
[
a-z0-9
\-
A-Z
]
+/g
,
''
);
window
.
location
.
href
=
instance
.
_extend
.
loginUrl
+
'
?url=
'
+
window
.
btoa
(
href
);
window
.
location
.
href
=
instance
.
_extend
.
loginUrl
+
'
?url=
'
+
window
.
btoa
(
href
);
return
;
return
;
...
@@ -195,7 +190,7 @@ instance.interceptors.response.use(
...
@@ -195,7 +190,7 @@ instance.interceptors.response.use(
switch
(
error
.
response
.
status
)
{
switch
(
error
.
response
.
status
)
{
case
401
:
case
401
:
// todo: 系统中有3处处理401的地方
// todo: 系统中有3处处理401的地方
var
href
=
window
.
location
.
href
;
let
href
=
window
.
location
.
href
;
href
=
href
.
replace
(
/
\?
token=
[
a-z0-9
\-
A-Z
]
+/g
,
''
);
href
=
href
.
replace
(
/
\?
token=
[
a-z0-9
\-
A-Z
]
+/g
,
''
);
window
.
location
.
href
=
instance
.
_extend
.
loginUrl
+
'
?url=
'
+
window
.
btoa
(
href
);
window
.
location
.
href
=
instance
.
_extend
.
loginUrl
+
'
?url=
'
+
window
.
btoa
(
href
);
return
;
return
;
...
@@ -299,7 +294,7 @@ const http = {
...
@@ -299,7 +294,7 @@ const http = {
});
});
},
},
cancel
()
{
cancel
()
{
cancelArr
.
map
(
cancel
=>
cancel
());
cancelArr
.
forEach
(
cancel
=>
cancel
());
},
},
};
};
...
...
package.json
View file @
411171c8
{
{
"name"
:
"@qg/sys-sdk"
,
"name"
:
"@qg/sys-sdk"
,
"version"
:
"1.0.1
8
"
,
"version"
:
"1.0.1
9
"
,
"description"
:
""
,
"description"
:
""
,
"main"
:
"index.js"
,
"main"
:
"index.js"
,
"scripts"
:
{
"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