门户定制案例-默认选择展开第一个一级菜单
运行效果
门户初始化完成后,默认选择展开第一个一级菜或指定菜单
实现方法
- 定制企业门户应用,参考《门户定制》
- 在门户页 /entry/pcxapp/pcx/index.w 中,在方法 onInitedCallback 的 after 扩展点下设置选择属性selectedKeys和展开属性openKeys
- 从门户页(/entry/pcxapp/pcx/index.w)state中currentMenus属性,获取第一个一级菜单的key值并设置
注意: currentMenus菜单数据:当前人员成员权限下菜单数据(一般使用这里的菜单数据) menus菜单数据:当前用户下所有菜单数据
添加扩展点
桌面端门户的扩展点方法写在 /UI2/comp/portalConfig/components/portalConfig/portalConfig.config.pc.js 文件的 onConfigContextInit 方法中,如果没有 portalConfig.config.pc.js 文件,将 portalConfig.config.js 文件复制为 portalConfig.config.pc.js 文件
添加门户页 /entry/pcxapp/pcx/index.w 定义方法 onInitedCallback 的 after 扩展点,代码如下
async onConfigContextInit(configContextProcessor) {
let _this = configContextProcessor.page;
let portalConfig = {
"config": {
"/entry": {
"/pcxapp": {
"/pcx": {
"/index.w": {
"onInitedCallback": {
"@after": (result, ...args) => {
}
}
}
}
}
}
}
};
merge(_this.configContext, portalConfig);
ConfigContextProcessor.enhancePageAdvice(_this);
}
完整代码
/UI2/comp/portalConfig/components/portalConfig/portalConfig.config.pc.js 文件的完整代码如下
import { merge } from "lodash";
import ConfigContextProcessor from 'core/framework/ConfigContextProcessor';
import React from 'react';
export default {
processConfigContext(configContext) {
},
//自定义
async onConfigContextInit(configContextProcessor) {
//获取当前页
let _this = configContextProcessor.page;
//按照需要处理的文件路径及方法进行自定义
//@after:方法执行后执行;参数:(result,...args),其中result是方法返回数据,args是原方法自带参数
//@before:方法执行前执行;参数:(...args),其中args是原方法自带参数
//@replace:替换原方法;参数:(...args),其中args是原方法自带参数
//注意:上述3种方法,async标识必须与原方法同步,即原方法是异步,现在自定义方法才能使用异步,否则不能使用
//详细使用案例可以参考“帮助中心”下门户v2定制下相关案例
let portalConfig = {
"config": {
"/entry": {
"/pcxapp": {
"/pcx": {
"/index.w": {
/**
* onInitedCallback方法是在门户首页全部初始完成后执行方法,如果有相关state属性操作,都需要在这个之后进行
*
* */
"onInitedCallback":{
/**
* 菜单选择state属性是selectedKeys
* 菜单展开state属性是openKeys
* @param {*} result
* @param {...any} args
*/
"@after": async(result, ...args) => {
//注意这里的菜单需要从currentMenus中获取
/**
* 自定义需要展开菜单key,菜单key需要从_this.state.currentMenus中获取
*
*/
const optKeys=[
"SERVICE系统管理SERVICE系统管理",
"SERVICE::系统管理系统配置SERVICE::系统管理系统配置",
"SERVICE::系统管理::系统配置/entry/misc-mobileapp/misc-mobile/unionConfig/commonConfig.wSERVICE::系统管理::系统配置/entry/misc-pcxapp/misc-pcx/unionConfig/commonConfig"
];
//设置菜单选中并展开
// _this.setState({selectedKeys:optKeys,openKeys:optKeys});
/**
* 默认张开第一个一级菜单
*/
const firstMenu=[_this.state.currentMenus[0].key];
_this.setState({selectedKeys:firstMenu,openKeys:firstMenu});
}
}
}
}
}
}
}
};
//处理自定义内容
merge(_this.configContext, portalConfig);
ConfigContextProcessor.enhancePageAdvice(_this);
}
}
