TabExpPanelControlBase.tsx 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
import { ExpControlBase } from './ExpControlBase';

/**
 * 分页导航面板部件控制器
 *
 * @export
 * @class TabExpPanelControlBase
 * @extends {ControlBase}
 */
export class TabExpPanelControlBase extends ExpControlBase {

    /**
     * 行为参数
     *
     * @protected
     * @type {*}
     * @memberof TabExpPanelControlBase
     */
    protected action: any = '';

    /**
     * 当前激活分页面板项
     *
     * @protected
     * @type {string}
     * @memberof TabExpPanelControlBase
     */
    protected activatedTabViewPanel: string = '';

    /**
     * 所有面板项是否初始化状态管理
     *
     * @protected
     * @type {*}
     * @memberof TabExpPanelControlBase
     */
    protected isInit: any = {};

    /**
     * 分页视图面板数据变更
     *
     * @protected
     * @memberof TabExpPanelControlBase
     */
    protected tabViewPanelDatasChange = (): void => {
        this.counterRefresh();
    }

    /**
     * 组件创建完毕
     *
     * @protected
     * @memberof TabExpPanelControlBase
     */
    protected ctrlCreated(): void {
        if (this.viewState) {
            this.viewStateEvent = this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(tag, this.name)) {
                    return;
                }
                this.action = action;
                this.viewState.next({ tag: this.activatedTabViewPanel, action: action, data: data });
                this.$forceUpdate();
            });
        }
    }

    /**
     * 部件挂载完毕
     *
     * @protected
     * @memberof TabExpPanelControlBase
     */
    protected ctrlMounted(): void {
        if (this.viewparams && this.viewparams.srftabactivate) {
            const activate = this.viewparams.srftabactivate.toLowerCase();
            if (activate && this.isInit[activate] !== undefined) {
                for (const key in this.isInit) {
                    if (this.isInit.hasOwnProperty(key)) {
                        this.isInit[key] = false;
                    }
                }
                this.$nextTick(() => {
                    this.tabPanelClick(activate);
                });
            }
        }
    }

    /**
     * 分页面板选中
     *
     * @protected
     * @param {*} $event
     * @returns
     * @memberof TabExpPanelControlBase
     */
    protected tabPanelClick($event: any): void {
        if (!$event) {
            return;
        }
        this.isInit[$event] = true;
        if (!this.viewState) {
            return;
        }
        this.activatedTabViewPanel = $event;
        this.viewState.next({ tag: this.activatedTabViewPanel, action: this.action, data: {} });
    }
}