app-mob-menu-model.ts 6.3 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
import { IPSAppFunc, IPSApplication, IPSAppMenu, IPSAppMenuItem } from "@ibiz/dynamic-model-api";
import { GetModelService } from "ibiz-core";

/**
 * AppMobMenuModel 部件模型
 * 
 * @export
 * @class AppMobMenuModel
 */
export class AppMobMenuModel {

    /**
    * 菜单实例对象
    *
    * @memberof AppMobMenuModel
    */
    private MenuInstance !: IPSAppMenu;

    /**
    * 应用上下文
    *
    * @memberof AppMobMenuModel
    */
    private context: any = {};

    /**
    * 应用菜单数据
    *
    * @memberof AppMobMenuModel
    */
    private appMenus: Array<any> = [];

    /**
    * 应用功能数据
    *
    * @memberof AppMobMenuModel
    */
    private appFuncs: Array<any> = [];

    /**
     * 是否有预制功能
     *
     * @private
     * @type {boolean}
     * @memberof AppMobMenuModel
     */
    private isHasPrecutFunc:boolean = false;


    /**
     * 预制应用功能
     *
     * @private
     * @type {Array<any>}
     * @memberof AppMobMenuModel
     */
    private precutFuncs: Array<any> = [];

    /**
     * 预制应用功能菜单
     *
     * @private
     * @type {*}
     * @memberof AppMobMenuModel
     */
    private precutMenu :any;

    /**
    * Creates an instance of AppMobMenuModel.
    * 
    * @param {*} [opts]
    * 
    * @memberof AppMobMenuModel
    */
    constructor(context: any, opts: IPSAppMenu) {
        this.context = context;
        this.MenuInstance = opts;
    }

    /**
     * 模型加载
     *
     * @memberof AppMobMenuModel
     */
    async loaded(){
        await this.initAppMenuItems();
        await this.initAppFuncs();
    }

    /**
     * 初始化应用菜单
     *
     * @memberof AppMobMenuModel
     */
    public async initAppMenuItems() {
        let appMenuItems: Array<IPSAppMenuItem> | null = this.MenuInstance.getPSAppMenuItems();
        if (appMenuItems && (appMenuItems.length > 0)) {
            let application: IPSApplication = (await GetModelService(this.context)).getPSApplication();
            for (const menuItem of appMenuItems) {
                await this.initAppMenuItem(menuItem, application);
            }
        }
    }

    /**
     * 初始化应用菜单项
     *
     * @memberof AppMobMenuModel
     */
    public async initAppMenuItem(menuItem: IPSAppMenuItem, application: IPSApplication, sonMenuItemArray?: Array<any>) {
        let appMenuItem: any = {};
        Object.assign(appMenuItem, { authtag: `${application.codeName}-${this.MenuInstance.codeName}-${menuItem.M.name}` });
        Object.assign(appMenuItem, { name: menuItem.M.name });
        Object.assign(appMenuItem, { caption: menuItem.caption });
        if((menuItem  as any)?.getCapPSLanguageRes?.()?.lanResTag){
            Object.assign(appMenuItem, { captionTag: (menuItem  as any).getCapPSLanguageRes()?.lanResTag });
        }
        Object.assign(appMenuItem, { itemType: menuItem.itemType });
        Object.assign(appMenuItem, { counterid: menuItem.counterId });
        Object.assign(appMenuItem, { tooltip: menuItem.tooltip });
        if(menuItem?.getTooltipPSLanguageRes?.()?.lanResTag){
            Object.assign(appMenuItem, { tooltipTag: menuItem.getTooltipPSLanguageRes()?.lanResTag });
        }
        Object.assign(appMenuItem, { expanded: menuItem.expanded });
        Object.assign(appMenuItem, { seperator: menuItem.seperator });
        Object.assign(appMenuItem, { hidden: menuItem.hidden });
        Object.assign(appMenuItem, { hidesidebar: menuItem.hideSideBar });
        Object.assign(appMenuItem, { openDefault: menuItem.openDefault });
        Object.assign(appMenuItem, { getPSSysImage: menuItem.getPSSysImage() });
        Object.assign(appMenuItem, { getPSSysCss: menuItem.getPSSysCss() });
        Object.assign(appMenuItem, { getPSAppFunc: menuItem.getPSAppFunc() });
        Object.assign(appMenuItem, { resourcetag: menuItem.accessKey });
        Object.assign(appMenuItem, { getPSNavigateContexts: menuItem.getPSNavigateContexts() });
        if (menuItem?.getPSAppMenuItems?.()) {
            let childMenus: Array<any> = [];
            Object.assign(appMenuItem, { getPSAppMenuItems: childMenus });
            for (const childMenuItem of menuItem.getPSAppMenuItems() as IPSAppMenuItem[]) {
                await this.initAppMenuItem(childMenuItem, application, childMenus);
            }
        }
        this.appMenus.push(appMenuItem);
    }

    /**
     * 初始化应用功能数据
     *
     * @memberof AppMobMenuModel
     */
    public async initAppFuncs() {
        let application: IPSApplication = (await GetModelService(this.context)).getPSApplication();
        if (application && application.getAllPSAppFuncs()) {
            for (const appFunc of application.getAllPSAppFuncs() as IPSAppFunc[]) {
                //  基础应用功能
                    let tempAppFunc: any = {};
                    Object.assign(tempAppFunc, { name: appFunc.name });
                    Object.assign(tempAppFunc, { appfunctag: appFunc.codeName });
                    Object.assign(tempAppFunc, { appFuncType: appFunc.appFuncType });
                    Object.assign(tempAppFunc, { htmlPageUrl: appFunc.htmlPageUrl });
                    Object.assign(tempAppFunc, { openMode: appFunc.openMode });
                    Object.assign(tempAppFunc, { getPSAppView: appFunc.getPSAppView() });
                    Object.assign(tempAppFunc, { getPSNavigateContexts: appFunc.getPSNavigateContexts() });
                    Object.assign(tempAppFunc, { getPSNavigateParams: appFunc.getPSNavigateParams() });
                    this.appFuncs.push(tempAppFunc);
            }
        }
    }

    /**
     * 获取所有应用功能
     *
     * @memberof AppMobMenuModel
     */
    public getAllFuncs() {
        return this.appFuncs;
    }

    /**
     * 获取所有菜单项
     *
     * @memberof AppMobMenuModel
     */
    public getAllMenuItems() {
        return this.appMenus;
    }

    /**
     * 预制模型
     *
     * @memberof AppMobMenuModel
     */
    public getAllPrecutFuncs(){
        return this.precutFuncs;
    }

    /**
     * 是否启用预制功能
     *
     * @readonly
     * @memberof AppMobMenuModel
     */
    get isEnablePrecutFuncs(){
        return this.isHasPrecutFunc;
    }


    /**
     * 预制功能对应菜单
     *
     * @return {*} 
     * @memberof AppMobMenuModel
     */
    public getPrecutMenu(){
        return this.precutMenu;
    }
}