瀏覽代碼

菜单优化,展示层级结构

master
yaoq 2 年之前
父節點
當前提交
2dc572a744
共有 3 個檔案被更改,包括 103 行新增33 行删除
  1. +23
    -2
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogCache.java
  2. +79
    -30
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/PreviewMenuTreeService.java
  3. +1
    -1
      smtweb-framework/bpm/src/main/resources/codegen/ts/formatter.ts

+ 23
- 2
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogCache.java 查看文件

@@ -8,6 +8,7 @@ import cc.smtweb.framework.core.db.DbEngine;
import cc.smtweb.framework.core.db.EntityDao;
import cc.smtweb.framework.core.db.vo.ModelCatalog;

import java.util.ArrayList;
import java.util.List;

/**
@@ -22,8 +23,8 @@ public class ModelCatalogCache extends AbstractCache<ModelCatalog> {
}

public ModelCatalogCache() {
regList(SwConsts.KEY_PARENT_ID, k-> String.valueOf(k.getParentId()));
regList(CACHE_KEY, k-> k.getPrjId() + SwConsts.SPLIT_CHAR + k.getParentId());
regList(SwConsts.KEY_PARENT_ID, k -> String.valueOf(k.getParentId()));
regList(CACHE_KEY, k -> k.getPrjId() + SwConsts.SPLIT_CHAR + k.getParentId());
}

@Override
@@ -52,4 +53,24 @@ public class ModelCatalogCache extends AbstractCache<ModelCatalog> {
}
return sret.substring(1);
}

public List<Long> getAllParent(long value) {
List<Long> list = new ArrayList<>();
list.add(value);
getAllParent(value, list);
return list;
}

private void getAllParent(long value, List<Long> ids) {
Long parent_id = getParentId(value);
if (parent_id == null) return;
ids.add(parent_id);
getAllParent(parent_id, ids);
}

public Long getParentId(long id) {
ModelCatalog bean = get(id);
if (bean == null || bean.isEmpty()) return null;
return bean.getParentId();
}
}

+ 79
- 30
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/PreviewMenuTreeService.java 查看文件

@@ -3,51 +3,100 @@ package cc.smtweb.system.bpm.web.design.preview;
import cc.smtweb.framework.core.annotation.SwParam;
import cc.smtweb.framework.core.annotation.SwService;
import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.exception.BizException;
import cc.smtweb.framework.core.exception.SwException;
import cc.smtweb.framework.core.common.SwEnum;
import cc.smtweb.framework.core.db.DbEngine;
import cc.smtweb.framework.core.db.vo.ModelCatalog;
import cc.smtweb.framework.core.exception.BizException;
import cc.smtweb.framework.core.session.UserSession;
import cc.smtweb.framework.core.util.CommUtil;
import cc.smtweb.system.bpm.util.TreeDataUtil;
import cc.smtweb.system.bpm.web.design.db.ModelCatalogCache;
import cc.smtweb.system.bpm.web.design.db.ModelProjectCache;
import cc.smtweb.system.bpm.web.design.form.ModelForm;
import cc.smtweb.system.bpm.web.design.form.ModelFormCache;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SwService
public class PreviewMenuTreeService {
@SwParam
private DbEngine dbEngine;

public R treeAll(@SwParam("module") String module, UserSession us) {
String prj_id = ModelProjectCache.getInstance().getIdByModule(module);
List<ModelForm> listForm;
if (StringUtils.isNotEmpty(prj_id)) {
listForm = new ArrayList<>(ModelFormCache.getInstance().getFormsByPrj(Long.parseLong(prj_id)));
} else {
listForm = new ArrayList<>(ModelFormCache.getInstance().getAll());
}
listForm.sort((o1, o2) -> CommUtil.chineseCompare(o1.getTitle(), o2.getTitle()));
if (listForm.isEmpty()) throw new BizException("此项目无页面设计!");

List<MenuVO> list = new ArrayList<>(listForm.size());
for (ModelForm form: listForm) {
MenuVO menu = new MenuVO();
menu.setId(form.getId());
menu.setName(form.getTitle());
menu.setPath("/bpm/" + form.getId());
// menu.setParentId(-1L);
list.add(menu);
@SwParam
private DbEngine dbEngine;

public R treeAll(@SwParam("module") String module, UserSession us) {
String prj_id = ModelProjectCache.getInstance().getIdByModule(module);

List<ModelForm> listForm;
if (StringUtils.isNotEmpty(prj_id)) {
listForm = new ArrayList<>(ModelFormCache.getInstance().getFormsByPrj(Long.parseLong(prj_id)));
} else {
listForm = new ArrayList<>(ModelFormCache.getInstance().getAll());
}
listForm.sort((o1, o2) -> CommUtil.chineseCompare(o1.getTitle(), o2.getTitle()));
if (listForm.isEmpty()) throw new BizException("此项目无页面设计!");

List<MenuVO> list = new ArrayList<>();
Map<Long, MenuVO> map = new HashMap<>();
for (ModelForm form : listForm) {
if (SwEnum.FormType.PAGE.value != form.getType()) continue;
List<Long> parentLog = ModelCatalogCache.getInstance().getAllParent(form.getMcId());
for (Long parent_id : parentLog) {
if (map.containsKey(parent_id)) continue;
ModelCatalog catalog = ModelCatalogCache.getInstance().get(parent_id);
if (catalog == null || catalog.isEmpty()) continue;
MenuVO menu = setMenuParent(parent_id, map, list);
if (menu == null) continue;
setMenuChildren(map.get(menu.getParentId()), menu);
}
MenuVO menu = new MenuVO();
menu.setId(form.getId());
menu.setName(form.getTitle());
menu.setPath("/bpm/" + form.getId());
menu.setParentId(form.getMcId());

setMenuChildren(map.get(form.getMcId()), menu);
}

MenuVO root = new MenuVO();
root.setName("项目");
root.setPath(module);
root.setId(-1L);
List<MenuVO> data = TreeDataUtil.buildTree(root, list, MenuVO.createTreeHandler());

return R.success(data);
}

MenuVO root = new MenuVO();
root.setName("项目");
root.setPath(module);
List<MenuVO> data = TreeDataUtil.buildTree(root, list, MenuVO.createTreeHandler());
private MenuVO setMenuParent(Long parent_id, Map<Long, MenuVO> map, List<MenuVO> list) {
MenuVO parent = map.get(parent_id);
if (parent != null) return parent;

return R.success(data);
}
ModelCatalog parentBean = ModelCatalogCache.getInstance().get(parent_id);
if (parentBean == null) return null;
parent = map.get(parentBean.getId());
if (parent != null) return parent;
parent = new MenuVO();
parent.setId(parentBean.getId());
parent.setName(parentBean.getName());
parent.setPath("");
parent.setParentId(parentBean.getParentId());
if (parentBean.getParentId() == -1) {
list.add(parent);
}
map.put(parentBean.getId(), parent);
setMenuParent(parentBean.getParentId(), map, list);
return parent;
}

private void setMenuChildren(MenuVO parent, MenuVO child) {
if (parent == null) return;
List<MenuVO> childs = parent.getChildren();
if (childs == null) {
childs = new ArrayList<>();
parent.setChildren(childs);
}
childs.add(child);
}
}

+ 1
- 1
smtweb-framework/bpm/src/main/resources/codegen/ts/formatter.ts 查看文件

@@ -5,7 +5,7 @@ export default {
methods: {
timeFormatter(row: string, column: any, cellValue: string) {
// 日期时间
// temp 20210226113627 -> 2021-02-26 11:36:27
// temp.json 20210226113627 -> 2021-02-26 11:36:27
if (cellValue && cellValue.length >= 14) {
const pattern = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/;
return cellValue.replace(pattern, '$1-$2-$3 $4:$5:$6');


Loading…
取消
儲存