import { IHttpResponse, IParam } from '@/core/interface'; import { ControlVOBase } from '../control-vo'; import { CtrlServiceBase } from './ctrl-service-base'; /** * 向导面板服务 * * @class WizardPanelService * @extends {CtrlServiceBase} * @template T */ class WizardPanelService extends CtrlServiceBase { /** * 处理响应 * * @param {IHttpResponse} response * @param {*} [opts={}] * @return {*} * @memberof WizardPanelService */ handleResponse(response: IHttpResponse, opts: any = {}) { response.data = this.newControlVO(response.data); return response; } /** * 初始化向导 * * @param {string} action * @param {IParam} [context={}] * @param {IParam} [data={}] * @return {*} {Promise} * @memberof WizardPanelService */ async init( action: string, context: IParam = {}, data: IParam = {} ): Promise { let result: Promise | null = null; const { data: Data, context: Context } = this.handleRequestData( context, data ); try { await this.initEntityService(); if (this.appEntityService) { result = this.appEntityService[action ? action : 'Create']( Context, Data ); if (result) { const response = await result; this.handleResponse(response); } } } catch (error) {} return result; } /** * 完成向导 * * @param {string} action * @param {IParam} [context={}] * @param {IParam} [data={}] * @return {*} {Promise} * @memberof WizardPanelService */ async finish( action: string, context: IParam = {}, data: IParam = {} ): Promise { let result: Promise | null = null; const { data: Data, context: Context } = this.handleRequestData( context, data ); try { await this.initEntityService(); Object.assign(Data, { ignoreversioncheck: 1 }); if (this.appEntityService) { result = this.appEntityService[action ? action : 'Update']( Context, Data ); if (result) { const response = await result; this.handleResponse(response); } } } catch (error) {} return result; } } export default WizardPanelService;