app-style2-indexview.tsx 11.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 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 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
import { AuthService, LogUtil, Util } from 'ibiz-core';
import { Component } from 'vue-property-decorator';
import { AppFuncService, AppLayoutService, FooterItemsService } from '../../../app-service';
import { AppMenuService } from '../../../ctrl-service/app-menu-service';
import { VueLifeCycleProcessing } from '../../../decorators';
import { AppIndexViewBase } from '../app-common-view/app-indexview-base';


/**
 * 应用首页视图
 *
 * @export
 * @class AppStyle2IndexView
 * @extends {AppIndexViewBase}
 */
@Component({})
@VueLifeCycleProcessing()
export class AppStyle2IndexView extends AppIndexViewBase {

    /**
     * 建构权限服务对象
     *
     * @type {AuthService}
     * @memberof AppStyle2IndexView
     */
    public authService: AuthService = new AuthService();

    /**
     * 底部项绘制服务
     *
     * @type {FooterItemsService}
     * @memberof AppStyle2IndexView
     */
    public footerItemsService: FooterItemsService = new FooterItemsService();

    /**
     * 当前激活菜单项
     * 
     * @type {*}
     * @memberof AppStyle2IndexView
     */
    public activeItem: any;

    /**
     * 左侧导航菜单
     *
     * @type {*}
     * @memberof AppStyle2IndexView
     */
    public left_exp: any;

    /**
     * 底部导航菜单
     *
     * @type {*}
     * @memberof AppStyle2IndexView
     */
    public bottom_exp: any;

    /**
     * 标题栏菜单
     *
     * @type {*}
     * @memberof AppStyle2IndexView
     */
    public top_menus: any;

    /**
     * 用户菜单
     *
     * @type {*}
     * @memberof AppStyle2IndexView
     */
    public user_menus: any;

    /**
     * 底部绘制
     *
     * @private
     * @memberof AppStyle2IndexView
     */
    public footerRenders: { remove: () => boolean }[] = [];

    /**
     * 菜单模型数据
     * 
     * @memberof AppStyle2IndexView
     */
    public appMenuModel: any;

    /**
     * 菜单部件服务对象
     *
     * @type {*}
     * @memberof ControlBase
     */
    public service: any;

    /**
     * 初始化应用首页视图实例
     * 
     * @memberof AppStyle2IndexView
     */
    public async viewModelInit(){
        await super.viewModelInit();
        this.service = new AppMenuService(this.menuInstance, this.context);
        await this.service.initServiceParam(this.context,this.menuInstance);
        this.appMenuModel = this.service.getAllMenuItems();
        this.left_exp = this.handleMenusResource('left_exp');
        this.bottom_exp = this.handleMenusResource('bottom_exp');
        this.top_menus = this.handleMenusResource('top_menus');
        this.user_menus = this.handleMenusResource('user_menus');
        this.registerFooterItems();
    }
    /**
     * 根据名称获取菜单组
     * 
	 * @param {string} name
     * @memberof AppStyle2IndexViewLayout 
     */
    public getMenuGroup(name: string){
        return this.appMenuModel.find((item: any) => Object.is(item.name, name));
    }

    /**
     * 通过统一资源标识计算菜单
     *
     * @param {*} name 菜单标识
     * @memberof AppStyle2IndexViewLayout
     */
    public handleMenusResource(name: any) {
        const inputMenus = this.getMenuGroup(name);
        if (inputMenus && inputMenus.getPSAppMenuItems) {
            this.computedEffectiveMenus(inputMenus.getPSAppMenuItems);
            // this.computeParentMenus(inputMenus.getPSAppMenuItems);
        }
        return inputMenus;
    }

    /**
     * 计算有效菜单项
     *
     * @param {*} inputMenus
     * @memberof AppStyle2IndexViewLayout
     */
    public computedEffectiveMenus(inputMenus: Array<any>) {
        inputMenus.forEach((_item: any) => {
            if (!this.authService?.getMenusPermission(_item)) {
                _item.hidden = true;
            }
            if (_item.getPSAppMenuItems && _item.getPSAppMenuItems.length > 0) {
                this.computedEffectiveMenus(_item.getPSAppMenuItems);
            }
        });
    }

    // /**
    //  * 计算父项菜单项是否隐藏
    //  *
    //  * @param {*} inputMenus
    //  * @memberof AppStyle2IndexViewLayout
    //  */
    // public computeParentMenus(inputMenus: Array<any>) {
    //     if (inputMenus && inputMenus.length > 0) {
    //         inputMenus.forEach((item: any) => {
    //             if (item.hidden && item.getPSAppMenuItems && item.getPSAppMenuItems.length > 0) {
    //                 item.getPSAppMenuItems.map((singleItem: any) => {
    //                     if (!singleItem.hidden) {
    //                         item.hidden = false;
    //                     }
    //                     if (singleItem.getPSAppMenuItems && singleItem.getPSAppMenuItems.length > 0) {
    //                         this.computeParentMenus(singleItem.getPSAppMenuItems);
    //                     }
    //                 });
    //             }
    //         });
    //     }
    // }

    /**
     * 注册底部项
     *
     * @memberof AppStyle2IndexViewLayout
     */
    protected registerFooterItems(): void {
        const leftItems: any = this.getMenuGroup('footer_left');
        const centerItems: any = this.getMenuGroup('footer_center');
        const rightItems: any = this.getMenuGroup('footer_right');
        if (leftItems && leftItems.getPSAppMenuItems) {
            leftItems.getPSAppMenuItems.forEach((item: any) => {
                this.footerRenders.push(
                    this.footerItemsService.registerLeftItem((h: any) => {
                        return (
                            <div class='action-item' title={item.tooltip} on-click={() => this.click(item)}>
                                <menu-icon item={item} />
                                {item.caption}
                                {/* todo 菜单多语言*/}
                                {/* this.$tl(item.captiontag,item.caption) */}
                            </div>
                        );
                    }),
                );
            });
        }
        if (centerItems && centerItems.getPSAppMenuItems) {
            centerItems.getPSAppMenuItems.forEach((item: any) => {
                this.footerRenders.push(
                    this.footerItemsService.registerCenterItem((h: any) => {
                        return (
                            <div class='action-item' title={item.tooltip} on-click={() => this.click(item)}>
                                <menu-icon item={item} />
                                {item.caption}
                                {/* todo 菜单多语言*/}
                                {/* this.$tl(item.captiontag,item.caption) */}
                            </div>
                        );
                    }),
                );
            });
        }
        if (rightItems && rightItems.getPSAppMenuItems) {
            rightItems.getPSAppMenuItems.forEach((item: any) => {
                this.footerRenders.push(
                    this.footerItemsService.registerRightItem((h: any) => {
                        return (
                            <div class='action-item' title={item.tooltip} on-click={() => this.click(item)}>
                                <menu-icon item={item} />
                                {item.caption}
                                {/* todo 菜单多语言*/}
                                {/* this.$tl(item.captiontag,item.caption) */}
                            </div>
                        );
                    }),
                );
            });
        }
    }

    /**
     * 项点击触发界面行为
     *
     * @protected
     * @param {*} item
     * @memberof AppStyle2IndexViewLayout
     */
    protected click(item: any): void {
        this.$store.commit('removeAllPage');
        this.navDataService.removeNavDataFrist();
        let tempContext:any = Util.deepCopy(this.context);
        if(item.getPSNavigateContexts){
            const localContext = Util.formatNavParam(item.getPSNavigateContexts);
            Object.assign(tempContext,localContext);
        }
        if (item.getPSAppFunc) {
            const appFuncs: Array<any> = this.service.getAllFuncs();
            const appFunc = appFuncs.find((element:any) =>{
                return element.appfunctag === item.getPSAppFunc.codeName;
            });
            if (appFunc) {
                AppFuncService.getInstance().executeApplication(appFunc,tempContext);
            }
        } else {
            LogUtil.warn('未指定应用功能');
        }
    }

    /**
     * 绘制左导航菜单
     * 
     * @memberof AppStyle2IndexView
     */
    public renderLeftNavMenu(){
        return (
            this.left_exp?.getPSAppMenuItems ?
            <app-content-left-nav-menu
                slot="leftNavMenu"
                ref="leftNavMenu"
                ctrlName={this.menuInstance?.codeName?.toLowerCase()}
                menus={this.left_exp?.getPSAppMenuItems}
                modelService={this.modelService}
                on-menu-click={(item: any) => this.click(item)}/>
            : null        
        )
    }

    /**
     * 绘制头部菜单
     * 
     * @memberof AppStyle2IndexView
     */
    public renderHeaderMenus(){
        return (
            <app-style2-header-menus
                slot="headerMenus"
                ref="headerMenus"
                ctrlName={this.menuInstance?.codeName?.toLowerCase()}
                menus={this.top_menus?.getPSAppMenuItems}
                modelService={this.modelService}
                on-menu-click={(item: any) => this.click(item)}/>
        )
    }

    /**
     * 绘制导航分页
     * 
     * @memberof AppStyle2IndexView
     */
    public renderTabPageExp(){
        return (
            <tab-page-exp-style2 slot="tabPageExp" ref="tabExp" modelService={this.modelService} activeItem={this.activeItem}></tab-page-exp-style2>
        )
    }

    /**
     * 绘制底部导航
     * 
     * @memberof AppStyle2IndexView
     */
    public renderBottomExp(){
        return (
            this.bottom_exp?.getPSAppMenuItems ?
            <app-content-bottom-exp
                slot="bottomExp"
                ref="bottomExp"
                service={this.service}
                ctrlName={this.menuInstance?.codeName?.toLowerCase()}
                modelService={this.modelService}
                items={this.bottom_exp?.getPSAppMenuItems} />
            : null           
        )
    }

    /**
     * 渲染视图主题内容(隐藏主体表单)
     * 
     * @memberof IndexViewBase
     */
     public renderMainContent() {
        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, style: { display: 'none'} });
    }

    /**
     * 应用首页视图渲染
     * 
     * @memberof AppStyle2IndexView
     */
    render(h: any){
        if(!this.viewIsLoaded){
            return null;
        }
        const targetViewLayoutComponent: any = AppLayoutService.getLayoutComponent(`${this.viewInstance?.viewType}-${this.viewInstance?.viewStyle}`);
        return h(targetViewLayoutComponent, {
            props: { viewInstance: this.viewInstance, model: this.model, modelService: this.modelService, viewparams: this.viewparams, context: this.context },
        }, [
            this.renderLeftNavMenu(),
            this.renderHeaderMenus(),
            this.renderTabPageExp(),
            this.renderMainContent(),
            this.renderBottomExp(),
        ]);
    }
    
}