增加搜索菜单功能

pull/1/head
wangziyangyang 2020-03-25 17:23:16 +08:00
parent b9a7f297a1
commit 9f0df886ba
7 changed files with 138 additions and 25 deletions

View File

@ -9,9 +9,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map; import java.util.Map;
@ -56,6 +54,11 @@ public class SysLoginController extends BaseController {
return "admin/welcome"; return "admin/welcome";
} }
/**
*
* @return
* @throws Exception
*/
@ApiOperation("系统首页初始化菜单树数据") @ApiOperation("系统首页初始化菜单树数据")
@GetMapping("/list/index/menu/tree") @GetMapping("/list/index/menu/tree")
@ResponseBody @ResponseBody
@ -64,4 +67,18 @@ public class SysLoginController extends BaseController {
return Result.success(result); 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<String, Object> result = sysMenuService.listIndexMenuSearchTree(menuName);
return Result.success(result);
}
} }

View File

@ -16,12 +16,21 @@ import java.util.List;
*/ */
public interface SysMenuMapper extends BaseMapper<SysMenu> { public interface SysMenuMapper extends BaseMapper<SysMenu> {
/** /**
* id * id
* *
* @param roleId * @param roleId
* @return * @return
* @throws Exception * @throws Exception
*/ */
List<SysMenuDTO> listByRoleId(String roleId) throws Exception; List<SysMenuDTO> listByRoleId(String roleId) throws Exception;
/**
*
*
* @param menuName
* @return
* @throws Exception
*/
List<SysMenu> listBySearchByName(String menuName) throws Exception;
} }

View File

@ -36,6 +36,16 @@ public interface ISysMenuService extends IService<SysMenu> {
*/ */
Map<String, Object> listIndexMenuTree() throws Exception; Map<String, Object> listIndexMenuTree() throws Exception;
/**
*
*
* @return
* @throws Exception
*/
Map<String, Object> listIndexMenuSearchTree(String menuName) throws Exception;
/** /**
* *
* *

View File

@ -48,8 +48,8 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
@Override @Override
public Map<String, Object> listIndexMenuTree() throws Exception { public Map<String, Object> listIndexMenuTree() throws Exception {
Map<String, Object> result = new LinkedHashMap<>(4); Map<String, Object> result = new LinkedHashMap<>(4);
QueryWrapper queryWrapper =new QueryWrapper(); QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.orderBy(true,true,"sort_num"); queryWrapper.orderBy(true, true, "sort_num");
List<SysMenu> sysMenus = sysMenuMapper.selectList(queryWrapper); List<SysMenu> sysMenus = sysMenuMapper.selectList(queryWrapper);
Map<String, String> clearInfo = new HashMap<>(2); Map<String, String> clearInfo = new HashMap<>(2);
@ -60,10 +60,10 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
homeInfo.put("icon", "fa fa-home"); homeInfo.put("icon", "fa fa-home");
homeInfo.put("url", "admin/welcome-ui"); homeInfo.put("url", "admin/welcome-ui");
Map<String, String> logoInfo = new HashMap<>(4); Map<String, String> logoInfo = new HashMap<>(4);
logoInfo.put("name", "黑科制造MES"); logoInfo.put("name", "黑科制造MES");
logoInfo.put("image", "image/logo.png"); logoInfo.put("image", "image/logo.png");
logoInfo.put("url", ""); logoInfo.put("url", "");
Map<String, Object> menuInfo = new LinkedHashMap<>(8); Map<String, Object> menuInfo = new LinkedHashMap<>(8);
@ -95,6 +95,40 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
return result; return result;
} }
/**
*
* @param menuName
* @return
* @throws Exception
*/
@Override
public Map<String, Object> listIndexMenuSearchTree(String menuName) throws Exception {
Map<String, Object> result = new LinkedHashMap<>(4);
Map<String, Object> menuInfo = new LinkedHashMap<>(8);
List<SysMenu> sysMenus = sysMenuMapper.listBySearchByName(menuName);
List<TreeVO<SysMenu>> menus = new ArrayList<>();
for (SysMenu m : sysMenus) {
TreeVO<SysMenu> 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<TreeVO<SysMenu>> treeVOS = TreeUtil.buildList(menus, "0");
for (TreeVO<SysMenu> mTree : treeVOS) {
menuInfo.put(mTree.getCode(), mTree);
}
result.put("menuInfo", menuInfo);
return result;
}
/** /**
* *
* *

View File

@ -28,4 +28,22 @@
ON ssrm.role_id = #{roleId} ON ssrm.role_id = #{roleId}
WHERE t.id = ssrm.menu_id WHERE t.id = ssrm.menu_id
</select> </select>
<!--根据输入菜单模糊匹配-->
<select id="listBySearchByName" parameterType="java.lang.String" resultMap="resultMap">
SELECT * FROM
(
SELECT * FROM sp_sys_menu
<where>
name LIKE CONCAT(CONCAT('%', #{menuName}), '%')
</where>
UNION
SELECT *
FROM sp_sys_menu
<where>
grade !='3'
</where>
) A
order by A.grade, A.sort_num
</select>
</mapper> </mapper>

View File

@ -49,7 +49,7 @@ layui.define(["element", "jquery"], function (exports) {
spLayui.initHome(data.data.homeInfo); spLayui.initHome(data.data.homeInfo);
spLayui.initLogo(data.data.logoInfo); spLayui.initLogo(data.data.logoInfo);
spLayui.initClear(data.data.clearInfo); spLayui.initClear(data.data.clearInfo);
spLayui.initMenu(data.data.menuInfo); spLayui.initMenu(data.data.menuInfo,false);
spLayui.initTab(); spLayui.initTab();
} }
}).fail(function () { }).fail(function () {
@ -124,7 +124,7 @@ layui.define(["element", "jquery"], function (exports) {
* 初始化菜单栏 * 初始化菜单栏
* @param data * @param data
*/ */
this.initMenu = function (data) { this.initMenu = function (data,booleanNav) {
var headerMenuHtml = '', var headerMenuHtml = '',
headerMobileMenuHtml = '', headerMobileMenuHtml = '',
leftMenuHtml = '', leftMenuHtml = '',
@ -137,7 +137,14 @@ layui.define(["element", "jquery"], function (exports) {
leftMenuHtml += '<ul class="layui-nav layui-nav-tree layui-left-nav-tree ' + leftMenuCheckDefault + '" id="' + key + '">\n'; leftMenuHtml += '<ul class="layui-nav layui-nav-tree layui-left-nav-tree ' + leftMenuCheckDefault + '" id="' + key + '">\n';
var menuList = val.children; var menuList = val.children;
$.each(menuList, function (index, menu) { $.each(menuList, function (index, menu) {
leftMenuHtml += '<li class="layui-nav-item">\n'; if (booleanNav)
{
leftMenuHtml += '<li class="layui-nav-item layui-nav-itemed">\n';
}
else
{
leftMenuHtml += '<li class="layui-nav-item ">\n';
}
if (menu.children && menu.children.length > 0) { if (menu.children && menu.children.length > 0) {
leftMenuHtml += '<a href="javascript:;" class="layui-menu-tips" ><i style="width: 14px;" class="' + menu.icon + '"></i><span class="layui-left-nav"> ' + menu.name + '</span> </a>'; leftMenuHtml += '<a href="javascript:;" class="layui-menu-tips" ><i style="width: 14px;" class="' + menu.icon + '"></i><span class="layui-left-nav"> ' + menu.name + '</span> </a>';
var buildChildHtml = function (html, children, menuParameId) { var buildChildHtml = function (html, children, menuParameId) {

View File

@ -73,7 +73,7 @@
<div layui-left-menu style="display: flex; height: 6% ;margin-right: 4px;"> <div layui-left-menu style="display: flex; height: 6% ;margin-right: 4px;">
<i class="layui-icon layui-icon-search" style=" width: 30px;margin-top: 5px;font-size:24px ;"></i> <i class="layui-icon layui-icon-search" style=" width: 30px;margin-top: 5px;font-size:24px ;"></i>
<input name="search" type="text" placeholder="搜索..." class="layui-input layui-input-search" <input name="search" type="text" placeholder="搜索..." class="layui-input layui-input-search"
autocomplete="off" > autocomplete="off">
</div> </div>
<button class="layui-btn layui-hide" lay-submit lay-filter="js-search-filter">搜索</button> <button class="layui-btn layui-hide" lay-submit lay-filter="js-search-filter">搜索</button>
</div> </div>
@ -112,10 +112,28 @@
spLayui.init('${request.contextPath}/admin/list/index/menu/tree'); spLayui.init('${request.contextPath}/admin/list/index/menu/tree');
form.on('submit(js-search-filter)', function (data) { form.on('submit(js-search-filter)', function (data) {
console.log(data.elem) //被执行事件的元素DOM对象一般为button对象
console.log(data.form) //被执行提交的form对象一般在存在form标签时才会返回 if (data.field.search) {
console.log(data.field) //当前容器的全部表单字段,名值对形式:{name: value} 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; return false;
}); });
}); });