import { message } from 'ant-design-vue'; import { IParams, IPSSysViewPanel, PSSysViewPanel, IBzEvent, PSSysViewPanelService } from '@ibizstudio/api'; import { DesignDefaultController } from '@ibizstudio/dynamic-design'; import { mergeRight } from 'ramda'; import { CreateElement } from 'vue'; import { getControl } from '@ibiz/dynamic-model-api'; import { IPanelDesignContext } from '../interface'; /** * 设计控制器 * * @export * @class PanelDesignController * @extends {DesignController} */ export class PanelDesignController extends DesignDefaultController { /** * 上下文对象 * * @type {IPanelDesignContext} * @memberof PanelDesignController */ ctx!: IPanelDesignContext; /** * 主数据 * * @type {*} * @memberof PanelDesignController */ masterData: any = null; /** * 布局状态事件 * * @type {IbzEvent<{layout: number}>} * @memberof PanelDesignController */ readonly evt: IBzEvent<{ layoutState: number }> = new IBzEvent(); renderChildItem(h: CreateElement, ctx: any, item: any, pData: any) { const key = item.srfkey || 'tempkey'; switch (item.itemtype) { case 'FIELD': return ; case 'CONTAINER': return ; case 'TABPANEL': return ( ); default: return ; } } /** * 加载行为 * * @type {string} * @memberof PanelDesignController */ loadAction: string = 'Get'; /** * 修改行为 * * @type {string} * @memberof PanelDesignController */ updateAction: string = 'Update'; /** * 初始化核心服务 * * @param {IPSDEEditForm} controlModel 部件模型对象 * @memberof PanelDesignController */ async initAction() { const controlModel: any = getControl(this.viewModel, 'form'); const getAction = await controlModel.getGetPSControlAction().fill(); const updateAction = await controlModel.getUpdatePSControlAction().fill(); if (getAction) { this.loadAction = getAction.actionName; } if (updateAction) { this.updateAction = updateAction.actionName; } } /** * 加载面板数据 * * @param {IParams} [params={}] * @return {*} {(Promise)} * @memberof PanelDesignController */ async load(params: IParams = {}): Promise { const { ctrl, context, evt } = this.ctx; const s:any = PSSysViewPanelService.getInstance(); const res = await s[this.loadAction](mergeRight(context, params)); if (res.ok) { const data = new PSSysViewPanel(res.data); this.evt.emit('layoutState', data.viewlayoutflag); context.psdataentity = data.psdeid; context.pssysviewpanel = data.pssysviewpanelid; ctrl.select.set(data); this.setMainInfo(data); evt.emit('loaded'); if (data) { ctrl.masterData = data; const entityService = await ___ibz___.gs.getPSDataEntityService(); const res = await entityService.Get({ ...this.ctx.context, psdataentity: ctrl.masterData.psdeid }); if (res.ok) { this.ctx.context.psdataentity = res.data.psdataentityid; await entityService.selectLocal(this.ctx.context, res.data); } } } else { message.error('面板内容加载失败: ' + res.statusText); } return null; } /** * 保存 * * @return {*} {Promise} * @memberof PanelDesignController */ save(): Promise { return (this.service as any)[this.updateAction](this.ctx.context, null); } }