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
3c1cb6ed
Commit
3c1cb6ed
authored
Jun 25, 2019
by
duanledexianxianxian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
。。。
parent
aa01d58c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
20 deletions
+53
-20
src/app.js
src/app.js
+8
-0
src/config.js
src/config.js
+3
-0
src/utils/kim-request.js
src/utils/kim-request.js
+19
-18
src/utils/request.js
src/utils/request.js
+23
-2
No files found.
src/app.js
0 → 100644
View file @
3c1cb6ed
export
const
dva
=
{
config
:
{
onError
(
e
)
{
console
.
log
(
e
);
e
.
preventDefault
();
},
},
};
src/config.js
View file @
3c1cb6ed
...
@@ -7,5 +7,8 @@ export default {
...
@@ -7,5 +7,8 @@ export default {
Authorization
:
Authorization
:
'
eyJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjMzLCJ1c24iOiLmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrociLCJzdGEiOjE1NjEzNDQyNDg5ODksImxpZCI6Im91eWFuZ2JveXUifQ.FbY-QQLgq8H9CWSo1FhCPgXZJQtte5lhAPC4W45mHmo
'
,
'
eyJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjMzLCJ1c24iOiLmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrociLCJzdGEiOjE1NjEzNDQyNDg5ODksImxpZCI6Im91eWFuZ2JveXUifQ.FbY-QQLgq8H9CWSo1FhCPgXZJQtte5lhAPC4W45mHmo
'
,
}),
}),
resCodeKey
:
'
code
'
,
// 后台正常返回错误编码
resMessageKey
:
'
message
'
,
// 后台正常返回错误编码
successCode
:
'
sys.success
'
,
// 后台正常返回错误编码
successCode
:
'
sys.success
'
,
// 后台正常返回错误编码
isThrowError
:
true
,
};
};
src/utils/kim-request.js
View file @
3c1cb6ed
...
@@ -29,12 +29,12 @@ class HttpRequest {
...
@@ -29,12 +29,12 @@ class HttpRequest {
baseURL
:
this
.
options
.
baseUrl
,
// baseURL
baseURL
:
this
.
options
.
baseUrl
,
// baseURL
timeout
:
10000
,
timeout
:
10000
,
responseType
:
'
json
'
,
responseType
:
'
json
'
,
'
x-requested-with
'
:
'
XMLHttpRequest
'
,
withCredentials
:
false
,
// default
withCredentials
:
false
,
// default
headers
:
{
headers
:
{
'
Access-Control-Allow-Origin
'
:
'
*
'
,
'
Access-Control-Allow-Origin
'
:
'
*
'
,
'
Content-T
ype
'
:
'
application/json
'
,
'
content-t
ype
'
:
'
application/json
'
,
Accept
:
'
application/json
'
,
Accept
:
'
application/json
'
,
'
x-requested-with
'
:
'
XMLHttpRequest
'
,
...
this
.
options
.
headers
,
...
this
.
options
.
headers
,
},
},
};
};
...
@@ -65,23 +65,24 @@ class HttpRequest {
...
@@ -65,23 +65,24 @@ class HttpRequest {
const
{
data
,
status
}
=
res
;
const
{
data
,
status
}
=
res
;
return
{
data
,
status
,
statusText
:
codeMessage
[
status
]
};
return
{
data
,
status
,
statusText
:
codeMessage
[
status
]
};
},
},
error
=>
{
error
=>
// error
// console.log('error', error);
this
.
destroy
(
url
);
// // error
const
errorResult
=
JSON
.
parse
(
JSON
.
stringify
(
error
));
// this.destroy(url);
const
errorInfo
=
error
.
response
;
// const errorResult = JSON.parse(JSON.stringify(error));
if
(
!
errorInfo
)
{
// console.log('errorResult', errorResult);
const
{
// const errorInfo = error.response;
request
:
{
status
},
// if (!errorInfo) {
}
=
errorResult
;
// const {
errorResult
.
statusText
=
codeMessage
[
status
];
// request: { status },
if
(
options
.
errorHandler
instanceof
Function
)
{
// } = errorResult;
options
.
errorHandler
({
queues
:
this
.
queues
,
error
,
options
});
// errorResult.statusText = codeMessage[status];
}
// if (options.errorHandler instanceof Function) {
}
// options.errorHandler({ queues: this.queues, error, options });
// }
// }
return
Promise
.
reject
(
errorResult
);
Promise
.
reject
(
error
),
},
);
);
}
}
...
...
src/utils/request.js
View file @
3c1cb6ed
...
@@ -2,7 +2,15 @@ import { notification } from 'antd';
...
@@ -2,7 +2,15 @@ import { notification } from 'antd';
import
HttpRequest
from
'
./kim-request
'
;
import
HttpRequest
from
'
./kim-request
'
;
import
config
from
'
@/config
'
;
import
config
from
'
@/config
'
;
const
{
baseUrl
,
apiPrefix
,
headers
}
=
config
;
const
{
baseUrl
,
apiPrefix
,
headers
,
resCodeKey
,
resMessageKey
,
successCode
,
isThrowError
=
true
,
}
=
config
;
/**
/**
* 异常处理程序
* 异常处理程序
...
@@ -46,7 +54,20 @@ const axios = new HttpRequest({
...
@@ -46,7 +54,20 @@ const axios = new HttpRequest({
* @param {返回请求数据} response
* @param {返回请求数据} response
* @param {配置项} more
* @param {配置项} more
*/
*/
const
checkCode
=
(
response
,
more
)
=>
{};
const
checkCode
=
(
response
,
more
)
=>
{
const
{
data
}
=
response
;
//
if
(
`
${
data
[
resCodeKey
]}
`
!==
`
${
successCode
}
`
)
{
if
(
isThrowError
)
{
const
errorMessage
=
data
[
resMessageKey
]
||
'
后端接口返回异常
'
;
const
error
=
new
Error
(
data
[
resCodeKey
]);
error
.
code
=
response
[
resCodeKey
];
error
.
message
=
errorMessage
;
throw
error
;
}
}
return
data
;
};
export
default
function
request
(
url
,
options
=
{},
more
=
{})
{
export
default
function
request
(
url
,
options
=
{},
more
=
{})
{
let
newOptions
=
options
;
let
newOptions
=
options
;
...
...
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