门户定制案例-系统标题中显示当前人机构名称
运行效果
在门户页顶部标题中显示当前人的第一级机构名称,如下图所示
实现方法
- 定制企业门户应用,参考《门户定制》
- 在门户页 /entry/pcxapp/pcx/index.w 中,页面顶部标题渲染方法 bindedHeaderTitleRender 的 before 扩展点,获取系统名称,获取当前人机构名称,写入标题参数
添加扩展点
桌面端门户的扩展点方法写在 /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 页面顶部标题渲染方法 bindedHeaderTitleRender 的 before 扩展点,代码如下
async onConfigContextInit(configContextProcessor) {
let _this = configContextProcessor.page;
let portalConfig = {
"config": {
"/entry": {
"/pcxapp": {
"/pcx": {
"/index.w": {
"bindedHeaderTitleRender": {
"@before": (...args) => {
if(!_this.state.currentPsm) return;
//获取系统名称和当前人机构名称,写入标题
let orgName = _this.state.currentPsm.label.split("/")[0];
args[1].props.children = _this.state.portalConfig.sysName + " " + orgName;
}
},
}
}
}
}
}
};
merge(_this.configContext, portalConfig);
ConfigContextProcessor.enhancePageAdvice(_this);
}
- 从 _this.state.portalConfig.sysName 中获取系统名称
- 从 _this.state.currentPsm 中获取当前人机构名称
- args[1].props.children 是系统标题参数
完整代码
/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": {
"bindedHeaderTitleRender": {
"@before": (...args) => {
if(!_this.state.currentPsm) return;
//获取系统名称和当前人机构名称,写入标题
let orgName = _this.state.currentPsm.label.split("/")[0];
args[1].props.children = _this.state.portalConfig.sysName + " " + orgName;
}
}
}
}
}
}
}
};
//处理自定义内容
merge(_this.configContext, portalConfig);
ConfigContextProcessor.enhancePageAdvice(_this);
}
}