import { IAbsoluteLayoutContext } from '@ibizstudio/absolute-layout-design'; import { acc, EntityBaseService, IBzEvent } from '@ibizstudio/api'; import { clone } from 'lodash'; export class PanelItemAbsoluteLayoutController { /** * 上下文 * * @type {IAbsoluteLayoutContext} * @memberof PanelItemAbsoluteLayoutController */ ctx: IAbsoluteLayoutContext; /** * 注册事件 * * @type {Subject} * @memberof PanelAbsoluteLayoutController */ readonly evt: IBzEvent<{ added: any }> = new IBzEvent(); /** * 服务对象 * * @type {EntityBaseService} * @memberof PanelItemAbsoluteLayoutController */ s!: EntityBaseService; /** * 实体名称 * * @type {string} * @memberof PanelItemAbsoluteLayoutController */ entityName: string = 'PSSysViewPanelItem'; /** * @description acc订阅标识 * @type {string[]} * @memberof PanelItemAbsoluteLayoutController */ accSubs: string[] = []; /** * 获取服务对象 * * @return {*} {Promise} * @memberof PanelItemAbsoluteLayoutController */ getService(): Promise { const getServiceName = `get${this.entityName}Service`; return (___ibz___.gs as any)[getServiceName](); } /** * 查询所有项 * * @return {*} * @memberof PanelItemAbsoluteLayoutController */ async selectPanelItems() { const { context } = this.ctx; this.s = await this.getService(); const res = await this.s.FetchDefault(context); if (res.ok) { return res.data; } } /** * 订阅数据变更 * * @memberof PanelItemAbsoluteLayoutController */ subscription() { this.accSubs.push( acc.commandLocal( (entity: any) => { const cell = this.ctx.ctrl.graph.getCell(entity.srfkey); cell.setProp('width', entity.width); cell.setProp('height', entity.height); const component = clone((cell as any).component); const data = (cell as any).component.data(); data.item = entity; component.data = () => { return data; }; cell.setProp('component', { ...component, }); cell.hasChanged(); }, 'update', this.entityName.toUpperCase(), ) ); } /** * The new item * * @param {*} item * @memberof PanelItemAbsoluteLayoutController */ async addPanelItem(item: any) { const { context } = this.ctx; const res = await this.s.CreateTemp(context, item); if (res.ok) { this.ctx.ctrl.select.set(res.data); return res.data; } } /** * @description 组件销毁 * @memberof PanelItemAbsoluteLayoutController */ destroy() { this.accSubs.forEach(item => { acc.unsubscribeLocal(item); }); } /** * Creates an instance of PanelItemAbsoluteLayoutController. * @param {IAbsoluteLayoutContext} ctx * @memberof PanelItemAbsoluteLayoutController */ constructor(ctx: IAbsoluteLayoutContext) { this.ctx = ctx; } }