增加搜索菜单功能
parent
b9a7f297a1
commit
9f0df886ba
|
@ -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<String, Object> result = sysMenuService.listIndexMenuSearchTree(menuName);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,4 +24,13 @@ public interface SysMenuMapper extends BaseMapper<SysMenu> {
|
|||
* @throws Exception
|
||||
*/
|
||||
List<SysMenuDTO> listByRoleId(String roleId) throws Exception;
|
||||
|
||||
/**
|
||||
* 根据用户输入的菜单名称 模糊匹配
|
||||
*
|
||||
* @param menuName 菜单名称
|
||||
* @return 用户结果
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
List<SysMenu> listBySearchByName(String menuName) throws Exception;
|
||||
}
|
||||
|
|
|
@ -36,6 +36,16 @@ public interface ISysMenuService extends IService<SysMenu> {
|
|||
*/
|
||||
Map<String, Object> listIndexMenuTree() throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* 用户搜索系统首页初始化菜单树数据
|
||||
*
|
||||
* @return 系统首页初始化菜单树数据
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
Map<String, Object> listIndexMenuSearchTree(String menuName) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* 获取系统菜单树
|
||||
*
|
||||
|
|
|
@ -95,6 +95,40 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统菜单树
|
||||
*
|
||||
|
|
|
@ -28,4 +28,22 @@
|
|||
ON ssrm.role_id = #{roleId}
|
||||
WHERE t.id = ssrm.menu_id
|
||||
</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>
|
||||
|
|
|
@ -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 += '<ul class="layui-nav layui-nav-tree layui-left-nav-tree ' + leftMenuCheckDefault + '" id="' + key + '">\n';
|
||||
var menuList = val.children;
|
||||
$.each(menuList, function (index, menu) {
|
||||
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) {
|
||||
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) {
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue