import Vue from 'vue'; import { EntityBaseService, IEntity, IParams } from '@ibizstudio/api'; import { IDesignContext } from '../interface'; import { DataHistory } from '../utils/data-history'; import { SelectState } from '../utils/select-state'; import { IPSAppDEEditView, getControl, IPSAppDataEntity, IPSControl } from '@ibizstudio-ex/runtime'; /** * 设计界面控制器 * * @export * @class DesignController */ export abstract class DesignController { /** * 上下文内容 * * @type {IDesignContext} * @memberof DesignController */ ctx!: IDesignContext; /** * 选中状态操作对象 * * @memberof DesignController */ readonly select = new SelectState(); /** * 历史记录操作对象 * * @memberof DesignController */ readonly history = new DataHistory(); /** * 模型初始化完毕 * * @author chitanda * @date 2021-04-14 15:04:48 */ modelInit = false; /** * 素材区快速搜索值 * */ materialSearch = ''; /** * 视图副标题(部件名称) * */ subTitle: string = ''; /** * 视图模型对象 * * @type {IPSAppDEEditView} */ viewModel!: IPSAppDEEditView; /** * 子模型对象 * * @type {IPSControl} * @memberof DesignController */ itemModel!: IPSControl; /** * 实体 * * @author chitanda * @date 2021-04-14 16:04:13 * @type {IPSAppDataEntity} */ entity!: IPSAppDataEntity; /** * 主数据对象 * * @type {IEntity} * @memberof IPSAppDataEntity */ data!: IEntity; /** * 项实体 * * @author chitanda * @date 2021-04-14 16:04:43 * @type {IPSAppDataEntity} */ itemEntity!: IPSAppDataEntity; /** * 实体服务 * * @author chitanda * @date 2021-04-14 16:04:49 * @type {EntityBaseService} */ service!: EntityBaseService; /** * 项实体服务 * * @author chitanda * @date 2021-04-14 16:04:34 * @type {EntityBaseService} */ itemService!: EntityBaseService; /** * 项预览实体服务 * * @type {EntityBaseService} * @memberof DesignController */ previewService!: EntityBaseService; /** * Creates an instance of DesignController. * @param {IDesignContext} ctx * @memberof DesignController */ constructor(ctx: IDesignContext) { this.ctx = ctx; } /** * 设置视图模型 * * @param {IPSAppDEEditView} viewModel * @memberof FormDesignController */ setViewModel(viewModel: IPSAppDEEditView) { this.viewModel = viewModel; this.initModel(this.viewModel); } /** * 根据视图模型初始化参数 * * @author chitanda * @date 2021-04-14 15:04:51 * @param {IPSAppDEEditView} view * @return {*} {Promise} */ async initModel(view: IPSAppDEEditView): Promise { // 主相关 await view.fill(true); const entity = await view.getPSAppDataEntity()!.fill(true); this.entity = entity as any; this.service = await this.ctx.gs.getService(this.entity.codeName) as EntityBaseService; await this.initChildModel(view); // 模型初始化完毕 this.modelInit = true; this.ctx.evt.emit('initComplete'); } /** * 根据视图模型初始化关联子实体参数 * * @protected * @param {IPSAppDEEditView} view * @memberof DesignController */ protected async initChildModel(view: IPSAppDEEditView): Promise { // 项相关 const itemCtrl = getControl(view, 'item'); if (itemCtrl) { this.itemModel = itemCtrl; const itemEntity = await itemCtrl.getPSAppDataEntity()!.fill(true); this.itemEntity = itemEntity as any; this.itemService = await this.ctx.gs.getService(this.itemEntity.codeName) as EntityBaseService; } } /** * 数据加载 * * @param {IParams} [_params = {}] * @return {*} {Promise} * @memberof DesignController */ async load(_params: IParams = {}): Promise { throw new Error('load未实现'); } /** * 重新加载数据 * * @author chitanda * @date 2021-06-03 15:06:40 * @return {*} {Promise} */ async reload(_params: IParams = {}): Promise { const loading = Vue.prototype.$loading({ lock: true, text: '重新加载中...', background: '#ffffffe6', }); try { const res = await this.load(_params); this.ctx.loaded = false; setTimeout(() => { this.ctx.loaded = true; }, 10); loading.close(); return res; } catch (err: any) { loading.close(); throw new Error(err); } } /** * 设置展示的主文本信息 * * @author chitanda * @date 2021-06-06 15:06:12 * @param {*} data */ setMainInfo(data: any): void { if (this.viewModel) { this.ctx.mainInfo = `${this.viewModel.caption}:${data.srfmajortext}`; const win: any = window; if (win.ibzModal) { win.ibzModal.caption = `${data.srfmajortext}<${this.viewModel.caption}>`; } } } }