index-view-base.tsx 3.4 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
import { IPSAppIndexView, IPSAppMenu } from '@ibiz/dynamic-model-api';
import { MobIndexViewInterface, ModelTool, ViewTool } from 'ibiz-core';
import { AppFuncService } from '../app-service';
import { ViewBase } from "./view-base";

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

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

    /**
     * 视图实例
     * 
     * @memberof ViewBase
     */
    public declare viewInstance: IPSAppIndexView;

    /**
     * 导航视图参数
     *
     * @memberof IndexViewBase
     */
    public embedViewProps: any = {};

    /**
     * 视图显示状态
     *
     * @memberof IndexViewBase
     */
    public init = false;

    /**
     * 引擎初始化
     *
     * @public
     * @memberof MobEditView3Base
     */
    public engineInit(): void {
        this.engine.init({
            view: this,
            menu: (this.$refs[this.menuInstance.name] as any).ctrl,
        });
        this.engine.load();
    }

    /**
     * 初始化应用首页视图实例
     * 
     * @memberof IndexViewBase
     */
    public async viewModelInit() {
        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();
        ViewTool.setIndexParameters([{ pathName: this.viewInstance.codeName, parameterName: this.viewInstance.codeName }]);
        ViewTool.setIndexViewParam(this.context);
    }

    /**
     * 计算目标部件所需参数
     *
     * @param {string} [controlType]
     * @returns
     * @memberof IndexViewBase
     */
    public computeTargetCtrlData(controlInstance: any, args?: any) {
        const { targetCtrlName, targetCtrlParam, targetCtrlEvent } = super.computeTargetCtrlData(controlInstance, args);
        const { codeName, defaultPage, name } = this.viewInstance;
        Object.assign(targetCtrlParam.staticProps, {
            viewName: codeName,
            mode: this.model,
            isDefaultPage: defaultPage,
            name: name,

        })
        return { targetCtrlName, targetCtrlParam, targetCtrlEvent }
    }

    /**
     * 绘制菜单导航内容区
     *
     * @memberof IndexViewBase
     */
    renderEmbedViewContent() {      
        return (
                this.init ? this.$createElement('app-view-shell', { props: this.embedViewProps, class:'app-view-container',slot:'embedview' }) : null
        )
    }

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