使用扩展点实现用户中心菜单替换
1. 工程中引起pamirs-user-api
<dependency>
<groupId>pro.shushi.pamirs.core</groupId>
<artifactId>pamirs-user-api</artifactId>
</dependency>
2. 实现TopBarUserBlockAction的后置扩展
- 实现HookAfter后置扩展接口
@Hook(model = {TopBarUserBlock.MODEL_MODEL}, fun = {"construct"})
添加Hook注解注明是TopBarUserBlock
模型的construct
函数的后置扩展。- 替换原有的用户中心菜单
@Component
public class DemoTopBarUserBlockDataHookAfter implements HookAfter {
@Override
@Hook(model = {TopBarUserBlock.MODEL_MODEL}, fun = {"construct"})
public Object run(Function function, Object ret) {
if (ret == null) {
return null;
}
TopBarUserBlock result = null;
if (ret instanceof Object[]) {
Object[] rets = (Object[]) ((Object[]) ret);
if (rets.length == 1) {
result = (TopBarUserBlock) rets[0];
//例:替换用户中心:修改密码菜单
//使用name和model查询出模型的ViewAction替换修改密码ViewAction
ViewAction demoViewAction = new ViewAction().setName("changePassword").setModel(Dog.MODEL_MODEL).queryOne();
//设置菜单的icon
Map<String, Object> attributes = Optional.ofNullable(demoViewAction.getAttributes()).orElse(new HashMap<>());
attributes.put("icon", "oinone-xiugaimima");
demoViewAction.setAttributes(attributes);
//UserViewAction第0个是修改密码ViewAction,使用自定义的ViewAction就可以实现替换
result.getUserViewAction().set(0, demoViewAction);
}
} else {
result = (TopBarUserBlock) ret;
}
return result;
}
}
使用@UxRouteButton方式新增ViewAction,更多新增Action方式详见:Action的类型
@Model.model(Dog.MODEL_MODEL)
@Component
@UxRouteButton(
action = @UxAction(name = "changePassword", displayName = "修改密码"),
value = @UxRoute(model = Dog.MODEL_MODEL, openType = ActionTargetEnum.DIALOG))
public class DogAction {
}
Oinone社区 作者:yexiu原创文章,如若转载,请注明出处:https://doc.oinone.top/backend/14399.html
访问Oinone官网:https://www.oinone.top获取数式Oinone低代码应用平台体验