app-menu-model.ts 5.2 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
import { IPSAppFunc, IPSApplication, IPSAppMenu, IPSAppMenuItem } from "@ibiz/dynamic-model-api";
import { GetModelService } from "ibiz-core";

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

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

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

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

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

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

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

    /**
     * 初始化应用菜单项
     *
     * @memberof AppMenuModel
     */
    public 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, { disableClose: menuItem.disableClose });
        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[]) {
                this.initAppMenuItem(childMenuItem, application,childMenus);
            }
        }
        if (sonMenuItemArray) {
            sonMenuItemArray.push(appMenuItem);
        } else {
            this.appMenus.push(appMenuItem);
        }
    }

    /**
     * 初始化应用功能数据
     *
     * @memberof AppMenuModel
     */
    public async initAppFuncs() {
        let application: IPSApplication = (await GetModelService()).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 AppMenuModel
     */
    public getAllFuncs() {
        return this.appFuncs;
    }

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

}