panel-tab-page.ts 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
import { PanelDetailModel } from './panel-detail';
import { PanelTabPanelModel } from './panel-tab-panel';

/**
 * 分页面板模型
 *
 * @export
 * @class PanelTabPageModel
 * @extends {PanelDetailModel}
 */
export class PanelTabPageModel extends PanelDetailModel {

13 14 15 16 17 18 19
    /**
     * 子项
     *
     * @type {string[]}
     * @memberof PanelTabPageModel
     */
    public details: string[] = [];
20 21 22 23 24 25 26 27 28 29

    /**
     * Creates an instance of PanelTabPageModel.
     * PanelTabPageModel 实例
     * 
     * @param {*} [opts={}]
     * @memberof PanelTabPageModel
     */
    constructor(opts: any = {}) {
        super(opts);
30
        this.details = opts.details;
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
    }

    /**
     * 设置分页是否启用
     *
     * @param {boolean} state
     * @memberof PanelTabPageModel
     */
    public setVisible(state: boolean): void {
        this.visible = state;
        const tabPanel = this.getTabPanelModel();
        if (tabPanel) {
            tabPanel.setActiviePage();
        }
    }

    /**
     * 获取分页面板
     *
     * @returns {(PanelTabPanelModel | null)}
     * @memberof PanelTabPageModel
     */
    public getTabPanelModel(): PanelTabPanelModel | null {
        if (!this.panel) {
            return null;
        }
        const tabPanels: any[] = Object.values(this.panel.detailsModel).filter((model: any) => Object.is(model.itemType, 'TABPANEL'));
        let index = tabPanels.findIndex((tabPanel: any) => {
            return tabPanel.tabPages.some((tabPag: any) => Object.is(tabPag.name, this.name));
        });
        if (index === -1) {
            return null;
        }
        const tabPanel: PanelTabPanelModel = tabPanels[index];
        return tabPanel;
    }
}