Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ant-design-pro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
ant-design-pro
Commits
ac1f46f4
Commit
ac1f46f4
authored
Jun 26, 2019
by
duanledexianxianxian
😁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sync
parent
5c414d78
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
19 deletions
+33
-19
src/config.js
src/config.js
+1
-1
src/utils/kim-request.js
src/utils/kim-request.js
+5
-2
src/utils/request.js
src/utils/request.js
+27
-16
No files found.
src/config.js
View file @
ac1f46f4
...
...
@@ -5,7 +5,7 @@ export default {
storeNameSpace
:
'
kim
'
,
headers
:
()
=>
({
Authorization
:
'
1
eyJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjMzLCJ1c24iOiLmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrociLCJzdGEiOjE1NjE0MzAzMzI4NzQsImxpZCI6Im91eWFuZ2JveXUifQ.209scGXfvjPj7KgvXhzrI4ciHg6aTDt8LQ1Z2Nw-ZxA
'
,
'
eyJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjMzLCJ1c24iOiLmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrociLCJzdGEiOjE1NjE0MzAzMzI4NzQsImxpZCI6Im91eWFuZ2JveXUifQ.209scGXfvjPj7KgvXhzrI4ciHg6aTDt8LQ1Z2Nw-ZxA
'
,
}),
resCodeKey
:
'
code
'
,
// 后台正常返回错误编码
resMessageKey
:
'
message
'
,
// 后台正常返回错误编码
...
...
src/utils/kim-request.js
View file @
ac1f46f4
...
...
@@ -44,14 +44,17 @@ class HttpRequest {
res
=>
{
// success
this
.
destroy
(
url
);
if
(
options
.
successHandler
instanceof
Function
)
{
options
.
successHandler
({
queues
:
this
.
queues
,
res
,
options
});
}
const
{
data
,
status
}
=
res
;
return
{
data
,
status
};
},
error
=>
{
// error
this
.
destroy
(
url
);
if
(
error
.
response
)
{
console
.
log
(
error
.
response
);
if
(
options
.
errorHandler
instanceof
Function
)
{
options
.
errorHandler
({
queues
:
this
.
queues
,
error
,
options
}
);
}
return
Promise
.
reject
(
error
);
},
...
...
src/utils/request.js
View file @
ac1f46f4
...
...
@@ -2,6 +2,10 @@ import { notification } from 'antd';
import
HttpRequest
from
'
./kim-request
'
;
import
config
from
'
@/config
'
;
/**
* todo 还需处理国际化
*/
const
codeMessage
=
{
200
:
'
服务器成功返回请求的数据。
'
,
201
:
'
新建或修改数据成功。
'
,
...
...
@@ -55,41 +59,48 @@ const axios = new HttpRequest({
* @param {配置项} more
*/
const
handleResponse
=
(
response
,
more
)
=>
{
console
.
log
(
'
handleResponse
'
,
response
);
const
{
data
}
=
response
;
//
if
(
`
${
data
[
resCodeKey
]}
`
!==
`
${
successCode
}
`
)
{
if
(
isThrowError
)
{
const
errorMessage
=
data
[
resMessageKey
]
||
'
后端接口返回异常
'
;
const
error
=
new
Error
(
data
[
resCodeKey
]);
let
error
=
new
Error
();
error
=
{
...
error
,
...
data
};
error
.
code
=
data
[
resCodeKey
];
error
.
message
=
errorMessage
;
return
Promise
.
reject
(
error
);
}
}
// success
return
data
;
};
const
handleError
=
error
=>
{
console
.
log
(
'
handleError
'
);
const
{
response
}
=
error
;
console
.
log
(
'
handleError
'
,
response
);
// 如果response存在
if
(
response
&&
response
.
status
)
{
// const errorText = codeMessage[response.status] || response.statusText;
// const {
// status,
// config: { url },
// } = response;
console
.
log
(
'
什么情况
'
);
const
errorText
=
codeMessage
[
response
.
status
]
||
response
.
statusText
;
const
{
status
,
config
:
{
url
},
}
=
response
;
notification
.
error
({
message
:
'
请求错误
'
,
description
:
'
111
'
,
duration
:
100
,
message
:
`请求错误
${
status
}
:
${
url
}
`
,
description
:
errorText
,
});
}
else
{
const
{
code
,
message
}
=
error
;
notification
.
error
({
key
:
`notification_
${
code
?
message
:
code
}
`
,
message
:
'
请求错误
'
,
description
:
message
,
});
}
if
(
isThrowError
)
{
throw
error
;
}
else
{
return
error
;
}
};
export
default
function
request
(
url
,
options
=
{},
more
=
{})
{
...
...
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