import { IParam, IPickupViewAbility, IPickupViewController, IPickupViewControllerParams, IPickupViewPanelAbility, IPickupViewStore, ITreeExpBarAbility, } from '@/core/interface'; import { DEViewController } from './de-view-controller'; /** * 选择视图控制器 * * @export * @class PickupViewController * @extends {(DEViewController)} * @template T */ export class PickupViewController< T, S extends IPickupViewStore, A extends IPickupViewAbility > extends DEViewController implements IPickupViewController { /** * 处理视图初始化 * * @protected * @param {IPickupViewControllerParams} params * @memberof ExpViewController */ protected processViewInit(params: IPickupViewControllerParams) { super.processViewInit(params); Object.assign(this.store, { selections: [] }); } /** * 获取选择视图面板能力 * * @protected * @return {*} {(IPickupViewPanelAbility | ITreeExpBarAbility | undefined)} * @memberof PickupViewController */ protected getMainCtrlAbility(): IPickupViewPanelAbility | ITreeExpBarAbility| undefined { const pickupViewPanel = this.model.ctrls.find( (ctrl: IParam) => ctrl.controlType === 'PICKUPVIEWPANEL' ); return pickupViewPanel ? this.getSubAbility(pickupViewPanel.name) : undefined; } /** * 处理部件行为 * * @param {string} name * @param {string} action * @param {IParam[]} data * @memberof PickupViewController */ public handleCtrlAction(name: string, action: string, data: IParam[]): void { super.handleCtrlAction(name, action, data); const pickupViewPanel = this.getMainCtrlAbility(); if (pickupViewPanel && pickupViewPanel.name === name) { this.handlePickupViewPanelAction(action, data); } } /** * 处理选择视图面板事件 * * @param {string} action * @param {IParam[]} data * @memberof PickupViewController */ public handlePickupViewPanelAction(action: string, data: IParam[]) { switch (action) { case 'selectionChange': this.handleValueChange(data); break; case 'dataActive': this.handleDataActive(data); break; } } /** * 处理值变更 * * @protected * @param {IParam[]} data * @memberof PickupViewController */ protected handleValueChange(data: IParam[]) { this.store.selections = data; } /** * 处理数据激活 * * @protected * @param {IParam[]} data * @memberof PickupViewController */ protected handleDataActive(data: IParam[]) { this.emit('viewDataChange', this.store.selections); this.emit('viewClose', []); } /** * 处理确认行为 * * @memberof PickupViewController */ public confirm() { this.emit('viewDataChange', this.store.selections); this.emit('viewClose', []); } /** * 处理取消行为 * * @memberof PickupViewController */ public cancel() { this.emit('viewClose', []); } }