Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CivManage
Project
Project
Details
Activity
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
ReactWeb5
CivManage
Commits
7ec833b7
Commit
7ec833b7
authored
Jan 12, 2023
by
邓超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修改网关拼接问题
parent
c35ae5d7
Pipeline
#66495
passed with stages
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
25 deletions
+36
-25
index.js
src/utils/request/index.js
+36
-25
No files found.
src/utils/request/index.js
View file @
7ec833b7
...
@@ -7,8 +7,8 @@ import toLower from 'lodash/toLower';
...
@@ -7,8 +7,8 @@ import toLower from 'lodash/toLower';
import
isFunction
from
'lodash/isFunction'
;
import
isFunction
from
'lodash/isFunction'
;
import
extendConfig
from
'./defaultConfig'
;
import
extendConfig
from
'./defaultConfig'
;
const
globalConfig
=
{
const
globalConfig
=
{
bizRedirectHandler
:
extendConfig
.
bizRedirectHandler
bizRedirectHandler
:
extendConfig
.
bizRedirectHandler
,
}
}
;
const
globalConfigMatchers
=
[];
const
globalConfigMatchers
=
[];
/* no-unused-vars */
/* no-unused-vars */
const
getMatchedConfig
=
requestConfig
=>
{
const
getMatchedConfig
=
requestConfig
=>
{
...
@@ -19,42 +19,54 @@ const getMatchedConfig = requestConfig => {
...
@@ -19,42 +19,54 @@ const getMatchedConfig = requestConfig => {
const
[
matcher
,
extendConfig
]
=
globalConfigMatchers
[
i
];
const
[
matcher
,
extendConfig
]
=
globalConfigMatchers
[
i
];
// 匹配到第一个matcher就返回了, 存在后续配置不生效的情况
// 匹配到第一个matcher就返回了, 存在后续配置不生效的情况
if
(
matcher
(
requestConfig
))
{
if
(
matcher
(
requestConfig
))
{
console
.
log
(
`matched url:
${
requestConfig
.
url
}
`
)
console
.
log
(
`matched url:
${
requestConfig
.
url
}
`
)
;
return
extendConfig
;
return
extendConfig
;
}
}
return
null
;
return
null
;
}
}
};
};
axios
.
defaults
.
withCredentials
=
true
axios
.
defaults
.
withCredentials
=
true
;
axios
.
interceptors
.
request
.
use
(
function
(
request
){
axios
.
interceptors
.
request
.
use
(
const
token
=
localStorage
.
getItem
(
'token'
)
function
(
request
)
{
const
pandaPublish
=
localStorage
.
getItem
(
'panda-publish'
)
const
token
=
localStorage
.
getItem
(
'token'
);
const
getWay
=
'/PandaCore/GateWay'
const
pandaPublish
=
localStorage
.
getItem
(
'panda-publish'
);
if
(
token
){
const
getWay
=
'/PandaCore/GateWay'
;
request
.
headers
.
Authorization
=
'Bearer '
+
token
if
(
token
)
{
request
.
headers
.
Authorization
=
'Bearer '
+
token
;
}
}
if
(
pandaPublish
){
if
(
pandaPublish
)
{
if
(
request
.
url
!=
'/PandaOMS/OMS/OMSLogin'
&&
request
.
url
!=
'/Publish/OMS/FileCenter/SaveMobileApk'
&&
request
.
url
!=
'/PandaOMS/OMS/HostManager/GetGateWay'
)
console
.
log
(
request
.
url
,
'request.url'
);
request
.
url
=
getWay
+
request
.
url
if
(
request
.
url
!=
'/PandaOMS/OMS/OMSLogin'
&&
request
.
url
!=
'/Publish/OMS/FileCenter/SaveMobileApk'
&&
request
.
url
!=
'/PandaOMS/OMS/HostManager/GetGateWay'
&&
request
.
url
!=
'/PandaCore/GateWay/OcelotSettings/GetReRoutes'
)
request
.
url
=
getWay
+
request
.
url
;
}
}
return
request
return
request
;
},
function
(
error
)
{
},
function
(
error
)
{
// Any status codes that falls outside the range of 2xx cause this function to trigger
// Any status codes that falls outside the range of 2xx cause this function to trigger
// Do something with response error
// Do something with response error
return
Promise
.
reject
(
error
);
return
Promise
.
reject
(
error
);
})
},
axios
.
interceptors
.
response
.
use
(
function
(
response
)
{
);
return
response
axios
.
interceptors
.
response
.
use
(
},
(
error
)
=>
{
function
(
response
)
{
return
response
;
},
error
=>
{
if
(
error
.
response
)
{
if
(
error
.
response
)
{
switch
(
error
.
response
.
status
)
{
switch
(
error
.
response
.
status
)
{
case
401
:
case
401
:
globalConfig
.
bizRedirectHandler
(
error
.
response
)
globalConfig
.
bizRedirectHandler
(
error
.
response
);
}
}
}
}
return
Promise
.
reject
(
error
);
return
Promise
.
reject
(
error
);
})
},
);
export
const
request
=
(
config
,
ctx
)
=>
{
export
const
request
=
(
config
,
ctx
)
=>
{
const
{
const
{
...
@@ -106,7 +118,8 @@ export const request = (config, ctx) => {
...
@@ -106,7 +118,8 @@ export const request = (config, ctx) => {
requestOptions
=
bizRequestAdapter
(
requestOptions
);
requestOptions
=
bizRequestAdapter
(
requestOptions
);
}
}
return
axios
(
requestOptions
).
then
(
raw
=>
raw
&&
raw
.
data
)
return
axios
(
requestOptions
)
.
then
(
raw
=>
raw
&&
raw
.
data
)
.
then
(
.
then
(
res
=>
res
=>
new
Promise
((
resolve
,
reject
)
=>
{
new
Promise
((
resolve
,
reject
)
=>
{
...
@@ -119,9 +132,7 @@ export const request = (config, ctx) => {
...
@@ -119,9 +132,7 @@ export const request = (config, ctx) => {
const
errorDesc
=
bizDevErrorAdapter
?
bizDevErrorAdapter
(
res
)
:
null
;
const
errorDesc
=
bizDevErrorAdapter
?
bizDevErrorAdapter
(
res
)
:
null
;
// 3. 用户级错误信息转换
// 3. 用户级错误信息转换
const
errorMsg
=
bizErrorMessageAdapter
const
errorMsg
=
bizErrorMessageAdapter
?
bizErrorMessageAdapter
(
res
)
:
null
;
?
bizErrorMessageAdapter
(
res
)
:
null
;
// 4. 成功信息转换
// 4. 成功信息转换
const
successMsg
=
bizSuccessMessageAdapter
const
successMsg
=
bizSuccessMessageAdapter
...
...
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