diff options
author | cyuamber <xuranyjy@chinamobile.com> | 2019-08-30 10:32:04 +0800 |
---|---|---|
committer | cyuamber <xuranyjy@chinamobile.com> | 2019-08-30 10:32:20 +0800 |
commit | 44b2c522ad321e5a6b7c2d7737e7e9c60a343130 (patch) | |
tree | 7b171292f03feb91b441a8d8ba4c38efadcc6188 /usecaseui-portal/src/app/shared/utils | |
parent | 0fe93162839f6848710dccfc49667973a3c3763e (diff) |
feat: optimization request function
Change-Id: I9382aaabbc6d96ff405ef1bf3e1f96bacfbc1e0b
Issue-ID: USECASEUI-307
Signed-off-by: cyuamber <xuranyjy@chinamobile.com>
Diffstat (limited to 'usecaseui-portal/src/app/shared/utils')
-rw-r--r-- | usecaseui-portal/src/app/shared/utils/http.ts | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/usecaseui-portal/src/app/shared/utils/http.ts b/usecaseui-portal/src/app/shared/utils/http.ts index f68ea5e5..c0fc3f29 100644 --- a/usecaseui-portal/src/app/shared/utils/http.ts +++ b/usecaseui-portal/src/app/shared/utils/http.ts @@ -6,7 +6,6 @@ export default function http (url:string,data:object = {},method:any = 'get',que method = method.trim().toLocaleLowerCase()
let promise:any;
if(method === 'get' || method === 'delete'){
- // 若无参数则不传递data
let options:object;
if(JSON.stringify(data) === '{}'){
options = { method, url };
@@ -14,7 +13,6 @@ export default function http (url:string,data:object = {},method:any = 'get',que options = { method, url, params: data};
}
- // 若请求方式为delete请求,则携带请求头
if(method === 'delete'){
}
@@ -23,13 +21,13 @@ export default function http (url:string,data:object = {},method:any = 'get',que }else if (method === 'post' || method === 'put') {
if(method === 'post' && query){
- let params:string;
+ let params:string = '';
if(<string>query){
query = JSON.parse((<string>query));
}
- for(let key in <object>query){
- params = '&' + key + '=' + query[key];
- }
+ Object.keys(query).forEach(item => {
+ params += '&' + item + '=' + query[item];
+ })
params = params.slice(1);
url += '?' + params;
}
@@ -41,7 +39,6 @@ export default function http (url:string,data:object = {},method:any = 'get',que }
promise
.then((response) => {
- // 请求成功返回携带成功状态及响应数据的promise对象
if(response.status === 200 || 304){
resolve(response.data)
}else{
@@ -49,12 +46,7 @@ export default function http (url:string,data:object = {},method:any = 'get',que }
})
.catch((error) => {
- if(error.status === 404){
- reject('请求资源不存在')
- }else{
- reject(error.message)
- }
-
+ reject(error.message)
})
})
|