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 --- .../check-process-model.component.ts | 85 ++++++++++------------ 1 file changed, 38 insertions(+), 47 deletions(-) (limited to 'usecaseui-portal/src/app/views/services/slicing-management/slicing-task-management/check-process-model/check-process-model.component.ts') diff --git a/usecaseui-portal/src/app/views/services/slicing-management/slicing-task-management/check-process-model/check-process-model.component.ts b/usecaseui-portal/src/app/views/services/slicing-management/slicing-task-management/check-process-model/check-process-model.component.ts index 95106050..843cf512 100644 --- a/usecaseui-portal/src/app/views/services/slicing-management/slicing-task-management/check-process-model/check-process-model.component.ts +++ b/usecaseui-portal/src/app/views/services/slicing-management/slicing-task-management/check-process-model/check-process-model.component.ts @@ -41,40 +41,35 @@ export class CheckProcessModelComponent implements OnInit { } getInfo(): void { - this.http.getSlicingBasicInfo(this.taskId).subscribe(res => { - const { result_body, result_header: { result_code } } = res; - if (+result_code === 200) { - const { - task_id, - task_name, - create_time, - processing_status, - business_demand_info, - nst_info, - business_demand_info: { service_snssai, coverage_area_ta_list } - } = result_body; - // 处理配置审核详情数据 - this.checkDetail = [{ task_id, task_name, create_time, processing_status, service_snssai }]; - // 业务需求信息数据 - business_demand_info.area = coverage_area_ta_list.map(item => { - item = item.split(';').join(' - ') - return item - }) - // 前端模拟数据 - let area = ["Beijing;Beijing;Haidian District", "Beijing;Beijing;Xicheng District", "Beijing;Beijing;Changping District"].map(item => { - item = item.split(';').join(' - ') - return item - }) - this.businessRequirement = [{ ...business_demand_info, area }]; - // 匹配NST信息 - this.NSTinfo = [nst_info]; - } else { - const errorMessage = this.moduleOperation === 'Creating' ? 'Failed to get data' : 'Viewing results failed'; - this.message.error(errorMessage); - } + let getSlicingBasicInfoFailedCallback = () => { this.isLoadingShow(); - }, ({ status, statusText }) => { - this.message.error(status + ' (' + statusText + ')'); + } + this.http.getSlicingBasicInfo(this.taskId, getSlicingBasicInfoFailedCallback).then(res => { + const { result_body } = res; + const { + task_id, + task_name, + create_time, + processing_status, + business_demand_info, + nst_info, + business_demand_info: { service_snssai, coverage_area_ta_list } + } = result_body; + // 处理配置审核详情数据 + this.checkDetail = [{ task_id, task_name, create_time, processing_status, service_snssai }]; + // 业务需求信息数据 + business_demand_info.area = coverage_area_ta_list.map(item => { + item = item.split(';').join(' - ') + return item + }) + // 前端模拟数据 + let area = ["Beijing;Beijing;Haidian District", "Beijing;Beijing;Xicheng District", "Beijing;Beijing;Changping District"].map(item => { + item = item.split(';').join(' - ') + return item + }) + this.businessRequirement = [{ ...business_demand_info, area }]; + // 匹配NST信息 + this.NSTinfo = [nst_info]; this.isLoadingShow(); }) } @@ -88,15 +83,17 @@ export class CheckProcessModelComponent implements OnInit { } getProgress(): void { - this.http.getSlicingCreateProgress(this.taskId).subscribe(res => { - const { result_body, result_header: { result_code } } = res; - if (+result_code === 200) { - this.data = []; + let getSlicingCreateProgressFailedCallback = () => { + this.isLoadingShow(); + } + this.http.getSlicingCreateProgress(this.taskId, getSlicingCreateProgressFailedCallback).then(res => { + const { result_body } = res; + this.data = []; const nssiList: string[] = ['an', 'tn', 'cn']; - nssiList.forEach( item => { - const progress: number = +result_body[item +'_progress']; + nssiList.forEach(item => { + const progress: number = +result_body[item + '_progress']; const title: string = item.charAt(0).toUpperCase() + item.slice(1); - let status: string = result_body[item +'_status']; + let status: string = result_body[item + '_status']; if ((progress || progress === 0) && status) { let currentProgress = 1 if (progress === 100 && status === 'finished') { @@ -110,7 +107,7 @@ export class CheckProcessModelComponent implements OnInit { this.data = [this.data]; let flag: boolean = false; nssiList.forEach(item => { - if (result_body[item +'_status'] === 'processing' && result_body[item +'_progress'] !== 0) { + if (result_body[item + '_status'] === 'processing' && result_body[item + '_progress'] !== 0) { flag = true; } }) @@ -119,12 +116,6 @@ export class CheckProcessModelComponent implements OnInit { this.getProgress() }, 5000) } - } else { - this.message.error('Failed to get progress') - } - this.isLoadingShow(); - }, ({ status, statusText }) => { - this.message.error(status + ' (' + statusText + ')'); this.isLoadingShow(); }) } -- cgit 1.2.3-korg