From 19abe2af19ba49073949f8254aec897afe7bb303 Mon Sep 17 00:00:00 2001 From: cyuamber Date: Sun, 1 Sep 2019 22:05:42 +0800 Subject: docs: add copyright info and changelog Change-Id: Ie2c7aa97aaf99c7a274f5ca45366f549223ba028 Issue-ID: USECASEUI-307 Signed-off-by: cyuamber --- usecaseui-portal/src/app/shared/utils/http.ts | 49 +++++++++++++++++--------- usecaseui-portal/src/app/shared/utils/utils.ts | 18 +++++++++- 2 files changed, 49 insertions(+), 18 deletions(-) (limited to 'usecaseui-portal/src/app/shared') diff --git a/usecaseui-portal/src/app/shared/utils/http.ts b/usecaseui-portal/src/app/shared/utils/http.ts index c0fc3f29..0d63418b 100644 --- a/usecaseui-portal/src/app/shared/utils/http.ts +++ b/usecaseui-portal/src/app/shared/utils/http.ts @@ -1,32 +1,47 @@ -import axios from 'axios'; +/* + Copyright (C) 2019 CMCC, Inc. and others. All rights reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +import axios from 'axios'; -export default function http (url:string,data:object = {},method:any = 'get',query?:string | object):any { - return new Promise((resolve,reject) => { +export default function http(url: string, data: object = {}, method: any = 'get', query?: string | object): any { + return new Promise((resolve, reject) => { method = method.trim().toLocaleLowerCase() - let promise:any; - if(method === 'get' || method === 'delete'){ - let options:object; - if(JSON.stringify(data) === '{}'){ + let promise: any; + if (method === 'get' || method === 'delete') { + let options: object; + if (JSON.stringify(data) === '{}') { options = { method, url }; - }else{ - options = { method, url, params: data}; + } else { + options = { method, url, params: data }; } - if(method === 'delete'){ + if (method === 'delete') { } promise = axios(options); - }else if (method === 'post' || method === 'put') { - if(method === 'post' && query){ - let params:string = ''; - if(query){ + } else if (method === 'post' || method === 'put') { + if (method === 'post' && query) { + let params: string = ''; + if (query) { query = JSON.parse((query)); } Object.keys(query).forEach(item => { - params += '&' + item + '=' + query[item]; + params += '&' + item + '=' + query[item]; }) params = params.slice(1); url += '?' + params; @@ -39,9 +54,9 @@ export default function http (url:string,data:object = {},method:any = 'get',que } promise .then((response) => { - if(response.status === 200 || 304){ + if (response.status === 200 || 304) { resolve(response.data) - }else{ + } else { reject(response) } }) diff --git a/usecaseui-portal/src/app/shared/utils/utils.ts b/usecaseui-portal/src/app/shared/utils/utils.ts index abdb9836..1aa9673e 100644 --- a/usecaseui-portal/src/app/shared/utils/utils.ts +++ b/usecaseui-portal/src/app/shared/utils/utils.ts @@ -1,4 +1,20 @@ -export class Util{ +/* + Copyright (C) 2019 CMCC, Inc. and others. All rights reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +export class Util { // Time formatting milliseconds to normal dateformater(vmstime) { if (!vmstime) { -- cgit 1.2.3-korg