后端实现
代理继承界面设计器视图模型
@Model.model(MyView.MODEL_MODEL)
@Model(displayName = "视图代理")
@Model.Advanced(type = ModelTypeEnum.PROXY)
public class MyView extends UiDesignerViewProxy {
public static final String MODEL_MODEL = "hr.simple.MyView";
@Field.Integer
@Field(displayName = "页面布局ID")
private Long uiDesignerViewLayoutId;
}
@Component
@Module(
name = TopModule.MODULE_NAME,
displayName = "oinone功能展示",
version = "1.0.0",
dependencies = {
ModuleConstants.MODULE_BASE,
CommonModule.MODULE_MODULE,
UserModule.MODULE_MODULE,
EipModule.MODULE_MODULE,
TriggerModule.MODULE_MODULE,
BusinessModule.MODULE_MODULE,
DataAuditModule.MODULE_MODULE,
FileModule.MODULE_MODULE,
ChannelModule.MODULE_MODULE,
WorkflowModule.MODULE_MODULE,
PrintModule.MODULE_MODULE,
UiDesignerModule.MODULE_MODULE
},
exclusions = {},
clientTypes = {
ClientTypeEnum.PC,
ClientTypeEnum.MOBILE
})
重写查询接口,返回页面布局ID,重写创建接口,实现创建页面逻辑。业务模块依赖 UiDesignerModule.MODULE_MODULE
package pro.shushi.pamirs.top.core.action;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import pro.shushi.pamirs.boot.base.constants.ViewConstants;
import pro.shushi.pamirs.boot.base.enmu.ActionTargetEnum;
import pro.shushi.pamirs.boot.base.ux.annotation.action.UxAction;
import pro.shushi.pamirs.boot.base.ux.annotation.action.UxRoute;
import pro.shushi.pamirs.boot.base.ux.annotation.button.UxRouteButton;
import pro.shushi.pamirs.framework.connectors.data.sql.Pops;
import pro.shushi.pamirs.framework.connectors.data.sql.query.LambdaQueryWrapper;
import pro.shushi.pamirs.meta.annotation.Action;
import pro.shushi.pamirs.meta.annotation.Function;
import pro.shushi.pamirs.meta.annotation.Model;
import pro.shushi.pamirs.meta.api.dto.condition.Pagination;
import pro.shushi.pamirs.meta.api.dto.wrapper.IWrapper;
import pro.shushi.pamirs.meta.api.session.PamirsSession;
import pro.shushi.pamirs.meta.constant.FunctionConstants;
import pro.shushi.pamirs.meta.enmu.*;
import pro.shushi.pamirs.top.api.model.MyView;
import pro.shushi.pamirs.ui.designer.api.designe.UiDesignerViewLayoutService;
import pro.shushi.pamirs.ui.designer.model.UiDesignerViewLayout;
import pro.shushi.pamirs.ui.designer.pmodel.UiDesignerViewLayoutProxy;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author Yexiu at 20:39 on 2025/3/27
*/
@Component
@Model.model(MyView.MODEL_MODEL)
public class MyViewAction {
@Autowired
private UiDesignerViewLayoutService uiDesignerViewLayoutService;
@Action.Advanced(name = FunctionConstants.create, managed = true)
@Action(displayName = "创建", summary = "添加", bindingType = ViewTypeEnum.FORM)
@Function(name = FunctionConstants.create)
@Function.fun(FunctionConstants.create)
public MyView create(MyView data) {
UiDesignerViewLayoutProxy uiDesignerViewLayoutProxy = new UiDesignerViewLayoutProxy();
uiDesignerViewLayoutProxy.setBizType(data.getBizType());
uiDesignerViewLayoutProxy.setDesignerActionBarType(data.getDesignerActionBarType());
uiDesignerViewLayoutProxy.setViewType(data.getType());
uiDesignerViewLayoutProxy.setModel(data.getModel());
uiDesignerViewLayoutProxy.setModule(PamirsSession.getServApp());
uiDesignerViewLayoutProxy.setViewTitle(data.getTitle());
uiDesignerViewLayoutProxy.setUsingDefaultView(data.getLoadLayout());
UiDesignerViewLayoutProxy saveUiDesigner = uiDesignerViewLayoutService.create(uiDesignerViewLayoutProxy);
data.setDesignerViewId(saveUiDesigner.getId());
return data;
}
@Function.Advanced(type = FunctionTypeEnum.QUERY, displayName = "查询列表")
@Function.fun(FunctionConstants.queryPage)
@Function(openLevel = {FunctionOpenEnum.API, FunctionOpenEnum.LOCAL})
public Pagination<MyView> queryPage(Pagination<MyView> page, IWrapper<MyView> queryWrapper) {
LambdaQueryWrapper<MyView> wrapper = Pops.<MyView>lambdaQuery().from(MyView.MODEL_MODEL)
.eq(MyView::getSys, Boolean.FALSE)
.eq(MyView::getSystemSource, SystemSourceEnum.UI);
Pagination<MyView> myViewPagination = new MyView().queryPage(page, wrapper);
List<MyView> content = myViewPagination.getContent();
// 提前返回,就算是NULL的也没事,省去不必要的判断
if (CollectionUtils.isEmpty(content)) {
return myViewPagination;
}
List<UiDesignerViewLayout> uiDesignerViewLayoutList = new UiDesignerViewLayout().queryList();
if (CollectionUtils.isEmpty(uiDesignerViewLayoutList)) {
return myViewPagination;
}
Map<String, Long> userTaskMap = uiDesignerViewLayoutList.stream().collect(Collectors.toMap(
i-> buildMapKey(i.getModel(), i.getViewName()), UiDesignerViewLayout::getId, (old, n) -> old)
);
for (MyView myView : content) {
myView.setUiDesignerViewLayoutId(userTaskMap.get(buildMapKey(myView.getModel(), myView.getName())));
}
return myViewPagination;
}
private String buildMapKey(String model, String viewName) {
return model + ":" + viewName;
}
}
在页面设计器创建页面,并创建跳转动作
复制表单到详情实现,做界面设计器发布接口后置拦截。
package pro.shushi.pamirs.top.core.hook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import pro.shushi.pamirs.meta.annotation.Hook;
import pro.shushi.pamirs.meta.api.core.faas.HookAfter;
import pro.shushi.pamirs.meta.api.dto.common.Message;
import pro.shushi.pamirs.meta.api.dto.fun.Function;
import pro.shushi.pamirs.meta.api.session.PamirsSession;
import pro.shushi.pamirs.meta.enmu.InformationLevelEnum;
import pro.shushi.pamirs.meta.enmu.ViewTypeEnum;
import pro.shushi.pamirs.ui.designer.api.designe.UiDesignerViewLayoutCopyService;
import pro.shushi.pamirs.ui.designer.model.UiDesignerViewLayout;
import pro.shushi.pamirs.ui.designer.pmodel.UiDesignerViewLayoutProxy;
/**
* @author Yexiu at 17:25 on 2025/3/31
*/
@Component
public class UiDesignerHook implements HookAfter {
@Autowired
private UiDesignerViewLayoutCopyService uiDesignerViewLayoutCopyService;
@Override
@Hook(module = {"ui_designer"}, model = {UiDesignerViewLayoutProxy.MODEL_MODEL}, fun = {"saveView"})
public Object run(Function function, Object ret) {
if (ret == null) {
return null;
}
UiDesignerViewLayoutProxy result = null;
if (ret instanceof Object[]) {
Object[] rets = (Object[]) ((Object[]) ret);
if (rets.length == 1) {
result = (UiDesignerViewLayoutProxy) rets[0];
}
} else {
result = (UiDesignerViewLayoutProxy) ret;
}
UiDesignerViewLayout source = result.queryOne();
if (source != null && ViewTypeEnum.FORM.equals(source.getViewType())) {
UiDesignerViewLayoutProxy target = new UiDesignerViewLayoutProxy();
target.setModel(source.getModel());
target.setModule(source.getModule());
target.setViewTitle(result.getViewTitle() + "-详情");
target.setViewType(ViewTypeEnum.DETAIL);
target.setModuleDefinition(source.getModuleDefinition());
target.setModelDefinition(PamirsSession.getContext().getModelConfig(source.getModel()).getModelDefinition());
target.setViewDescription(result.getViewDescription());
if (source.getDesignerActionBarType() != null) {
target.setDesignerActionBarType(source.getDesignerActionBarType());
}
//利用以上输入信息做唯一,也就是说用户不可以建两个标题一样的模版,否则原有复制的详情页面会被覆盖
//可以根据业务需求自定义修改逻辑
UiDesignerViewLayoutProxy isExist = null;
try {
isExist = target.queryOne();
} catch (Exception e) {
PamirsSession.getMessageHub().msg(Message.init().setLevel(InformationLevelEnum.ERROR)
.setMessage("该模型下存在重复模版标题: 【" + target.getViewTitle() + "】请删除后重试"));
throw new RuntimeException(e);
}
if (isExist == null) {
uiDesignerViewLayoutCopyService.copy(source, target);
} else {
isExist.setDesignerJson(result.getDesignerJson());
isExist.setTemplateJson(result.getTemplateJson());
isExist.createOrUpdate();
}
}
return ret;
}
}
Oinone社区 作者:yexiu原创文章,如若转载,请注明出处:https://doc.oinone.top/other/20853.html
访问Oinone官网:https://www.oinone.top获取数式Oinone低代码应用平台体验