From 1285ba494ddc6e8a31819758f4f66c539f0092e3 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Thu, 29 Apr 2021 12:46:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=B3=BB=E7=BB=9F=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=BC=B9=E6=A1=86=E6=94=B9=E4=B8=BA=E9=9A=90=E8=97=8F=E8=B7=AF?= =?UTF-8?q?=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/sys/SysMenuController.java | 7 + .../controller/sys/response/MenuTreeNode.java | 26 +++ .../io/dataease/service/sys/MenuService.java | 31 +++ frontend/src/api/system/menu.js | 9 +- .../business/complex-table/index.vue | 4 + frontend/src/views/system/dept/form.vue | 173 ++++++++++++++++ frontend/src/views/system/dept/index.vue | 22 ++- frontend/src/views/system/menu/form.vue | 187 ++++++++++++++++++ frontend/src/views/system/menu/index.vue | 22 ++- frontend/src/views/system/role/form.vue | 80 ++++++++ frontend/src/views/system/role/index.vue | 18 +- frontend/src/views/system/user/form.vue | 3 +- 12 files changed, 558 insertions(+), 24 deletions(-) create mode 100644 backend/src/main/java/io/dataease/controller/sys/response/MenuTreeNode.java create mode 100644 frontend/src/views/system/dept/form.vue create mode 100644 frontend/src/views/system/menu/form.vue create mode 100644 frontend/src/views/system/role/form.vue diff --git a/backend/src/main/java/io/dataease/controller/sys/SysMenuController.java b/backend/src/main/java/io/dataease/controller/sys/SysMenuController.java index 19e7026fdf..517c83a130 100644 --- a/backend/src/main/java/io/dataease/controller/sys/SysMenuController.java +++ b/backend/src/main/java/io/dataease/controller/sys/SysMenuController.java @@ -7,6 +7,7 @@ import io.dataease.commons.utils.BeanUtils; import io.dataease.controller.sys.request.MenuCreateRequest; import io.dataease.controller.sys.request.MenuDeleteRequest; import io.dataease.controller.sys.response.MenuNodeResponse; +import io.dataease.controller.sys.response.MenuTreeNode; import io.dataease.service.sys.MenuService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -62,6 +63,12 @@ public class SysMenuController { sets.add(pid); return sets; } + @PostMapping("/nodesByMenuId/{menuId}") + public List nodesByMenuId(@PathVariable("menuId") Long menuId) { + return menuService.searchTree(menuId); + } + + } diff --git a/backend/src/main/java/io/dataease/controller/sys/response/MenuTreeNode.java b/backend/src/main/java/io/dataease/controller/sys/response/MenuTreeNode.java new file mode 100644 index 0000000000..56d708a369 --- /dev/null +++ b/backend/src/main/java/io/dataease/controller/sys/response/MenuTreeNode.java @@ -0,0 +1,26 @@ +package io.dataease.controller.sys.response; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class MenuTreeNode implements Serializable { + + private Long id; + + private String label; + + private Boolean hasChildren; + + private List children; + + public List toList(){ + List lists = new ArrayList<>(); + lists.add(this); + return lists; + } +} diff --git a/backend/src/main/java/io/dataease/service/sys/MenuService.java b/backend/src/main/java/io/dataease/service/sys/MenuService.java index 8eb3fe2b1d..725fa7b390 100644 --- a/backend/src/main/java/io/dataease/service/sys/MenuService.java +++ b/backend/src/main/java/io/dataease/service/sys/MenuService.java @@ -1,5 +1,6 @@ package io.dataease.service.sys; +import io.dataease.base.domain.SysDept; import io.dataease.base.domain.SysMenu; import io.dataease.base.domain.SysMenuExample; import io.dataease.base.mapper.SysMenuMapper; @@ -7,8 +8,10 @@ import io.dataease.base.mapper.ext.ExtMenuMapper; import io.dataease.commons.utils.BeanUtils; import io.dataease.controller.sys.request.MenuCreateRequest; import io.dataease.controller.sys.request.MenuDeleteRequest; +import io.dataease.controller.sys.response.DeptTreeNode; import io.dataease.controller.sys.response.MenuNodeResponse; +import io.dataease.controller.sys.response.MenuTreeNode; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ObjectUtils; import org.springframework.stereotype.Service; @@ -16,6 +19,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.HashSet; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -121,6 +125,24 @@ public class MenuService { return responses; } + public List searchTree(Long menuId) { + List roots = nodesByPid(0L); + if (menuId == MENU_ROOT_PID) return roots.stream().map(this::format).collect(Collectors.toList()); + SysMenu sysMenu = sysMenuMapper.selectByPrimaryKey(menuId); + if (roots.stream().anyMatch(node -> node.getMenuId() == menuId)) return roots.stream().map(this::format).collect(Collectors.toList()); + SysMenu current = sysMenu; + MenuTreeNode currentNode = format(sysMenu); + while (current.getPid() != MENU_ROOT_PID){ + SysMenu parent = sysMenuMapper.selectByPrimaryKey(current.getPid()); //pid上有索引 所以效率不会太差 + MenuTreeNode parentNode = format(parent); + parentNode.setChildren(currentNode.toList()); + current = parent; + currentNode = parentNode; + } + MenuTreeNode targetRootNode = currentNode; + return roots.stream().map(node -> node.getMenuId() == targetRootNode.getId() ? targetRootNode : format(node)).collect(Collectors.toList()); + } + private Set getChilds(List lists, Set sets){ lists.forEach(menu -> { sets.add(menu); @@ -132,6 +154,15 @@ public class MenuService { return sets; } + private MenuTreeNode format(SysMenu sysMenu) { + MenuTreeNode menuTreeNode = new MenuTreeNode(); + menuTreeNode.setId(sysMenu.getMenuId()); + menuTreeNode.setLabel(sysMenu.getName()); + menuTreeNode.setHasChildren(false); + Optional.ofNullable(sysMenu.getMenuSort()).ifPresent(num -> menuTreeNode.setHasChildren(num > 0)); + return menuTreeNode; + } + public List convert(List menus){ return menus.stream().map(node -> { MenuNodeResponse menuNodeResponse = BeanUtils.copyBean(new MenuNodeResponse(), node); diff --git a/frontend/src/api/system/menu.js b/frontend/src/api/system/menu.js index a093687647..2aef84616e 100644 --- a/frontend/src/api/system/menu.js +++ b/frontend/src/api/system/menu.js @@ -46,4 +46,11 @@ export function editMenu(data) { }) } -export default { addMenu, editMenu, delMenu, getMenusTree, getChild } +export function treeByMenuId(menuId) { + return request({ + url: '/api/menu/nodesByMenuId/' + menuId, + method: 'post' + }) +} + +export default { addMenu, editMenu, delMenu, getMenusTree, getChild, treeByMenuId } diff --git a/frontend/src/components/business/complex-table/index.vue b/frontend/src/components/business/complex-table/index.vue index 9c625a4edb..684a9430dc 100644 --- a/frontend/src/components/business/complex-table/index.vue +++ b/frontend/src/components/business/complex-table/index.vue @@ -46,9 +46,13 @@ export default { type: Array, default: () => [] }, + // eslint-disable-next-line vue/require-default-prop localKey: String, // 如果需要记住选择的列,则这里添加一个唯一的Key + // eslint-disable-next-line vue/require-default-prop header: String, + // eslint-disable-next-line vue/require-default-prop searchConfig: Object, + // eslint-disable-next-line vue/require-default-prop paginationConfig: Object }, data() { diff --git a/frontend/src/views/system/dept/form.vue b/frontend/src/views/system/dept/form.vue new file mode 100644 index 0000000000..9d767d63ca --- /dev/null +++ b/frontend/src/views/system/dept/form.vue @@ -0,0 +1,173 @@ + + + diff --git a/frontend/src/views/system/dept/index.vue b/frontend/src/views/system/dept/index.vue index 19a3c8b8ce..a2c25378a8 100644 --- a/frontend/src/views/system/dept/index.vue +++ b/frontend/src/views/system/dept/index.vue @@ -203,17 +203,23 @@ export default { this.search() }, methods: { + // create() { + // this.form = Object.assign({}, this.defaultForm) + // this.dialogOrgAddVisible = true + // this.formType = 'add' + // }, + // edit(row) { + // this.dialogOrgAddVisible = true + // this.formType = 'modify' + // this.oldPid = row.pid + // this.form = Object.assign({}, row) + // this.treeByRow(row) + // }, create() { - this.form = Object.assign({}, this.defaultForm) - this.dialogOrgAddVisible = true - this.formType = 'add' + this.$router.push({ name: '组织表单' }) }, edit(row) { - this.dialogOrgAddVisible = true - this.formType = 'modify' - this.oldPid = row.pid - this.form = Object.assign({}, row) - this.treeByRow(row) + this.$router.push({ name: '组织表单', params: row }) }, treeByRow(row) { diff --git a/frontend/src/views/system/menu/form.vue b/frontend/src/views/system/menu/form.vue new file mode 100644 index 0000000000..d84b7529be --- /dev/null +++ b/frontend/src/views/system/menu/form.vue @@ -0,0 +1,187 @@ + + + diff --git a/frontend/src/views/system/menu/index.vue b/frontend/src/views/system/menu/index.vue index 1fb23fc3b1..b17ef69f7e 100644 --- a/frontend/src/views/system/menu/index.vue +++ b/frontend/src/views/system/menu/index.vue @@ -199,21 +199,27 @@ export default { this.initTableData() }, methods: { + // create() { + // this.form = Object.assign({}, this.defaultForm) + // this.dialogVisible = true + // this.formType = 'add' + // }, create() { - this.form = Object.assign({}, this.defaultForm) - this.dialogVisible = true - this.formType = 'add' + this.$router.push({ name: '菜单表单' }) }, search(condition) { console.log(condition) }, + // edit(row) { + // this.dialogVisible = true + // this.formType = 'modify' + // this.oldPid = row.pid + // this.form = Object.assign({}, row) + // this.treeByRow(row) + // }, edit(row) { - this.dialogVisible = true - this.formType = 'modify' - this.oldPid = row.pid - this.form = Object.assign({}, row) - this.treeByRow(row) + this.$router.push({ name: '菜单表单', params: row }) }, treeByRow(row) { diff --git a/frontend/src/views/system/role/form.vue b/frontend/src/views/system/role/form.vue new file mode 100644 index 0000000000..6ecc4551fb --- /dev/null +++ b/frontend/src/views/system/role/form.vue @@ -0,0 +1,80 @@ + + + diff --git a/frontend/src/views/system/role/index.vue b/frontend/src/views/system/role/index.vue index a80a4a55a5..93e2c40ca7 100644 --- a/frontend/src/views/system/role/index.vue +++ b/frontend/src/views/system/role/index.vue @@ -152,10 +152,13 @@ export default { handleClick(tab, event) { console.log(tab, event) }, + // create() { + // this.form = {} + // this.formType = 'add' + // this.dialogVisible = true + // }, create() { - this.form = {} - this.formType = 'add' - this.dialogVisible = true + this.$router.push({ name: '角色表单' }) }, search(condition) { const temp = formatCondition(condition) @@ -167,10 +170,13 @@ export default { }) }, + // edit(row) { + // this.formType = 'modify' + // this.dialogVisible = true + // this.form = Object.assign({}, row) + // }, edit(row) { - this.formType = 'modify' - this.dialogVisible = true - this.form = Object.assign({}, row) + this.$router.push({ name: '角色表单', params: row }) }, saveRole(roleForm) { diff --git a/frontend/src/views/system/user/form.vue b/frontend/src/views/system/user/form.vue index 520684236f..39c7fd9696 100644 --- a/frontend/src/views/system/user/form.vue +++ b/frontend/src/views/system/user/form.vue @@ -31,7 +31,7 @@ v-model="form.deptId" :options="depts" :load-options="loadDepts" - + :auto-load-root-options="false" placeholder="选择部门" /> @@ -182,6 +182,7 @@ export default { const results = res.data.map(node => { if (node.hasChildren && !node.children) { node.children = null + // delete node.children } return node })