indexview-base.tsx 4.6 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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
import { IPSAppIndexView, IPSAppMenu } from '@ibiz/dynamic-model-api';
import { IndexViewInterface, ModelTool, ViewTool } from 'ibiz-core';
import { AppFuncService } from '../app-service';
import { ViewBase } from "./view-base";

/**
 * 首页视图基类
 *
 * @export
 * @class IndexViewBase
 * @extends {ViewBase}
 * @implements {IndexViewInterface}
 */
export class IndexViewBase extends ViewBase implements IndexViewInterface {

    /**
     * 是否支持应用切换
     *
     * @type {boolean}
     * @memberof IndexViewBase
     */
    public isEnableAppSwitch: boolean = false;

    /**
     * 是否为应用起始页面
     *
     * @type {boolean}
     * @memberof IndexViewBase
     */
    public isDefaultPage: boolean = false;

    /**
     * 是否为空白视图模式
     *
     * @type {boolean}
     * @memberof IndexViewBase
     */
    public isBlankMode: boolean = false;

    /**
     * 菜单收缩变化
     *
     * @type {boolean}
     * @memberof IndexViewBase
     */
    public collapseChange: boolean = false;

    /**
     * 菜单实例
     *
     * @type {*}
     * @memberof IndexViewBase
     */
    public menuInstance!: IPSAppMenu;

    /**
     * 初始化应用首页视图实例
     * 
     * @memberof IndexViewBase
     */
    public async viewModelInit() {
        this.viewInstance = (this.staticProps?.modeldata) as IPSAppIndexView;
        await super.viewModelInit();
        this.menuInstance = (this.viewInstance.findPSControl(ModelTool.findPSControlByType("APPMENU", this.viewInstance.getPSControls()))) as IPSAppMenu;
    }

    /**
     * 视图初始化
     *
     * @memberof IndexViewBase
     */
    public viewInit() {
        super.viewInit();
        AppFuncService.getInstance().init(this);
    }

    /**
     *  视图挂载
     *
     * @memberof IndexViewBase
     */
    public containerMounted() {
        super.containerMounted();
        if (!this.viewProxyMode) {
            this.viewState.next({ tag: this.menuInstance?.name, action: 'load', data: {} });
        }
        ViewTool.setIndexParameters([{ pathName: this.viewInstance?.codeName, parameterName: this.viewInstance?.codeName }]);
        ViewTool.setIndexViewParam(this.context);
        this.appLoadingDestroyed();
    }

    /**
     * 初始化部件自定义参数(传入布局)(重写)
     *
     * @memberof IndexViewBase
     */
    public initCtrlCustomParams() {
        let counterdata: any = null;
        if (this.counterServiceArray?.length > 0) {
            counterdata = this.counterServiceArray[0].service?.counterData;
        }
        const tempStaticProps = {
            mode: this.viewInstance?.mainMenuAlign,
            isDefaultPage: (this.viewInstance as IPSAppIndexView)?.defaultPage,
            isBlankMode: (this.viewInstance as IPSAppIndexView)?.blankMode,
            defPSAppView: (this.viewInstance as IPSAppIndexView)?.getDefPSAppView(),
            counterdata: counterdata,
        }
        // 设置部件自定义参数(传入布局)
        this.setCtrlCustomParams('appmenu', { staticProps: tempStaticProps });
    }

    /**
     *  应用loading销毁
     *
     * @memberof IndexViewBase
     */
    public appLoadingDestroyed() {
        setTimeout(() => {
            const el = document.getElementById('app-loading-x');
            if (el) {
                el.style.display = 'none';
            }
        }, 300);
    }

    /**
     * 视图销毁
     *
     * @memberof IndexViewBase
     */
    public viewDestroyed() {
        super.viewDestroyed()
    }


    /**
     * 渲染视图主题内容
     * 
     * @memberof IndexViewBase
     */
    public renderMainContent() {
        let { targetCtrlName, targetCtrlParam, targetCtrlEvent }: { targetCtrlName: string, targetCtrlParam: any, targetCtrlEvent: any } = this.computeTargetCtrlData(this.menuInstance);
        Object.assign(targetCtrlParam.dynamicProps, { collapseChange: this.collapseChange });
        return this.$createElement(targetCtrlName, { props: targetCtrlParam, ref: this.menuInstance?.name, on: targetCtrlEvent });
    }

    /**
     * 计算目标部件所需参数
     *
     * @param {string} [controlType]
     * @returns
     * @memberof IndexViewBase
     */
    public computeTargetCtrlData(controlInstance: any, args?: any) {
        const { targetCtrlName, targetCtrlParam, targetCtrlEvent } = super.computeTargetCtrlData(controlInstance, args);
        Object.assign(targetCtrlParam.dynamicProps, this.ctrlCustomParams['appmenu'].dynamicProps);
        Object.assign(targetCtrlParam.staticProps, this.ctrlCustomParams['appmenu'].staticProps);
        return { targetCtrlName, targetCtrlParam, targetCtrlEvent }
    }

}