From 43cb242d5a78e86786d4274fc539d81680fc15c4 Mon Sep 17 00:00:00 2001 From: cyuamber Date: Tue, 8 Sep 2020 09:50:48 +0800 Subject: feat: Optimize the public request method of axios Change-Id: Iab9e86c66628c9a0c39e0a9ed56607417805c9d4 Issue-ID: USECASEUI-444 Signed-off-by: cyuamber --- .../slicing-business-model.component.ts | 35 ++++---- .../slicing-business-table.component.ts | 100 ++++++++------------- 2 files changed, 53 insertions(+), 82 deletions(-) (limited to 'usecaseui-portal/src/app/views/services/slicing-management/slicing-resource-management/slicing-business-management') diff --git a/usecaseui-portal/src/app/views/services/slicing-management/slicing-resource-management/slicing-business-management/slicing-business-model/slicing-business-model.component.ts b/usecaseui-portal/src/app/views/services/slicing-management/slicing-resource-management/slicing-business-management/slicing-business-model/slicing-business-model.component.ts index b27e5a31..7bed4304 100644 --- a/usecaseui-portal/src/app/views/services/slicing-management/slicing-resource-management/slicing-business-management/slicing-business-model/slicing-business-model.component.ts +++ b/usecaseui-portal/src/app/views/services/slicing-management/slicing-resource-management/slicing-business-management/slicing-business-model/slicing-business-model.component.ts @@ -29,27 +29,22 @@ export class SlicingBusinessModelComponent implements OnInit { } getDetail() { - this.myhttp.getSlicingBusinessDetail(this.businessId).subscribe(res => { + this.myhttp.getSlicingBusinessDetail(this.businessId).then(res => { this.isSpinning = false; - const { result_body, result_header: { result_code } } = res; - if (+result_code === 200) { - const { business_demand_info, business_demand_info: { coverage_area_ta_list }, nst_info, nsi_info } = result_body; - business_demand_info.area = coverage_area_ta_list.map(item => { - item = item.split(';').join('-'); - return item - }); - // area : Front-end analog data - let area = ["Haidian District;Beijing;Beijing", "Xicheng District;Beijing;Beijing", "Changping District;Beijing;Beijing"].map(item => { - item = item.split(';').join(' - '); - return item - }); - this.businessRequirement = [{ ...business_demand_info, area }]; - this.NSTinfo = [nst_info]; - if (nsi_info.nsi_id !== null) { - this.nsiInfo = [nsi_info]; - } - }else{ - this.message.error(res.result_header.result_message) + const { business_demand_info, business_demand_info: { coverage_area_ta_list }, nst_info, nsi_info } = res.result_body; + business_demand_info.area = coverage_area_ta_list.map(item => { + item = item.split(';').join('-'); + return item + }); + // area : Front-end analog data + let area = ["Haidian District;Beijing;Beijing", "Xicheng District;Beijing;Beijing", "Changping District;Beijing;Beijing"].map(item => { + item = item.split(';').join(' - '); + return item + }); + this.businessRequirement = [{ ...business_demand_info, area }]; + this.NSTinfo = [nst_info]; + if (nsi_info.nsi_id !== null) { + this.nsiInfo = [nsi_info]; } }) } diff --git a/usecaseui-portal/src/app/views/services/slicing-management/slicing-resource-management/slicing-business-management/slicing-business-table/slicing-business-table.component.ts b/usecaseui-portal/src/app/views/services/slicing-management/slicing-resource-management/slicing-business-management/slicing-business-table/slicing-business-table.component.ts index 5410a0f4..cf9b221c 100644 --- a/usecaseui-portal/src/app/views/services/slicing-management/slicing-resource-management/slicing-business-management/slicing-business-table/slicing-business-table.component.ts +++ b/usecaseui-portal/src/app/views/services/slicing-management/slicing-resource-management/slicing-business-management/slicing-business-table/slicing-business-table.component.ts @@ -56,11 +56,13 @@ export class SlicingBusinessTableComponent implements OnInit { paramsObj["businessStatus"] = this.selectedValue.toLocaleLowerCase(); this.isSelect = true; } - this.myhttp.getSlicingBusinessList(paramsObj, this.isSelect).subscribe(res => { - const { result_header: { result_code }, result_body: { slicing_business_list, record_number } } = res; + let getSlicingBusinessListFailedCallback = () => { this.loading = false; - if (+result_code === 200) { - this.total = record_number; + } + this.myhttp.getSlicingBusinessList(paramsObj, this.isSelect, getSlicingBusinessListFailedCallback).then(res => { + const { result_body: { slicing_business_list, record_number } } = res; + this.loading = false; + this.total = record_number; if(slicing_business_list !==null && slicing_business_list.length >0){ this.listOfData = slicing_business_list.map((item, index) => { if (item.last_operation_progress && item.last_operation_type && Number(item.last_operation_progress) < 100) { @@ -80,7 +82,6 @@ export class SlicingBusinessTableComponent implements OnInit { return item }); } - } }) } getListOfProcessingStatus() { @@ -124,27 +125,18 @@ export class SlicingBusinessTableComponent implements OnInit { } changeActivate(paramsObj, isActivate, slicing, activateValue, finished, index) { this.loading = true; - this.myhttp.changeActivateSlicingService(paramsObj, isActivate).subscribe(res => { - const { result_header: { result_code, result_message }, result_body: { operation_id } } = res; - this.loading = false; - if (+result_code === 200) { - this.notification1.notificationSuccess('slicing business', finished, slicing.service_instance_id); - this.getBusinessList(); - } else { - let singleSlicing = Object.assign({}, this.listOfData[index]); - this.listOfData[index] = singleSlicing; - this.listOfData = [...this.listOfData]; - this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id); - this.getBusinessList(); - } - this.getBusinessList(); - }, () => { + let changeActivateFailedCallback = () => { this.loading = false; let singleSlicing = Object.assign({}, this.listOfData[index]); this.listOfData[index] = singleSlicing; this.listOfData = [...this.listOfData]; this.notification1.notificationFailed('slicing business', finished, slicing.service_instance_id); this.getBusinessList(); + } + this.myhttp.changeActivateSlicingService(paramsObj, isActivate, changeActivateFailedCallback).then(res => { + this.loading = false; + this.notification1.notificationSuccess('slicing business', finished, slicing.service_instance_id); + this.getBusinessList(); }) } terminate(slicing,index) { @@ -156,20 +148,15 @@ export class SlicingBusinessTableComponent implements OnInit { let paramsObj = { serviceId: slicing.service_instance_id }; this.terminateStart[index] = true; this.loading = true; - this.myhttp.terminateSlicingService(paramsObj).subscribe(res => { - const { result_header: { result_code, result_message }, result_body: { operation_id } } = res; - this.loading = false; - if (+result_code === 200) { - this.notification1.notificationSuccess('slicing business', 'terminate', slicing.service_instance_id); - this.getBusinessList(); - } else { - this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id); - this.terminateStart[index] = false; - } - }, () => { + let terminateFailedCallback = () => { this.loading = false; this.notification1.notificationFailed('slicing business', 'terminate', slicing.service_instance_id); this.terminateStart[index] = false; + } + this.myhttp.terminateSlicingService(paramsObj, terminateFailedCallback).then(res => { + this.loading = false; + this.notification1.notificationSuccess('slicing business', 'terminate', slicing.service_instance_id); + this.getBusinessList(); }) }, nzCancelText: 'No', @@ -193,44 +180,33 @@ export class SlicingBusinessTableComponent implements OnInit { queryProgress(obj, action, index, callback) { return new Promise(res => { let requery = () => { - this.myhttp.getSlicingBusinessProgress(obj) - .subscribe((data) => { - const { result_header: { result_code, result_message }, result_body: { operation_id } } = data; - if (+result_code === 200) { - if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) { - callback(data.result_body); - let progressSetTimeOut = setTimeout(() => { - requery(); - }, 5000); - this.progressingTimer.push({ - id: obj.serviceId, - timer: progressSetTimeOut - }) - } else { - this.progressingTimer.forEach((item) => { - if (item.serviceId === obj.serviceId) { - clearInterval(item.timer); - } - }); - res(data.result_body); - } + let queryProgressFailedCallback = () => { + this.progressingTimer.forEach((item) => { + if (item.serviceId === obj.serviceId) { + clearInterval(item.timer); + } + }); + this.getBusinessList(); + } + this.myhttp.getSlicingBusinessProgress(obj, queryProgressFailedCallback) + .then((data) => { + if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) { + callback(data.result_body); + let progressSetTimeOut = setTimeout(() => { + requery(); + }, 5000); + this.progressingTimer.push({ + id: obj.serviceId, + timer: progressSetTimeOut + }) } else { this.progressingTimer.forEach((item) => { if (item.serviceId === obj.serviceId) { clearInterval(item.timer); } }); - this.getBusinessList(); - this.message.error(result_message); + res(data.result_body); } - }, (err) => { - this.progressingTimer.forEach((item) => { - if (item.serviceId === obj.serviceId) { - clearInterval(item.timer); - } - }); - this.getBusinessList(); - this.message.error(err); }) }; requery(); -- cgit 1.2.3-korg