From 9f0df886baa8a87283db97c550b9a03a769668af Mon Sep 17 00:00:00 2001 From: wangziyangyang <707231019@qq.com> Date: Wed, 25 Mar 2020 17:23:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=90=9C=E7=B4=A2=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/SysLoginController.java | 23 ++++++++-- .../mes/system/mapper/SysMenuMapper.java | 25 ++++++---- .../mes/system/service/ISysMenuService.java | 10 ++++ .../service/impl/SysMenuServiceImpl.java | 46 ++++++++++++++++--- .../resources/mapper/system/SysMenuMapper.xml | 18 ++++++++ .../static/js/layuimodule/sp/spLayui.js | 13 ++++-- .../main/resources/templates/admin/index.ftl | 28 +++++++++-- 7 files changed, 138 insertions(+), 25 deletions(-) diff --git a/mes/src/main/java/com/wangziyang/mes/system/controller/admin/SysLoginController.java b/mes/src/main/java/com/wangziyang/mes/system/controller/admin/SysLoginController.java index 23f7312..575b7a1 100644 --- a/mes/src/main/java/com/wangziyang/mes/system/controller/admin/SysLoginController.java +++ b/mes/src/main/java/com/wangziyang/mes/system/controller/admin/SysLoginController.java @@ -9,9 +9,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.*; import java.util.Map; @@ -56,6 +54,11 @@ public class SysLoginController extends BaseController { return "admin/welcome"; } + /** + * 系统首页初始化菜单树数据 + * @return 菜单树数据 + * @throws Exception 异常 + */ @ApiOperation("系统首页初始化菜单树数据") @GetMapping("/list/index/menu/tree") @ResponseBody @@ -64,4 +67,18 @@ public class SysLoginController extends BaseController { return Result.success(result); } + /** + * 用户搜索系统首页初始化菜单树数据 + * @param menuName 菜单名字 + * @return 菜单树数据 + * @throws Exception 异常 + */ + @ApiOperation("系统首页初始化菜单树数据") + @GetMapping("/list/index/menu/search/tree/{menuName}") + @ResponseBody + public Result searchTree(@PathVariable String menuName) throws Exception { + Map result = sysMenuService.listIndexMenuSearchTree(menuName); + return Result.success(result); + } + } diff --git a/mes/src/main/java/com/wangziyang/mes/system/mapper/SysMenuMapper.java b/mes/src/main/java/com/wangziyang/mes/system/mapper/SysMenuMapper.java index e900981..1db2e67 100644 --- a/mes/src/main/java/com/wangziyang/mes/system/mapper/SysMenuMapper.java +++ b/mes/src/main/java/com/wangziyang/mes/system/mapper/SysMenuMapper.java @@ -16,12 +16,21 @@ import java.util.List; */ public interface SysMenuMapper extends BaseMapper { - /** - * 根据角色id查询菜单列表 - * - * @param roleId - * @return - * @throws Exception - */ - List listByRoleId(String roleId) throws Exception; + /** + * 根据角色id查询菜单列表 + * + * @param roleId + * @return + * @throws Exception + */ + List listByRoleId(String roleId) throws Exception; + + /** + * 根据用户输入的菜单名称 模糊匹配 + * + * @param menuName 菜单名称 + * @return 用户结果 + * @throws Exception 异常 + */ + List listBySearchByName(String menuName) throws Exception; } diff --git a/mes/src/main/java/com/wangziyang/mes/system/service/ISysMenuService.java b/mes/src/main/java/com/wangziyang/mes/system/service/ISysMenuService.java index e327411..45fb12a 100644 --- a/mes/src/main/java/com/wangziyang/mes/system/service/ISysMenuService.java +++ b/mes/src/main/java/com/wangziyang/mes/system/service/ISysMenuService.java @@ -36,6 +36,16 @@ public interface ISysMenuService extends IService { */ Map listIndexMenuTree() throws Exception; + + /** + * 用户搜索系统首页初始化菜单树数据 + * + * @return 系统首页初始化菜单树数据 + * @throws Exception 异常 + */ + Map listIndexMenuSearchTree(String menuName) throws Exception; + + /** * 获取系统菜单树 * diff --git a/mes/src/main/java/com/wangziyang/mes/system/service/impl/SysMenuServiceImpl.java b/mes/src/main/java/com/wangziyang/mes/system/service/impl/SysMenuServiceImpl.java index 1f1a7bb..32c9ef3 100644 --- a/mes/src/main/java/com/wangziyang/mes/system/service/impl/SysMenuServiceImpl.java +++ b/mes/src/main/java/com/wangziyang/mes/system/service/impl/SysMenuServiceImpl.java @@ -48,8 +48,8 @@ public class SysMenuServiceImpl extends ServiceImpl impl @Override public Map listIndexMenuTree() throws Exception { Map result = new LinkedHashMap<>(4); - QueryWrapper queryWrapper =new QueryWrapper(); - queryWrapper.orderBy(true,true,"sort_num"); + QueryWrapper queryWrapper = new QueryWrapper(); + queryWrapper.orderBy(true, true, "sort_num"); List sysMenus = sysMenuMapper.selectList(queryWrapper); Map clearInfo = new HashMap<>(2); @@ -60,10 +60,10 @@ public class SysMenuServiceImpl extends ServiceImpl impl homeInfo.put("icon", "fa fa-home"); homeInfo.put("url", "admin/welcome-ui"); - Map logoInfo = new HashMap<>(4); - logoInfo.put("name", "黑科制造MES"); - logoInfo.put("image", "image/logo.png"); - logoInfo.put("url", ""); + Map logoInfo = new HashMap<>(4); + logoInfo.put("name", "黑科制造MES"); + logoInfo.put("image", "image/logo.png"); + logoInfo.put("url", ""); Map menuInfo = new LinkedHashMap<>(8); @@ -95,6 +95,40 @@ public class SysMenuServiceImpl extends ServiceImpl impl return result; } + /** + * 用户搜索系统首页初始化菜单树数据 + * @param menuName 菜单名字 + * @return 菜单树数据 + * @throws Exception 异常 + */ + @Override + public Map listIndexMenuSearchTree(String menuName) throws Exception { + Map result = new LinkedHashMap<>(4); + Map menuInfo = new LinkedHashMap<>(8); + List sysMenus = sysMenuMapper.listBySearchByName(menuName); + List> menus = new ArrayList<>(); + for (SysMenu m : sysMenus) { + TreeVO tree = new TreeVO<>(); + tree.setId(m.getId()); + tree.setPid(m.getParentId()); + tree.setCode(m.getCode()); + tree.setName(m.getName()); + tree.setUrl(m.getUrl()); + tree.setIcon(m.getIcon()); + tree.setType(m.getType()); + tree.setPermission(m.getPermission()); + // TODO 是否需要更改? + tree.setTarget("_self"); + menus.add(tree); + } + List> treeVOS = TreeUtil.buildList(menus, "0"); + for (TreeVO mTree : treeVOS) { + menuInfo.put(mTree.getCode(), mTree); + } + result.put("menuInfo", menuInfo); + return result; + } + /** * 获取系统菜单树 * diff --git a/mes/src/main/resources/mapper/system/SysMenuMapper.xml b/mes/src/main/resources/mapper/system/SysMenuMapper.xml index 44632d3..83d1c02 100644 --- a/mes/src/main/resources/mapper/system/SysMenuMapper.xml +++ b/mes/src/main/resources/mapper/system/SysMenuMapper.xml @@ -28,4 +28,22 @@ ON ssrm.role_id = #{roleId} WHERE t.id = ssrm.menu_id + + + diff --git a/mes/src/main/resources/static/js/layuimodule/sp/spLayui.js b/mes/src/main/resources/static/js/layuimodule/sp/spLayui.js index 21ab826..a8b9f0c 100644 --- a/mes/src/main/resources/static/js/layuimodule/sp/spLayui.js +++ b/mes/src/main/resources/static/js/layuimodule/sp/spLayui.js @@ -49,7 +49,7 @@ layui.define(["element", "jquery"], function (exports) { spLayui.initHome(data.data.homeInfo); spLayui.initLogo(data.data.logoInfo); spLayui.initClear(data.data.clearInfo); - spLayui.initMenu(data.data.menuInfo); + spLayui.initMenu(data.data.menuInfo,false); spLayui.initTab(); } }).fail(function () { @@ -124,7 +124,7 @@ layui.define(["element", "jquery"], function (exports) { * 初始化菜单栏 * @param data */ - this.initMenu = function (data) { + this.initMenu = function (data,booleanNav) { var headerMenuHtml = '', headerMobileMenuHtml = '', leftMenuHtml = '', @@ -137,7 +137,14 @@ layui.define(["element", "jquery"], function (exports) { leftMenuHtml += '
    \n'; var menuList = val.children; $.each(menuList, function (index, menu) { - leftMenuHtml += '
  • \n'; + if (booleanNav) + { + leftMenuHtml += '
  • \n'; + } + else + { + leftMenuHtml += '
  • \n'; + } if (menu.children && menu.children.length > 0) { leftMenuHtml += ' ' + menu.name + ' '; var buildChildHtml = function (html, children, menuParameId) { diff --git a/mes/src/main/resources/templates/admin/index.ftl b/mes/src/main/resources/templates/admin/index.ftl index 3b227a9..cc4226c 100644 --- a/mes/src/main/resources/templates/admin/index.ftl +++ b/mes/src/main/resources/templates/admin/index.ftl @@ -73,7 +73,7 @@
    + autocomplete="off">
    @@ -112,10 +112,28 @@ spLayui.init('${request.contextPath}/admin/list/index/menu/tree'); form.on('submit(js-search-filter)', function (data) { - console.log(data.elem) //被执行事件的元素DOM对象,一般为button对象 - console.log(data.form) //被执行提交的form对象,一般在存在form标签时才会返回 - console.log(data.field) //当前容器的全部表单字段,名值对形式:{name: value} - // 阻止表单跳转。如果需要表单跳转,去掉这段即可。 + + if (data.field.search) { + var urlPath = '${request.contextPath}/admin/list/index/menu/search/tree/' + data.field.search; + itemNav =true; + } else { + var urlPath = '${request.contextPath}/admin/list/index/menu/tree'; + itemNav =false; + } + spUtil.ajax({ + url: urlPath, + async: false, + type: 'GET', + // 是否显示 loading + // showLoading: true, + // 是否序列化参数 + serializable: false, + // 参数 + data: {}, + success: function (data) { + spLayui.initMenu(data.data.menuInfo,itemNav); + } + }); return false; }); });