import { Util, LogUtil, throttle } from '@ibizstudio/runtime'; import { Emit } from 'vue-property-decorator'; import { AppMenuControlBase } from '../../../widgets'; /** * 应用菜单部件基类 * * @export * @class AppmenuBase * @extends {AppMenuControlBase} */ export class AppmenuBase extends AppMenuControlBase { /** * 左侧应用菜单的右侧视图组件 * * @type {*} * @memberof AppmenuBase */ renderRightView: any; /** * 左侧应用菜单分割面板比例 * * @type {number} * @memberof AppmenuBase */ split: number = 0.15; /** * 配置左侧分页菜单默认选项 * * @return {*} * @memberof AppmenuBase */ defaultMuneOption(menus: any[]): any { return menus[0]?.getPSAppMenuItems?.[0]; } /** * 顶部菜单项选中 * * @param {string} item * @memberof AppmenuBase */ topMenuSelected(item: string) { this.menus.forEach(menu1 => { if (menu1?.name == item) { return this.menuTreeClick(menu1); } else { menu1.getPSAppMenuItems.forEach((menu2: any) => { if (menu2?.name == item) { return this.menuTreeClick(menu2); } }); } }); } /** * 加载菜单的默认点击 * * @memberof AppmenuBase */ defaultMenuSelect(): void { //分页导航菜单的默认点击 if (Object.is(this.staticProps.mode, 'TABEXP_LEFT' || 'TABEXP_TOP' || 'TABEXP_RIGHT' || 'TABEXP_BOTTOM')) { return this.menuTreeClick(this.defaultMuneOption(this.menus)); } if (!this.isDefaultPage || this.isBlankMode) { return; } const appFuncs: Array = this.service.getAllFuncs(); if (this.$route && this.$route.matched && this.$route.matched.length == 2) { // 存在二级路由 const [{}, matched] = this.$route.matched; const appfunc: any = appFuncs.find((_appfunc: any) => Object.is(_appfunc.routepath, matched.path) && Object.is(_appfunc.appfunctype, 'APPVIEW')); if (appfunc) { this.computeMenuSelect(this.menus, appfunc.appfunctag); } return; } else if (this.defPSAppView && Object.keys(this.defPSAppView).length > 0) { // 存在默认视图 const appfunc: any = appFuncs.find((_appfunc: any) => Object.is(_appfunc.getPSAppView.codeName, this.defPSAppView.codeName) && Object.is(_appfunc.appFuncType, 'APPVIEW')); if (appfunc) { this.computeMenuSelect(this.menus, appfunc.appfunctag); } } else { this.computeMenuSelect(this.menus, ''); } let item = this.compute(this.menus, this.defaultActive); if (Object.keys(item).length === 0) { return; } if (!item.hidden) { this.click(item); } } /** * 左侧菜单点击 * * @param {*} item ***对象 * @memberof AppmenuBase */ menuTreeClick(item: any) { let tempContext: any = Util.deepCopy(this.context); if (item.getPSNavigateContexts) { const localContext = Util.formatNavParam(item.getPSNavigateContexts); Object.assign(tempContext, localContext); } else { if (tempContext.hasOwnProperty('srfdynainstid')) { delete tempContext.srfdynainstid; } } if (item.getPSAppFunc) { const appFuncs: Array = this.service.getAllFuncs(); const appFunc = appFuncs.find((element: any) => { return element.appfunctag === item.getPSAppFunc.codeName; }); if (appFunc && appFunc.getPSAppView) { Object.assign(tempContext, { viewpath: appFunc.getPSAppView._modelFilePath }); let targetCtrlParam: any = { staticProps: { viewDefaultUsage: false, }, dynamicProps: { viewparam: {}, viewdata: JSON.stringify(tempContext), }, }; this.renderRightView = this.$createElement('app-view-shell', { key: Util.createUUID(), class: 'viewcontainer2', props: targetCtrlParam, }); this.$forceUpdate(); } } else { LogUtil.warn(this.$t('app.commonwords.noassign')); } } /** * 左侧应用菜单树绘制事件 * * @param {*} h * @param {*} { node, data } * @return {*} **node * @memberof AppmenuBase */ menuTreeload(h: any, { node, data }: any) { if (data.hidden) { return null; } if (data.getPSAppMenuItems && data.getPSAppMenuItems.length > 0) { return (
{node.data.caption}
); } else { return (
{node.data.caption}
); } } /** * 部件事件 * * @param {{ controlname: string; action: string; data: any }} { controlname 部件名称, action 事件名称, data 事件参数 } * @memberof AppmenuBase */ @Emit('ctrl-event') ctrlEvent({ controlname, action, data }: { controlname: string; action: string; data: any }): void {} /** * 绘制菜单项 * * @param menu 同一级菜单 * @param isFirst 是否为一级菜单 * @memberof AppmenuBase */ renderMenuItem(menu: any, isFirst: boolean) { let hasIcon: boolean = menu.getPSSysImage?.imagePath || menu.getPSSysImage?.cssClass || (!menu.getPSSysImage && isFirst) ? true : false; return Object.is(menu.itemType, 'MENUITEM') && !menu.hidden ? ( {menu.getPSSysImage?.imagePath ? : null} {menu.getPSSysImage?.cssClass ? : null} {!menu.getPSSysImage && isFirst ? : null} {isFirst && this.collapseChange ? ( {(this as any).$tl(menu.captionTag, menu.caption).slice(0, 1)} ) : null} ) : Object.is(menu.itemType, 'SEPERATOR') && !menu.hidden ? ( ) : null; } /** * 绘制子菜单 * * @param menus 同一级菜单 * @param isFirst 是否为一级菜单 * @memberof AppmenuBase */ renderSubmenu(menus: any, isFirst: boolean) { let hasIcon: boolean = menus.getPSSysImage?.imagePath || menus.getPSSysImage?.cssClass || (!menus.getPSSysImage && isFirst) ? true : false; return !menus.hidden ? ( {menus.getPSAppMenuItems.map((menu: any) => { return this.renderAppMenuContent(menu, false); })} ) : null; } /** * 绘制菜单内容 * * @param menu 菜单项 * @param isFirst 是否为一级菜单 * @memberof AppmenuBase */ renderAppMenuContent(menu: any, isFirst: boolean) { if (menu?.getPSAppMenuItems?.length > 0) { return this.renderSubmenu(menu, isFirst); } else { return this.renderMenuItem(menu, isFirst); } } /** * 绘制应用菜单 * * @memberof AppmenuBase */ renderAppMenu() { return ( this.select(menuName)} on-close={(key: any, keyPath: any) => this.handleCloseMenu(key, keyPath)} default-active={this.defaultActive} >
{this.menus.map((menu: any) => { return this.renderAppMenuContent(menu, true); })}
); } /** * 绘制中间应用菜单 * * @memberof AppmenuBase */ renderMiddleMenu() { return (
{this.menus.map((menu: any) => { return (

{this.$tl(menu.captionTag, menu.caption)}

{menu.getPSAppMenuItems && menu.getPSAppMenuItems.length > 0 ? menu.getPSAppMenuItems.map((item: any) => { return !item.hidden ? this.$createElement('card', { class: 'app-middle-menu-item', nativeOn: { click: () => { throttle(this.click, [item], this); }, }, scopedSlots: { default: () => { return (
{this.$tl(item.captionTag, item.caption)}
); }, }, }) : null; }) : null}
); })}
); } /** * 左侧应用菜单的左侧树绘制 * * @return {*} * @memberof AppmenuBase */ renderMenuTree() { if (this.menus && this.menus.length > 0) { const defaultMuneOption: any = this.defaultMuneOption(this.menus)?.name; return this.$createElement('el-tree', { props: { 'current-node-key': defaultMuneOption, data: this.menus, props: { children: 'getPSAppMenuItems', label: 'caption', }, 'default-expand-all': true, 'highlight-current': true, 'render-content': this.menuTreeload.bind(this), 'node-key': 'name', 'filter-node-method': (filter: any, data: any) => { if (!filter) return true; return (this as any).$tl(data.captionTag, data.caption).indexOf(filter) !== -1; }, }, ref: 'eltree', on: { 'node-click': (e: any) => throttle(this.menuTreeClick, [e], this), }, scopedSlots: { default: ({ node, data }: any) => { return this.$tl(data.captionTag, data.caption); }, }, } as any); } } /** * 搜索菜单节点 * * @memberof AppmenuBase */ onSearch(filter: any) { const tree: any = this.$refs.eltree; if (tree && tree.filter && tree.filter instanceof Function) { tree.filter(filter); } } /** * 左侧应用菜单内容 * * @memberof AppmenuBase */ renderContent() { if (this.split == 0.85) { return [
{ this.onSearch(value); }} >
{this.renderMenuTree()}
,
{this.renderRightView ? this.renderRightView : null}
, ]; } else { return [
{ this.onSearch(value); }} >
{this.renderMenuTree()}
,
{this.renderRightView ? this.renderRightView : null}
, ]; } } /** * 绘制左侧应用菜单 * * @return {*} * @memberof AppmenuBase */ renderTableLeftMenu() { return ( {this.renderContent()} ); } /** * 绘制右侧分页菜单 * * @return {*} * @memberof AppmenuBase */ renderTableRightMenu() { this.split = 0.85; return ( {this.renderContent()} ); } /** * 绘制顶部分页菜单 * * @return {*} * @memberof AppmenuBase */ renderTableTopMenu() { const defaultMuneOption: any = this.defaultMuneOption(this.menus)?.name; return (
this.topMenuSelected(e)}> {this.menus.map((item, index) => item.getPSAppMenuItems && item.getPSAppMenuItems.length > 0 ? ( item.getPSAppMenuItems.getPSAppMenuItems && item.getPSAppMenuItems.getPSAppMenuItems.length > 0 ? ( {item.getPSAppMenuItems.getPSAppMenuItems.map((item2: any) => ( {this.$tl(item2.captionTag, item2.caption)} ))} ) : ( {item.getPSAppMenuItems.map((item1: any) => ( {this.$tl(item1.captionTag, item1.caption)} ))} ) ) : ( {this.$tl(item.captionTag, item.caption)} ), )}
{this.renderRightView ? this.renderRightView : null}
); } /** * 绘制底部分页菜单 * * @return {*} * @memberof AppmenuBase */ renderTableBottomMenu() { const defaultMuneOption: any = this.defaultMuneOption(this.menus)?.name; return (
{this.renderRightView ? this.renderRightView : null}
this.topMenuSelected(e)}> {this.menus.map((item, index) => item.getPSAppMenuItems && item.getPSAppMenuItems.length > 0 ? ( item.getPSAppMenuItems.getPSAppMenuItems && item.getPSAppMenuItems.getPSAppMenuItems.length > 0 ? ( {item.getPSAppMenuItems.getPSAppMenuItems.map((item2: any) => ( {this.$tl(item2.captionTag, item2.caption)} ))} ) : ( {item.getPSAppMenuItems.map((item1: any) => ( {this.$tl(item1.captionTag, item1.caption)} ))} ) ) : ( {this.$tl(item.captionTag, item.caption)} ), )}
); } /** * 绘制应用菜单 * * @returns {*} * @memberof AppmenuBase */ render() { if (!this.controlIsLoaded) { return null; } const { controlClassNames } = this.renderOptions; if (this.staticProps && this.staticProps.mode && Object.is(this.staticProps.mode, 'CENTER')) { return
{this.renderMiddleMenu()}
; } else if (this.staticProps && this.staticProps.mode && (Object.is(this.staticProps.mode, 'TABEXP_LEFT') || Object.is(this.staticProps.mode, 'TREEEXP'))) { return
{this.renderTableLeftMenu()}
; } else if (this.staticProps && this.staticProps.mode && Object.is(this.staticProps.mode, 'TABEXP_TOP')) { return
{this.renderTableTopMenu()}
; } else if (this.staticProps && this.staticProps.mode && Object.is(this.staticProps.mode, 'TABEXP_RIGHT')) { return
{this.renderTableRightMenu()}
; } else if (this.staticProps && this.staticProps.mode && Object.is(this.staticProps.mode, 'TABEXP_BOTTOM')) { return
{this.renderTableBottomMenu()}
; } else { return
{this.renderAppMenu()}
; } } }