Browse Source

优化资源管理的页面和接口

reghao 4 năm trước cách đây
mục cha
commit
fcea58df1f
19 tập tin đã thay đổi với 147 bổ sung104 xóa
  1. 17 17
      dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/controller/ResourceController.java
  2. 27 13
      dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/controller/ResourcePageController.java
  3. 1 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/controller/RoleController.java
  4. 8 7
      dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/controller/UserPageController.java
  5. 4 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/db/query/RoleQuery.java
  6. 5 8
      dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/db/query/UserQuery.java
  7. 9 8
      dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/entity/po/Menu.java
  8. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/repository/MenuRepository.java
  9. 8 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/service/MenuService.java
  10. 20 6
      dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/service/ResourceService.java
  11. 5 5
      dmaster/src/main/java/cn/reghao/autodop/dmaster/sys/controller/TestController.java
  12. 6 6
      dmaster/src/main/java/cn/reghao/autodop/dmaster/view/thymeleaf/attribute/SelectDictAttrProcessor.java
  13. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/view/thymeleaf/attribute/SelectListAttrProcessor.java
  14. 5 5
      dmaster/src/main/resources/static/js/timoTree.js
  15. 13 6
      dmaster/src/main/resources/templates/auth/menu/add.html
  16. 4 5
      dmaster/src/main/resources/templates/auth/menu/detail.html
  17. 10 11
      dmaster/src/main/resources/templates/auth/menu/index.html
  18. 0 0
      dmaster/src/main/resources/templates/auth/menu/roles.html
  19. 3 3
      dmaster/src/main/resources/templates/main.html

+ 17 - 17
dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/controller/MenuController.java → dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/controller/ResourceController.java

@@ -1,6 +1,5 @@
 package cn.reghao.autodop.dmaster.auth.controller;
 
-import cn.reghao.autodop.dmaster.auth.entity.DataStatus;
 import cn.reghao.autodop.dmaster.auth.entity.po.Menu;
 import cn.reghao.autodop.dmaster.utils.WebBody;
 import cn.reghao.autodop.dmaster.auth.service.ResourceService;
@@ -20,18 +19,17 @@ import java.util.Map;
 @Api(tags = "资源接口")
 @RequestMapping("/api/auth/menu")
 @RestController
-public class MenuController {
+public class ResourceController {
     private ResourceService resourceService;
 
-    public MenuController(ResourceService resourceService) {
+    public ResourceController(ResourceService resourceService) {
         this.resourceService = resourceService;
     }
 
     @ApiOperation(value = "添加/修改资源")
-    @PostMapping(value = "/save", produces = MediaType.APPLICATION_JSON_VALUE)
+    @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
     public String addMenu(@Validated Menu menu) {
-        Integer id = menu.getId();
-        if (id == null) {
+        if (menu.getId() == null) {
             // TODO menu 最多只能有两个 parent,即最多只能有三级菜单
             resourceService.addResource(menu);
         } else {
@@ -42,9 +40,11 @@ public class MenuController {
     }
 
     @ApiOperation(value = "修改资源状态")
-    @PostMapping(value = "/status/{status}", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String menuStatus(@PathVariable("status") String status,
-                             @RequestParam("ids") List<Integer> ids) {
+    @PostMapping(value = "/status/{isEnabled}", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String menuStatus(@PathVariable("isEnabled") boolean isEnabled, @RequestParam("ids") List<Integer> ids) {
+        if (isEnabled) {
+
+        }
         return WebBody.success();
     }
 
@@ -56,21 +56,21 @@ public class MenuController {
     }
 
     @ApiOperation(value = "获取所有的资源")
-    @GetMapping(value = "/list/{status}", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String list(@PathVariable(value = "status", required = false) String status) {
-        if (status == null) {
-            status = DataStatus.ENABLE.name();
+    @GetMapping(value = "/{isEnabled}", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String list(@PathVariable(value = "isEnabled", required = false) Boolean isEnabled) {
+        if (isEnabled == null) {
+            isEnabled = true;
         }
-        List<Menu> list = resourceService.getResourceByStatus(status);
+        List<Menu> list = resourceService.getResourceByStatus(isEnabled);
         return WebBody.success(list);
     }
 
-    @ApiOperation(value = "获取同一 pid 组内的资源位置")
-    @GetMapping(value = "/sortList/{pid}/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
+    @ApiOperation(value = "对同一 pid 组内的资源进行排序")
+    @GetMapping(value = "/sorted/{pid}/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
     public String sortList(@PathVariable(value = "pid") int pid,
                            @PathVariable(value = "id", required = false) Menu menu) {
         Map<Integer, String> map = resourceService.getMapByPid(pid);
-        // 排除正在编辑的 menu
+        // 排除当前 menu
         if (menu != null) {
             map.remove(menu.getPos());
         }

+ 27 - 13
dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/controller/MenuPageController.java → dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/controller/ResourcePageController.java

@@ -1,6 +1,6 @@
 package cn.reghao.autodop.dmaster.auth.controller;
 
-import cn.reghao.autodop.dmaster.auth.entity.DataStatus;
+import cn.reghao.autodop.dmaster.auth.db.query.RoleQuery;
 import cn.reghao.autodop.dmaster.auth.entity.po.Role;
 import cn.reghao.autodop.dmaster.auth.entity.po.Menu;
 import cn.reghao.autodop.dmaster.auth.service.ResourceService;
@@ -19,24 +19,27 @@ import java.util.*;
 @Api(tags = "资源页面")
 @RequestMapping("/auth/menu")
 @Controller
-public class MenuPageController {
+public class ResourcePageController {
+    private RoleQuery roleQuery;
     private ResourceService resourceService;
 
-    public MenuPageController(ResourceService resourceService) {
+    public ResourcePageController(RoleQuery roleQuery, ResourceService resourceService) {
+        this.roleQuery = roleQuery;
         this.resourceService = resourceService;
     }
 
-    @ApiOperation(value = "获取资源页面")
+    @ApiOperation(value = "资源列表页面")
     @GetMapping
-    public String systemMenu(@RequestParam(value = "status", required = false) String status, Model model) {
-        if (status == null) {
-            status = DataStatus.ENABLE.name();
+    public String menuPage(@RequestParam(value = "isEnabled", required = false) Boolean isEnabled, Model model) {
+        if (isEnabled == null) {
+            isEnabled = true;
         }
-        model.addAttribute("status", status);
+
+        model.addAttribute("isEnabled", isEnabled);
         return "/auth/menu/index";
     }
 
-    @ApiOperation(value = "获取资源添加页面")
+    @ApiOperation(value = "资源添加页面")
     @GetMapping({"/add", "/add/{pid}"})
     public String toAdd(@PathVariable(value = "pid", required = false) Integer pid, Model model) {
         // 父级菜单
@@ -44,11 +47,17 @@ public class MenuPageController {
         if (pid != null) {
             pMenu = resourceService.getResourceById(pid);
         }
+
+        Set<Role> allRoles = roleQuery.getAllRoles();
+        Set<Role> menuRoles = Collections.emptySet();
+
+        model.addAttribute("allRoles", allRoles);
+        model.addAttribute("menuRoles", menuRoles);
         model.addAttribute("pMenu", pMenu);
         return "/auth/menu/add";
     }
 
-    @ApiOperation(value = "获取资源编辑页面")
+    @ApiOperation(value = "资源编辑页面")
     @GetMapping("/edit/{id}")
     public String toEdit(@PathVariable("id") Menu menu, Model model) {
         int pid = menu.getPid();
@@ -59,21 +68,26 @@ public class MenuPageController {
             pMenu = resourceService.getResourceById(pid);
         }
 
+        Set<Role> allRoles = roleQuery.getAllRoles();
+        Set<Role> menuRoles = menu.getRoles();
+
+        model.addAttribute("allRoles", allRoles);
+        model.addAttribute("menuRoles", menuRoles);
         model.addAttribute("menu", menu);
         model.addAttribute("pMenu", pMenu);
         return "/auth/menu/add";
     }
 
     // TODO Hibernate 会根据传入的 id 自动查找相应的 Menu
-    @ApiOperation(value = "获取角色列表页面")
+    @ApiOperation(value = "可访问资源的角色列表页面")
     @GetMapping("/roleList/{id}")
     public String roleListWithResource(@PathVariable("id") Menu menu, Model model) {
         List<Role> list = new ArrayList<>(menu.getRoles());
         model.addAttribute("list", list);
-        return "/auth/menu/roleList";
+        return "/auth/menu/roles";
     }
 
-    @ApiOperation(value = "获取资源详细页面")
+    @ApiOperation(value = "资源详细信息页面")
     @GetMapping("/detail/{id}")
     public String toDetail(@PathVariable("id") Menu menu, Model model) {
         model.addAttribute("menu", menu);

+ 1 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/controller/RoleController.java

@@ -51,6 +51,7 @@ public class RoleController {
         List<Menu> allMenus = menuQuery.getAllMenus();
         allMenus.forEach(menu -> {
             if (menu.getRoles().contains(role)) {
+                // 对应前端的 checked 复选框
                 menu.setRemark("auth:true");
             }
         });

+ 8 - 7
dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/controller/UserPageController.java

@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
 
 import java.util.Collections;
 import java.util.List;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 /**
@@ -59,8 +60,8 @@ public class UserPageController {
     @ApiOperation(value = "新增用户页面")
     @GetMapping("/add")
     public String addUserPage(Model model) {
-        List<Role> allRoles = roleQuery.getAllRoles();
-        List<Role> userRoles = Collections.emptyList();
+        Set<Role> allRoles = roleQuery.getAllRoles();
+        Set<Role> userRoles = Collections.emptySet();
 
         model.addAttribute("allRoles", allRoles);
         model.addAttribute("userRoles", userRoles);
@@ -70,8 +71,8 @@ public class UserPageController {
     @ApiOperation(value = "用户信息编辑页面")
     @GetMapping("/edit/{id}")
     public String editUserPage(@PathVariable("id") User user, Model model) {
-        List<Role> allRoles = roleQuery.getAllRoles();
-        List<Role> userRoles = userQuery.getUserRoles(user);
+        Set<Role> allRoles = roleQuery.getAllRoles();
+        Set<Role> userRoles = userQuery.getUserRoles(user);
 
         model.addAttribute("allRoles", allRoles);
         model.addAttribute("userRoles", userRoles);
@@ -83,7 +84,7 @@ public class UserPageController {
     @GetMapping("/detail/{id}")
     public String userDetailPage(@PathVariable("id") int id, Model model) {
         User user = userQuery.getUserById(id);
-        List<Role> roles = userQuery.getUserRoles(user);
+        Set<Role> roles = userQuery.getUserRoles(user);
         List<String> names = roles.stream().map(Role::getName).collect(Collectors.toList());
 
         model.addAttribute("roles", names.toString());
@@ -101,9 +102,9 @@ public class UserPageController {
     @ApiOperation(value = "用户角色分配页面")
     @GetMapping("/role/{id}")
     public String assignRolePage(@PathVariable("id") User user, Model model) {
-        List<Role> roles = roleQuery.getAllRoles();
+        Set<Role> roles = roleQuery.getAllRoles();
         int userId = user.getId();
-        List<Role> authRoles = userQuery.getUserRoles(userId);
+        Set<Role> authRoles = userQuery.getUserRoles(userId);
 
         model.addAttribute("id", userId);
         model.addAttribute("list", roles);

+ 4 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/db/query/RoleQuery.java

@@ -13,7 +13,9 @@ import org.springframework.stereotype.Service;
 
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.SetJoin;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 /**
@@ -30,8 +32,8 @@ public class RoleQuery {
         this.userRepository = userRepository;
     }
 
-    public List<Role> getAllRoles() {
-        return roleRepository.findAll();
+    public Set<Role> getAllRoles() {
+        return new HashSet<>(roleRepository.findAll());
     }
 
     public Page<RoleVO> getRoleVOByPage(PageRequest pageRequest) {

+ 5 - 8
dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/db/query/UserQuery.java

@@ -12,10 +12,7 @@ import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 
 import javax.persistence.criteria.Predicate;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -45,19 +42,19 @@ public class UserQuery {
         return userRepository.findAll(specification).stream().map(UserVO::new).collect(Collectors.toList());
     }
 
-    public List<Role> getUserRoles(User user) {
+    public Set<Role> getUserRoles(User user) {
         Set<GrantedAuthorityImpl> set = user.getAuthoritiesSet();
         List<String> roles = set.stream()
                 .map(GrantedAuthorityImpl::getAuthority)
                 .collect(Collectors.toList());
         Specification<Role> spec = ((root, query, criteriaBuilder) -> root.get("title").in(roles));
-        return roleRepository.findAll(spec);
+        return new HashSet<>(roleRepository.findAll(spec));
     }
 
-    public List<Role> getUserRoles(Integer userId) {
+    public Set<Role> getUserRoles(Integer userId) {
         User user = getUserById(userId);
         if (user == null) {
-            return Collections.emptyList();
+            return Collections.emptySet();
         }
 
         return getUserRoles(user);

+ 9 - 8
dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/entity/po/Menu.java

@@ -23,31 +23,32 @@ import java.util.*;
 @ToString(exclude = {"roles"})
 @Entity
 public class Menu extends BaseEntity<Integer> {
-    // 父 menu id
+    // 父级菜单 ID
     @NotNull(message = "父级菜单不能为 NULL")
     private Integer pid;
     // 在同一个 pid 组内的位置,作为排序使用
     private Integer pos;
-    @NotBlank(message = "标题不能为空白字符串")
-    private String title;
-    @NotBlank(message = "url地址不能为空白字符串,可以输入#代替")
+    @NotBlank(message = "菜单名不能为空白字符串")
+    private String name;
+    @NotBlank(message = "URL 地址不能为空白字符串,目录类型使用可使用 # 字符")
     private String url;
     // Menu 类型
-    @NotNull(message = "菜单类型不能为 NULL")
+    @NotBlank(message = "菜单类型不能为空白字符串")
     private String type;
     private String icon;
     private String remark;
-    private String status;
+    private Boolean isEnabled;
     // 可访问资源的角色,一个资源可被多个角色访问
     @ManyToMany(mappedBy = "menus")
+    @NotNull(message = "角色不能为 NULL")
     private Set<Role> roles;
     // Menu 拥有的所有子 Menu(按排序顺序)
     // 不持久化
     @Transient
     private Map<Integer, Menu> children = new HashMap<>();
 
-    public Menu(int id, String title) {
+    public Menu(int id, String name) {
         this.id = id;
-        this.title = title;
+        this.name = name;
     }
 }

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/repository/MenuRepository.java

@@ -11,5 +11,5 @@ import java.util.List;
  */
 public interface MenuRepository extends JpaRepository<Menu, Integer> {
     List<Menu> findByPid(int pid);
-    List<Menu> findByStatus(String status);
+    List<Menu> findByIsEnabled(boolean isEnabled);
 }

+ 8 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/service/MenuService.java

@@ -0,0 +1,8 @@
+package cn.reghao.autodop.dmaster.auth.service;
+
+/**
+ * @author reghao
+ * @date 2021-07-14 20:39:55
+ */
+public interface MenuService {
+}

+ 20 - 6
dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/service/ResourceService.java

@@ -1,10 +1,10 @@
 package cn.reghao.autodop.dmaster.auth.service;
 
-import cn.reghao.autodop.dmaster.auth.entity.DataStatus;
 import cn.reghao.autodop.dmaster.auth.entity.po.Menu;
 import cn.reghao.autodop.dmaster.auth.entity.po.Role;
 import cn.reghao.autodop.dmaster.auth.repository.MenuRepository;
 import cn.reghao.autodop.dmaster.auth.repository.RoleRepository;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
@@ -15,6 +15,7 @@ import java.util.stream.Collectors;
  * @author reghao
  * @date 2021-05-17 17:16:19
  */
+@Slf4j
 @Service
 public class ResourceService {
     private final MenuRepository menuRepository;
@@ -26,12 +27,25 @@ public class ResourceService {
     }
 
     public void addResource(Menu menu) {
-        menu.setStatus(DataStatus.ENABLE.name());
         int pid = menu.getPid();
+        /*if (pid != 0) {
+            Menu menu1 = getResourceById(pid);
+            int pid1 = menu1.getPid();
+            if (pid1 != 0) {
+                Menu menu2 = getResourceById(pid1);
+                int pid2 = menu2.getPid();
+                if (pid2 != 0) {
+                    log.error("menu 最多只能有两个 parent,即最多只能有三级菜单...");
+                    return;
+                }
+            }
+        }*/
+
+        menu.setIsEnabled(true);
         int pos = menu.getPos()+1;
         if (adjustPosition(pid, pos)) {
             menu.setPos(pos);
-            menuRepository.save(menu);
+            //menuRepository.save(menu);
         }
     }
 
@@ -166,8 +180,8 @@ public class ResourceService {
         menuRepository.delete(menu);
     }
 
-    public List<Menu> getResourceByStatus(String status) {
-        List<Menu> menuList = menuRepository.findByStatus(status);
+    public List<Menu> getResourceByStatus(Boolean isEnabled) {
+        List<Menu> menuList = menuRepository.findByIsEnabled(isEnabled);
         Map<Integer, List<Menu>> map =  menuList.stream().collect(Collectors.groupingBy(Menu::getPid));
         List<Menu> list = new ArrayList<>();
         map.forEach((pid, menus) -> {
@@ -184,7 +198,7 @@ public class ResourceService {
         List<Menu> menus = menuRepository.findByPid(pid);
         Map<Integer, String> map = new HashMap<>();
         menus.forEach(menu -> {
-            map.put(menu.getPos(), menu.getTitle());
+            map.put(menu.getPos(), menu.getName());
         });
         return map;
     }

+ 5 - 5
dmaster/src/main/java/cn/reghao/autodop/dmaster/sys/controller/TestController.java

@@ -74,7 +74,7 @@ public class TestController {
         Menu homeMenu = new Menu();
         homeMenu.setPid(0);
         homeMenu.setPos(1);
-        homeMenu.setTitle("主页");
+        homeMenu.setName("主页");
         homeMenu.setUrl("/home");
         homeMenu.setType(MenuType.PAGE.name());
         homeMenu.setIcon("layui-icon layui-icon-home");
@@ -83,7 +83,7 @@ public class TestController {
         Menu sysMenu = new Menu();
         sysMenu.setPid(0);
         sysMenu.setPos(2);
-        sysMenu.setTitle("系统管理");
+        sysMenu.setName("系统管理");
         sysMenu.setUrl("#");
         sysMenu.setType(MenuType.DIR.name());
         sysMenu.setIcon("fa fa-cog");
@@ -94,7 +94,7 @@ public class TestController {
         Menu userMenu = new Menu();
         userMenu.setPid(sysMenu.getId());
         userMenu.setPos(1);
-        userMenu.setTitle("用户管理");
+        userMenu.setName("用户管理");
         userMenu.setUrl("/system/user");
         userMenu.setType(MenuType.PAGE.name());
         userMenu.setIcon("fa fa-cog");
@@ -103,7 +103,7 @@ public class TestController {
         Menu roleMenu = new Menu();
         roleMenu.setPid(sysMenu.getId());
         roleMenu.setPos(2);
-        roleMenu.setTitle("角色管理");
+        roleMenu.setName("角色管理");
         roleMenu.setUrl("/system/role");
         roleMenu.setType(MenuType.PAGE.name());
         roleMenu.setIcon("fa fa-cog");
@@ -112,7 +112,7 @@ public class TestController {
         Menu resourceMenu = new Menu();
         resourceMenu.setPid(sysMenu.getId());
         resourceMenu.setPos(3);
-        resourceMenu.setTitle("资源管理");
+        resourceMenu.setName("资源管理");
         resourceMenu.setUrl("/system/user/menu");
         resourceMenu.setType(MenuType.PAGE.name());
         resourceMenu.setIcon("fa fa-cog");

+ 6 - 6
dmaster/src/main/java/cn/reghao/autodop/dmaster/view/thymeleaf/attribute/SelectDictAttrProcessor.java

@@ -18,11 +18,11 @@ import java.util.*;
  * @date 2018/8/14
  */
 public class SelectDictAttrProcessor extends AbstractAttributeTagProcessor {
-    private final static Map<String, Map<String, String>> localCache = new HashMap<>();
+    private final static Map<String, Map<String, Object>> localCache = new HashMap<>();
     static {
-        localCache.put("SEARCH_STATUS", new HashMap<>());
-        localCache.get("SEARCH_STATUS").put("ENABLE", "ENABLE");
-        localCache.get("SEARCH_STATUS").put("DISABLE", "DISABLE");
+        localCache.put("MENU_STATUS", new HashMap<>());
+        localCache.get("MENU_STATUS").put("ENABLE", true);
+        localCache.get("MENU_STATUS").put("DISABLE", false);
 
         localCache.put("MENU_TYPE", new HashMap<>());
         localCache.get("MENU_TYPE").put("DIR", "DIR");
@@ -64,7 +64,7 @@ public class SelectDictAttrProcessor extends AbstractAttributeTagProcessor {
         }
 
         // 获取列表对象,空则不处理
-        Map<String, String> valueList = localCache.get(attributeValue);
+        Map<String, Object> valueList = localCache.get(attributeValue);
         if(valueList != null && valueList.size() > 0) {
             doProcess(context, tag, structureHandler, valueList);
         }
@@ -74,7 +74,7 @@ public class SelectDictAttrProcessor extends AbstractAttributeTagProcessor {
             final ITemplateContext context,
             final IProcessableElementTag tag,
             final IElementTagStructureHandler structureHandler,
-            Map<String, String> valueList) {
+            Map<String, Object> valueList) {
 
         // 获取默认选中值
         String attributeSelectedValue = tag.getAttributeValue(SELECTED_ATTR_NAME);

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/view/thymeleaf/attribute/SelectListAttrProcessor.java

@@ -59,7 +59,7 @@ public class SelectListAttrProcessor extends SelectDictAttrProcessor {
         }
 
         // 转换列表对象
-        Map<String, String> valueList = new LinkedHashMap<>();
+        Map<String, Object> valueList = new LinkedHashMap<>();
         if(expressionResult.getClass().isArray()){
             // 转换数组
             int length = Array.getLength(expressionResult);

+ 5 - 5
dmaster/src/main/resources/static/js/timoTree.js

@@ -118,9 +118,9 @@
                 var nav = {
                     id: val.id,
                     pId: val.pid,
-                    name: val.title
+                    name: val.name
                 };
-                if(nav.pId == 0){
+                if(nav.pId === 0){
                     nav.isParent = true;
                     nav.open = true;
                 }
@@ -166,7 +166,7 @@
             self.expandTree(treeList, rank, function (item, rank) {
                 var callback = template.replace(regex,function($1){
                     var point = $1.substring(2,$1.length-2);
-                    if(point == "title"){
+                    if(point == "name"){
                         var icon = self.options.treeIcon;
                         if(item.children == undefined){
                             icon = self.options.treeFill;
@@ -296,9 +296,9 @@
                 var nav = {
                     id: val.id,
                     pId: val.pid,
-                    name: val.title
+                    name: val.name
                 };
-                if(nav.pId == 0){
+                if(nav.pId === 0){
                     nav.isParent = true;
                     nav.open = true;
                 }

+ 13 - 6
dmaster/src/main/resources/templates/auth/menu/add.html

@@ -6,17 +6,17 @@
 </head>
 <body>
 <div class="layui-form timo-compile">
-    <form th:action="@{/auth/menu/save}">
+    <form th:action="@{/api/auth/menu}">
         <input type="hidden" name="id" th:if="${menu}" th:value="${menu.id}"/>
         <input type="hidden" name="isDelete" th:if="${menu}" th:value="${menu.isDelete}"/>
         <input type="hidden" name="createTime" th:if="${menu}" th:value="${menu.createTime}"/>
         <input type="hidden" name="updateTime" th:if="${menu}" th:value="${menu.updateTime}"/>
-        <input type="hidden" name="status" th:if="${menu}" th:value="${menu.status}"/>
+        <input type="hidden" name="isEnabled" th:if="${menu}" th:value="${menu.isEnabled}"/>
         <div class="layui-form-item">
             <label class="layui-form-label required">标题</label>
             <div class="layui-input-inline">
                 <label>
-                    <input class="layui-input" type="text" name="title"  placeholder="请输入标题" th:value="${menu?.title}">
+                    <input class="layui-input" type="text" name="name"  placeholder="请输入标题" th:value="${menu?.name}">
                 </label>
             </div>
         </div>
@@ -41,7 +41,7 @@
             <label class="layui-form-label required">父级菜单</label>
             <div class="layui-input-inline">
                 <label>
-                    <input class="layui-input select-tree" th:attr="data-url=@{/auth/menu/list/enable}, data-value=${pMenu?.id}" type="text" name="pid"  placeholder="请输入父级菜单(必须是目录类型)" th:value="${pMenu?.title}">
+                    <input class="layui-input select-tree" th:attr="data-url=@{/api/auth/menu/1}, data-value=${pMenu?.id}" type="text" name="pid"  placeholder="请选择父级菜单(必须是目录类型)" th:value="${pMenu?.name}">
                 </label>
             </div>
         </div>
@@ -57,8 +57,8 @@
             <label class="layui-form-label">排序</label>
             <div class="layui-input-inline">
                 <label>
-                    <select class="select-pos" name="pos"
-                            th:attr="data-url=@{/auth/menu/sortList}, data-id=${menu?.id}, data-pos=${menu?.pos}" lay-verify="pos"></select>
+                    <select class="select-pos" name="pos" lay-verify="pos"
+                            th:attr="data-url=@{/api/auth/menu/sorted}, data-id=${menu?.id}, data-pos=${menu?.pos}"></select>
                 </label>
             </div>
             <div class="layui-input-info">(之后)</div>
@@ -71,6 +71,13 @@
                 </label>
             </div>
         </div>
+        <div class="layui-form-item">
+            <label class="layui-form-label required">分配角色</label>
+            <div class="layui-input-block">
+                <input th:each="item:${allRoles}" type="checkbox" name="roles" th:title="${item.name}"
+                       th:value="${item.id}" th:checked="${#sets.contains(menuRoles, item)}" lay-skin="primary">
+            </div>
+        </div>
         <div class="layui-form-item timo-finally">
             <button class="layui-btn ajax-submit"><i class="fa fa-check-circle"></i> 保存</button>
             <button class="layui-btn btn-secondary close-popup"><i class="fa fa-times-circle"></i> 关闭</button>

+ 4 - 5
dmaster/src/main/resources/templates/auth/menu/detail.html

@@ -1,6 +1,5 @@
 <!DOCTYPE html>
-<html xmlns:th="http://www.thymeleaf.org"
-      xmlns:mo="https://gitee.com/aun/Timo">
+<html xmlns:th="http://www.thymeleaf.org">
 <head th:replace="/common/template :: header(~{::title},~{::link},~{::style})">
 </head>
 <body>
@@ -9,10 +8,10 @@
         <table class="layui-table timo-detail-table">
             <tbody>
             <tr>
-                <th width='100px'>菜单编号</th>
+                <th width='100px'>菜单 ID</th>
                 <td th:text="${menu.id}"></td>
-                <th width='100px'>菜单标题</th>
-                <td th:text="${menu.title}"></td>
+                <th width='100px'>菜单</th>
+                <td th:text="${menu.name}"></td>
             </tr>
             <tr>
                 <th width='100px'>图标</th>

+ 10 - 11
dmaster/src/main/resources/templates/auth/menu/index.html

@@ -5,7 +5,7 @@
         <link rel="stylesheet" th:href="@{/lib/zTree_v3/css/zTreeStyle/zTreeStyle.css}" type="text/css">
     </head>
     <body class="timo-layout-page">
-        <div class="layui-card timo-tree" th:attr="data-url=@{'/api/auth/menu/list/' + ${status}}">
+        <div class="layui-card timo-tree" th:attr="data-url=@{'/api/auth/menu/' + ${isEnabled}}">
             <div class="layui-card-header timo-card-header">
                 <span>
                     <i class="fa fa-bars"></i>
@@ -16,7 +16,7 @@
             <div class="layui-card-body layui-row">
                 <div class="layui-col-lg2 layui-col-sm3">
                     <div class="layui-card timo-nav-tree">
-                        <div class="layui-card-header">资源结构</div>
+                        <div class="layui-card-header">资源目录树</div>
                         <div class="layui-card-body">
                             <ul class="ztree"></ul>
                         </div>
@@ -28,8 +28,8 @@
                             <div class="layui-inline">
                                 <label class="layui-form-label">状态</label>
                                 <div class="layui-input-block timo-search-status">
-                                    <select id="getByStatus" class="timo-search-select" name="status" onchange="getListByStatus()"
-                                            mo:dict="SEARCH_STATUS" mo-selected="${status}"></select>
+                                    <select id="getByStatus" class="timo-search-select" name="isEnabled" onchange="getListByStatus()"
+                                            mo:dict="MENU_STATUS" mo-selected="${isEnabled}"></select>
                                 </div>
                             </div>
                         </div>
@@ -45,10 +45,10 @@
                                 </button>
                                 <dl class="layui-nav-child layui-anim layui-anim-upbit">
                                     <dd>
-                                        <a class="ajax-status" th:href="@{/auth/menu/status/enable}">启用</a>
+                                        <a class="ajax-status" th:href="@{/auth/menu/status/1}">启用</a>
                                     </dd>
                                     <dd>
-                                        <a class="ajax-status" th:href="@{/auth/menu/status/disable}">停用</a>
+                                        <a class="ajax-status" th:href="@{/auth/menu/status/0}">停用</a>
                                     </dd>
                                 </dl>
                             </div>
@@ -67,7 +67,7 @@
                                     <th>名称</th>
                                     <th>URL 地址</th>
                                     <th>资源类型</th>
-                                    <th>已授权的角色</th>
+                                    <th>可访问的角色</th>
                                     <th>操作</th>
                                 </tr>
                             </thead>
@@ -79,11 +79,11 @@
                                             <i class="layui-icon layui-icon-ok"></i>
                                         </label>
                                     </td>
-                                    <td>{{title}}</td>
+                                    <td>{{name}}</td>
                                     <td>{{url}}</td>
                                     <td>{{type}}</td>
                                     <td>
-                                        <a class="open-popup" data-title="角色列表"
+                                        <a class="open-popup" data-title="已授予的角色"
                                            th:attr="data-url=@{'/auth/menu/roleList/{{id}}'}" data-size="800,600"
                                            href="#">查看</a>
                                     </td>
@@ -113,11 +113,10 @@
         <script type="text/javascript" th:src="@{/js/timoTree.js}"></script>
         <script type="text/javascript">
             $.fn.timoTree();
-
             function getListByStatus() {
                 var selectedOption = $("#getByStatus option:selected")
                 var param = selectedOption.text()
-                url = '?status=' + param
+                url = '?isEnabled=' + param
                 window.location.href = window.location.pathname + url;
             }
         </script>

+ 0 - 0
dmaster/src/main/resources/templates/auth/menu/roleList.html → dmaster/src/main/resources/templates/auth/menu/roles.html


+ 3 - 3
dmaster/src/main/resources/templates/main.html

@@ -63,19 +63,19 @@
                 <li class="layui-nav-item" th:each="item:${treeMenu}">
                     <a href="javascript:" th:attr="lay-url=${item.value.url}">
                         <i th:class="${item.value.icon}"></i>
-                        <span class="layui-nav-title" th:text="${item.value.title}">一级菜单</span>
+                        <span class="layui-nav-title" th:text="${item.value.name}">一级菜单</span>
                     </a>
                     <dl class="layui-nav-child" th:if="${item.value.children.size()}">
                         <dd th:each="secondItem:${item.value.children}">
                             <a href="javascript:" th:attr="lay-url=${secondItem.value.url}">
                                 <i th:class="${secondItem.value.icon}"></i>
-                                <span class="layui-nav-title" th:text="${secondItem.value.title}">二级菜单</span>
+                                <span class="layui-nav-title" th:text="${secondItem.value.name}">二级菜单</span>
                             </a>
                             <dl class="layui-nav-child" th:if="${secondItem.value.children.size()}">
                                 <dd th:each="thirdItem:${secondItem.value.children}">
                                     <a href="javascript:" th:attr="lay-url=${thirdItem.value.url}">
                                         <i th:class="${thirdItem.value.icon}"></i>
-                                        <span class="layui-nav-title" th:text="${thirdItem.value.title}">三级菜单</span>
+                                        <span class="layui-nav-title" th:text="${thirdItem.value.name}">三级菜单</span>
                                     </a>
                                 </dd>
                             </dl>