Pre Merge pull request !389 from gwoksing/master

This commit is contained in:
gwoksing 2022-05-06 05:57:48 +00:00 committed by Gitee
commit b534f24386
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 168 additions and 64 deletions

View File

@ -1,6 +1,8 @@
package com.ruoyi.web.controller.system;
import java.util.List;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
@ -44,6 +46,18 @@ public class SysMenuController extends BaseController
return AjaxResult.success(menus);
}
/**
* 分页获取菜单列表
*/
@PreAuthorize("@ss.hasPermi('system:menu:list')")
@GetMapping("/listTreeByPage")
public TableDataInfo listTreeByPage(SysMenu menu)
{
startPage();
List<SysMenu> menus = menuService.selectTreeByPage(menu, getUserId());
return getDataTable(menus);
}
/**
* 根据菜单编号获取详细信息
*/

View File

@ -133,4 +133,13 @@ public interface ISysMenuService
* @return 结果
*/
public String checkMenuNameUnique(SysMenu menu);
/**
* 分页查询菜单树
*
* @param menu
* @param userId
* @return
*/
public List<SysMenu> selectTreeByPage(SysMenu menu, Long userId);
}

View File

@ -79,6 +79,60 @@ public class SysMenuServiceImpl implements ISysMenuService
return menuList;
}
/**
* 分页查询菜单树
*
* @param menu
* @param userId
* @return
*/
@Override
public List<SysMenu> selectTreeByPage(SysMenu menu, Long userId)
{
List<SysMenu> menuList = null;
menu.setParentId(0L);
// 管理员显示所有菜单信息
if (SysUser.isAdmin(userId)) {
menuList = menuMapper.selectMenuList(menu);
}
else
{
menu.getParams().put("userId", userId);
menuList = menuMapper.selectMenuListByUserId(menu);
}
return findChildren(menuList, userId);
}
public List<SysMenu> findChildren(List<SysMenu> sysMenuList, Long userId)
{
List<SysMenu> children = null;
SysMenu menu = new SysMenu();
for (SysMenu sysMenu : sysMenuList)
{
menu.setParentId(sysMenu.getMenuId());
// 管理员显示所有菜单信息
if (SysUser.isAdmin(userId))
{
children = menuMapper.selectMenuList(menu);
}
else
{
menu.getParams().put("userId", userId);
children = menuMapper.selectMenuListByUserId(menu);
}
if (StringUtils.isNotNull(children) && children.size() > 0)
{
findChildren(children, userId);
sysMenu.setChildren(children);
}
}
return sysMenuList;
}
/**
* 根据用户ID查询权限
*

View File

@ -35,6 +35,9 @@
<select id="selectMenuList" parameterType="SysMenu" resultMap="SysMenuResult">
<include refid="selectMenuVo"/>
<where>
<if test="parentId != null">
AND parent_id = #{parentId}
</if>
<if test="menuName != null and menuName != ''">
AND menu_name like concat('%', #{menuName}, '%')
</if>
@ -61,6 +64,9 @@
left join sys_user_role ur on rm.role_id = ur.role_id
left join sys_role ro on ur.role_id = ro.role_id
where ur.user_id = #{params.userId}
<if test="parentId != null">
AND m.parent_id = #{parentId}
</if>
<if test="menuName != null and menuName != ''">
AND m.menu_name like concat('%', #{menuName}, '%')
</if>

View File

@ -1,60 +1,69 @@
import request from '@/utils/request'
// 查询菜单列表
export function listMenu(query) {
return request({
url: '/system/menu/list',
method: 'get',
params: query
})
}
// 查询菜单详细
export function getMenu(menuId) {
return request({
url: '/system/menu/' + menuId,
method: 'get'
})
}
// 查询菜单下拉树结构
export function treeselect() {
return request({
url: '/system/menu/treeselect',
method: 'get'
})
}
// 根据角色ID查询菜单下拉树结构
export function roleMenuTreeselect(roleId) {
return request({
url: '/system/menu/roleMenuTreeselect/' + roleId,
method: 'get'
})
}
// 新增菜单
export function addMenu(data) {
return request({
url: '/system/menu',
method: 'post',
data: data
})
}
// 修改菜单
export function updateMenu(data) {
return request({
url: '/system/menu',
method: 'put',
data: data
})
}
// 删除菜单
export function delMenu(menuId) {
return request({
url: '/system/menu/' + menuId,
method: 'delete'
})
}
import request from '@/utils/request'
// 查询菜单列表
export function listMenu(query) {
return request({
url: '/system/menu/list',
method: 'get',
params: query
})
}
// 分页查询菜单列表
export function listTreeByPage(query) {
return request({
url: '/system/menu/listTreeByPage',
method: 'get',
params: query
})
}
// 查询菜单详细
export function getMenu(menuId) {
return request({
url: '/system/menu/' + menuId,
method: 'get'
})
}
// 查询菜单下拉树结构
export function treeselect() {
return request({
url: '/system/menu/treeselect',
method: 'get'
})
}
// 根据角色ID查询菜单下拉树结构
export function roleMenuTreeselect(roleId) {
return request({
url: '/system/menu/roleMenuTreeselect/' + roleId,
method: 'get'
})
}
// 新增菜单
export function addMenu(data) {
return request({
url: '/system/menu',
method: 'post',
data: data
})
}
// 修改菜单
export function updateMenu(data) {
return request({
url: '/system/menu',
method: 'put',
data: data
})
}
// 删除菜单
export function delMenu(menuId) {
return request({
url: '/system/menu/' + menuId,
method: 'delete'
})
}

View File

@ -77,7 +77,7 @@
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@ -102,6 +102,14 @@
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改菜单对话框 -->
<el-dialog :title="title" :visible.sync="open" width="680px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
@ -275,7 +283,7 @@
</template>
<script>
import { listMenu, getMenu, delMenu, addMenu, updateMenu } from "@/api/system/menu";
import { listMenu, getMenu, delMenu, addMenu, updateMenu, listTreeByPage } from "@/api/system/menu";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import IconSelect from "@/components/IconSelect";
@ -304,9 +312,12 @@ export default {
refreshTable: true,
//
queryParams: {
pageNum: 1,
pageSize: 10,
menuName: undefined,
visible: undefined
},
total: 0,
//
form: {},
//
@ -334,8 +345,9 @@ export default {
/** 查询菜单列表 */
getList() {
this.loading = true;
listMenu(this.queryParams).then(response => {
this.menuList = this.handleTree(response.data, "menuId");
listTreeByPage(this.queryParams).then(response => {
this.menuList = response.rows;
this.total = response.total;
this.loading = false;
});
},