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 {
...
@@ -5,7 +5,7 @@ export default {
storeNameSpace
:
'
kim
'
,
storeNameSpace
:
'
kim
'
,
headers
:
()
=>
({
headers
:
()
=>
({
Authorization
:
Authorization
:
'
1
eyJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjMzLCJ1c24iOiLmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrociLCJzdGEiOjE1NjE0MzAzMzI4NzQsImxpZCI6Im91eWFuZ2JveXUifQ.209scGXfvjPj7KgvXhzrI4ciHg6aTDt8LQ1Z2Nw-ZxA
'
,
'
eyJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjMzLCJ1c24iOiLmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrociLCJzdGEiOjE1NjE0MzAzMzI4NzQsImxpZCI6Im91eWFuZ2JveXUifQ.209scGXfvjPj7KgvXhzrI4ciHg6aTDt8LQ1Z2Nw-ZxA
'
,
}),
}),
resCodeKey
:
'
code
'
,
// 后台正常返回错误编码
resCodeKey
:
'
code
'
,
// 后台正常返回错误编码
resMessageKey
:
'
message
'
,
// 后台正常返回错误编码
resMessageKey
:
'
message
'
,
// 后台正常返回错误编码
...
...
src/utils/kim-request.js
View file @
ac1f46f4
...
@@ -44,14 +44,17 @@ class HttpRequest {
...
@@ -44,14 +44,17 @@ class HttpRequest {
res
=>
{
res
=>
{
// success
// success
this
.
destroy
(
url
);
this
.
destroy
(
url
);
if
(
options
.
successHandler
instanceof
Function
)
{
options
.
successHandler
({
queues
:
this
.
queues
,
res
,
options
});
}
const
{
data
,
status
}
=
res
;
const
{
data
,
status
}
=
res
;
return
{
data
,
status
};
return
{
data
,
status
};
},
},
error
=>
{
error
=>
{
// error
// error
this
.
destroy
(
url
);
this
.
destroy
(
url
);
if
(
error
.
response
)
{
if
(
options
.
errorHandler
instanceof
Function
)
{
console
.
log
(
error
.
response
);
options
.
errorHandler
({
queues
:
this
.
queues
,
error
,
options
}
);
}
}
return
Promise
.
reject
(
error
);
return
Promise
.
reject
(
error
);
},
},
...
...
src/utils/request.js
View file @
ac1f46f4
...
@@ -2,6 +2,10 @@ import { notification } from 'antd';
...
@@ -2,6 +2,10 @@ import { notification } from 'antd';
import
HttpRequest
from
'
./kim-request
'
;
import
HttpRequest
from
'
./kim-request
'
;
import
config
from
'
@/config
'
;
import
config
from
'
@/config
'
;
/**
* todo 还需处理国际化
*/
const
codeMessage
=
{
const
codeMessage
=
{
200
:
'
服务器成功返回请求的数据。
'
,
200
:
'
服务器成功返回请求的数据。
'
,
201
:
'
新建或修改数据成功。
'
,
201
:
'
新建或修改数据成功。
'
,
...
@@ -55,41 +59,48 @@ const axios = new HttpRequest({
...
@@ -55,41 +59,48 @@ const axios = new HttpRequest({
* @param {配置项} more
* @param {配置项} more
*/
*/
const
handleResponse
=
(
response
,
more
)
=>
{
const
handleResponse
=
(
response
,
more
)
=>
{
console
.
log
(
'
handleResponse
'
,
response
);
const
{
data
}
=
response
;
const
{
data
}
=
response
;
//
//
if
(
`
${
data
[
resCodeKey
]}
`
!==
`
${
successCode
}
`
)
{
if
(
`
${
data
[
resCodeKey
]}
`
!==
`
${
successCode
}
`
)
{
if
(
isThrowError
)
{
if
(
isThrowError
)
{
const
errorMessage
=
data
[
resMessageKey
]
||
'
后端接口返回异常
'
;
const
errorMessage
=
data
[
resMessageKey
]
||
'
后端接口返回异常
'
;
const
error
=
new
Error
(
data
[
resCodeKey
]);
let
error
=
new
Error
();
error
=
{
...
error
,
...
data
};
error
.
code
=
data
[
resCodeKey
];
error
.
code
=
data
[
resCodeKey
];
error
.
message
=
errorMessage
;
error
.
message
=
errorMessage
;
return
Promise
.
reject
(
error
);
return
Promise
.
reject
(
error
);
}
}
}
}
// success
return
data
;
return
data
;
};
};
const
handleError
=
error
=>
{
const
handleError
=
error
=>
{
console
.
log
(
'
handleError
'
);
const
{
response
}
=
error
;
const
{
response
}
=
error
;
console
.
log
(
'
handleError
'
,
response
);
// 如果response存在
if
(
response
&&
response
.
status
)
{
if
(
response
&&
response
.
status
)
{
// const errorText = codeMessage[response.status] || response.statusText;
const
errorText
=
codeMessage
[
response
.
status
]
||
response
.
statusText
;
// const {
const
{
// status,
status
,
// config: { url },
config
:
{
url
},
// } = response;
}
=
response
;
console
.
log
(
'
什么情况
'
);
notification
.
error
({
notification
.
error
({
message
:
'
请求错误
'
,
message
:
`请求错误
${
status
}
:
${
url
}
`
,
description
:
'
111
'
,
description
:
errorText
,
duration
:
100
,
});
}
else
{
const
{
code
,
message
}
=
error
;
notification
.
error
({
key
:
`notification_
${
code
?
message
:
code
}
`
,
message
:
'
请求错误
'
,
description
:
message
,
});
});
}
}
if
(
isThrowError
)
{
throw
error
;
throw
error
;
}
else
{
return
error
;
}
};
};
export
default
function
request
(
url
,
options
=
{},
more
=
{})
{
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