Merge branch 'master' into net6.0
This commit is contained in:
commit
e527e2fa59
@ -54,18 +54,30 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
return SUCCESS(sysMenuService.GetMenuByMenuId(menuId), "yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取菜单下拉树列表(分配角色所需菜单)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("treeSelect")]
|
||||
public IActionResult TreeSelect()
|
||||
{
|
||||
long userId = HttpContext.GetUId();
|
||||
var list = sysMenuService.SelectMenuList(new MenuQueryDto(), userId).FindAll(f => f.visible == "0");
|
||||
var treeMenus = sysMenuService.BuildMenuTreeSelect(list);
|
||||
///// <summary>
|
||||
///// 获取菜单下拉树列表(分配角色所需菜单)
|
||||
///// </summary>
|
||||
///// <returns></returns>
|
||||
//[HttpGet("treeSelect")]
|
||||
//public IActionResult TreeSelect()
|
||||
//{
|
||||
// long userId = HttpContext.GetUId();
|
||||
// var list = sysMenuService.SelectMenuList(new MenuQueryDto(), userId).FindAll(f => f.visible == "0");
|
||||
// var treeMenus = sysMenuService.BuildMenuTreeSelect(list);
|
||||
|
||||
return SUCCESS(treeMenus);
|
||||
// return SUCCESS(treeMenus);
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 根据菜单编号获取菜单列表,菜单管理首次进入
|
||||
/// </summary>
|
||||
/// <param name="menuId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list/{menuId}")]
|
||||
[ActionPermissionFilter(Permission = "system:menu:query")]
|
||||
public IActionResult GetMenuList(int menuId = 0)
|
||||
{
|
||||
return SUCCESS(sysMenuService.GetMenusByMenuId(menuId), "yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -18,7 +18,7 @@ namespace ZR.Admin.WebApi.Hubs
|
||||
public DateTime LoginTime { get; set; }
|
||||
public string UserIP { get; set; }
|
||||
|
||||
public OnlineUsers(string clientid, string name, long? userid, string? userip)
|
||||
public OnlineUsers(string clientid, string name, long? userid, string userip)
|
||||
{
|
||||
ConnnectionId = clientid;
|
||||
Name = name;
|
||||
|
||||
@ -80,6 +80,7 @@ namespace ZR.Model.System.Dto
|
||||
public string Visible { get; set; }
|
||||
public string Status { get; set; }
|
||||
public string MenuTypeIds { get; set; } = string.Empty;
|
||||
public int? ParentId { get; set; }
|
||||
public string[] MenuTypeIdArr
|
||||
{
|
||||
get
|
||||
|
||||
@ -21,12 +21,6 @@ namespace ZR.Model.System
|
||||
/// </summary>
|
||||
public string MenuName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 父菜单名称
|
||||
/// </summary>
|
||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||
public string parentName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 父菜单ID
|
||||
/// </summary>
|
||||
@ -90,5 +84,21 @@ namespace ZR.Model.System
|
||||
/// </summary>
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public List<SysMenu> children { get; set; } = new List<SysMenu>();
|
||||
/// <summary>
|
||||
/// 子菜单个数
|
||||
/// </summary>
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public int SubNum { get; set; }
|
||||
/// <summary>
|
||||
/// 是否包含子节点,前端用
|
||||
/// </summary>
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public bool HasChildren
|
||||
{
|
||||
get
|
||||
{
|
||||
return SubNum > 0 || children.Count > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ namespace ZR.Repository.System
|
||||
.WhereIF(!string.IsNullOrEmpty(menu.MenuName), it => it.MenuName.Contains(menu.MenuName))
|
||||
.WhereIF(!string.IsNullOrEmpty(menu.Visible), it => it.visible == menu.Visible)
|
||||
.WhereIF(!string.IsNullOrEmpty(menu.Status), it => it.status == menu.Status)
|
||||
|
||||
.WhereIF(!string.IsNullOrEmpty(menu.MenuTypeIds), it => menu.MenuTypeIdArr.Contains(it.menuType))
|
||||
.OrderBy(it => new { it.parentId, it.orderNum })
|
||||
.ToTree(it => it.children, it => it.parentId, 0);
|
||||
}
|
||||
@ -32,19 +32,20 @@ namespace ZR.Repository.System
|
||||
/// <summary>
|
||||
/// 根据用户查询系统菜单列表(菜单管理)
|
||||
/// </summary>
|
||||
/// <param name="sysMenu"></param>
|
||||
/// <param name="menu"></param>
|
||||
/// <param name="roles">用户角色集合</param>
|
||||
/// <returns></returns>
|
||||
public List<SysMenu> SelectTreeMenuListByUserId(MenuQueryDto sysMenu, List<long> roles)
|
||||
public List<SysMenu> SelectTreeMenuListByRoles(MenuQueryDto menu, List<long> roles)
|
||||
{
|
||||
var roleMenus = Context.Queryable<SysRoleMenu>()
|
||||
.Where(r => roles.Contains(r.Role_id));
|
||||
|
||||
return Context.Queryable<SysMenu>()
|
||||
.InnerJoin(roleMenus, (c, j) => c.MenuId == j.Menu_id)
|
||||
.WhereIF(!string.IsNullOrEmpty(sysMenu.MenuName), (c, j) => c.MenuName.Contains(sysMenu.MenuName))
|
||||
.WhereIF(!string.IsNullOrEmpty(sysMenu.Visible), (c, j) => c.visible == sysMenu.Visible)
|
||||
.WhereIF(!string.IsNullOrEmpty(sysMenu.Status), (c, j) => c.status == sysMenu.Status)
|
||||
.WhereIF(!string.IsNullOrEmpty(menu.MenuName), (c, j) => c.MenuName.Contains(menu.MenuName))
|
||||
.WhereIF(!string.IsNullOrEmpty(menu.Visible), (c, j) => c.visible == menu.Visible)
|
||||
.WhereIF(!string.IsNullOrEmpty(menu.Status), (c, j) => c.status == menu.Status)
|
||||
.WhereIF(!string.IsNullOrEmpty(menu.MenuTypeIds), c => menu.MenuTypeIdArr.Contains(c.menuType))
|
||||
.OrderBy((c, j) => new { c.parentId, c.orderNum })
|
||||
.Select(c => c)
|
||||
.ToTree(it => it.children, it => it.parentId, 0);
|
||||
@ -60,6 +61,7 @@ namespace ZR.Repository.System
|
||||
.WhereIF(!string.IsNullOrEmpty(menu.MenuName), it => it.MenuName.Contains(menu.MenuName))
|
||||
.WhereIF(!string.IsNullOrEmpty(menu.Visible), it => it.visible == menu.Visible)
|
||||
.WhereIF(!string.IsNullOrEmpty(menu.Status), it => it.status == menu.Status)
|
||||
.WhereIF(menu.ParentId != null, it => it.parentId == menu.ParentId)
|
||||
.OrderBy(it => new { it.parentId, it.orderNum })
|
||||
.ToList();
|
||||
}
|
||||
@ -87,35 +89,22 @@ namespace ZR.Repository.System
|
||||
|
||||
#region 左侧菜单树
|
||||
|
||||
/// <summary>
|
||||
/// 管理员获取左侧菜单树
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<SysMenu> SelectMenuTreeAll()
|
||||
{
|
||||
var menuTypes = new string[] { "M", "C" };
|
||||
|
||||
return Context.Queryable<SysMenu>()
|
||||
.Where(f => f.status == "0" && menuTypes.Contains(f.menuType))
|
||||
.OrderBy(it => new { it.parentId, it.orderNum }).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据用户角色获取左侧菜单树
|
||||
/// </summary>
|
||||
/// <param name="roleIds"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysMenu> SelectMenuTreeByRoleIds(List<long> roleIds)
|
||||
{
|
||||
var menuTypes = new string[] { "M", "C" };
|
||||
return Context.Queryable<SysMenu>()
|
||||
.Where((menu) =>
|
||||
menuTypes.Contains(menu.menuType)
|
||||
&& menu.status == "0"
|
||||
&& SqlFunc.Subqueryable<SysRoleMenu>().Where(s => roleIds.Contains(s.Role_id) && s.Menu_id == menu.MenuId).Any())
|
||||
.OrderBy((menu) => new { menu.parentId, menu.orderNum })
|
||||
.Select((menu) => menu).ToList();
|
||||
}
|
||||
///// <summary>
|
||||
///// 根据用户角色获取左侧菜单树
|
||||
///// </summary>
|
||||
///// <param name="roleIds"></param>
|
||||
///// <returns></returns>
|
||||
//public List<SysMenu> SelectMenuTreeByRoleIds(List<long> roleIds)
|
||||
//{
|
||||
// var menuTypes = new string[] { "M", "C" };
|
||||
// return Context.Queryable<SysMenu>()
|
||||
// .Where((menu) =>
|
||||
// menuTypes.Contains(menu.menuType)
|
||||
// && menu.status == "0"
|
||||
// && SqlFunc.Subqueryable<SysRoleMenu>().Where(s => roleIds.Contains(s.Role_id) && s.Menu_id == menu.MenuId).Any())
|
||||
// .OrderBy((menu) => new { menu.parentId, menu.orderNum })
|
||||
// .Select((menu) => menu).ToList();
|
||||
//}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@ namespace ZR.Service.System.IService
|
||||
List<SysMenu> SelectTreeMenuList(MenuQueryDto menu, long userId);
|
||||
|
||||
SysMenu GetMenuByMenuId(int menuId);
|
||||
List<SysMenu> GetMenusByMenuId(int menuId);
|
||||
int AddMenu(SysMenu menu);
|
||||
|
||||
int EditMenu(SysMenu menu);
|
||||
|
||||
@ -41,7 +41,7 @@ namespace ZR.Service
|
||||
else
|
||||
{
|
||||
var userRoles = SysRoleService.SelectUserRoles(userId);
|
||||
menuList = MenuRepository.SelectTreeMenuListByUserId(menu, userRoles);
|
||||
menuList = MenuRepository.SelectTreeMenuListByRoles(menu, userRoles);
|
||||
}
|
||||
return menuList;
|
||||
}
|
||||
@ -75,6 +75,21 @@ namespace ZR.Service
|
||||
return MenuRepository.SelectMenuById(menuId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据菜单id获取菜单列表
|
||||
/// </summary>
|
||||
/// <param name="menuId"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysMenu> GetMenusByMenuId(int menuId)
|
||||
{
|
||||
var list = MenuRepository.GetList(f => f.parentId == menuId).OrderBy(f => f.orderNum).ToList();
|
||||
Context.ThenMapper(list, item =>
|
||||
{
|
||||
item.SubNum = Context.Queryable<SysMenu>().SetContext(x => x.parentId, () => item.MenuId, item).Count();
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加菜单
|
||||
/// </summary>
|
||||
@ -154,17 +169,19 @@ namespace ZR.Service
|
||||
/// <returns></returns>
|
||||
public List<SysMenu> SelectMenuTreeByUserId(long userId)
|
||||
{
|
||||
List<SysMenu> menus;
|
||||
MenuQueryDto dto = new() { Status = "0", MenuTypeIds = "M,C" };
|
||||
//List<SysMenu> menus;
|
||||
if (SysRoleService.IsAdmin(userId))
|
||||
{
|
||||
menus = MenuRepository.SelectMenuTreeAll();
|
||||
return MenuRepository.SelectTreeMenuList(dto);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<long> roleIds = SysRoleService.SelectUserRoles(userId);
|
||||
menus = MenuRepository.SelectMenuTreeByRoleIds(roleIds);
|
||||
//menus = MenuRepository.SelectMenuTreeByRoleIds(roleIds);
|
||||
return MenuRepository.SelectTreeMenuListByRoles(dto, roleIds);
|
||||
}
|
||||
return GetChildPerms(menus, 0);
|
||||
//return GetChildPerms(menus, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -205,25 +222,25 @@ namespace ZR.Service
|
||||
|
||||
#region 方法
|
||||
|
||||
/// <summary>
|
||||
/// 根据父节点的ID获取所有子节点
|
||||
/// </summary>
|
||||
/// <param name="list">分类表</param>
|
||||
/// <param name="parentId">传入的父节点ID</param>
|
||||
/// <returns></returns>
|
||||
public List<SysMenu> GetChildPerms(List<SysMenu> list, int parentId)
|
||||
{
|
||||
List<SysMenu> returnList = new List<SysMenu>();
|
||||
var data = list.FindAll(f => f.parentId == parentId);
|
||||
///// <summary>
|
||||
///// 根据父节点的ID获取所有子节点
|
||||
///// </summary>
|
||||
///// <param name="list">分类表</param>
|
||||
///// <param name="parentId">传入的父节点ID</param>
|
||||
///// <returns></returns>
|
||||
//public List<SysMenu> GetChildPerms(List<SysMenu> list, int parentId)
|
||||
//{
|
||||
// List<SysMenu> returnList = new List<SysMenu>();
|
||||
// var data = list.FindAll(f => f.parentId == parentId);
|
||||
|
||||
foreach (var item in data)
|
||||
{
|
||||
RecursionFn(list, item);
|
||||
// foreach (var item in data)
|
||||
// {
|
||||
// RecursionFn(list, item);
|
||||
|
||||
returnList.Add(item);
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
// returnList.Add(item);
|
||||
// }
|
||||
// return returnList;
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 递归列表
|
||||
|
||||
@ -8,7 +8,13 @@ export function listMenu(query) {
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
// 查询菜单列表
|
||||
export function listMenuById(menuId) {
|
||||
return request({
|
||||
url: '/system/menu/list/' + menuId,
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
// 查询菜单详细
|
||||
export function getMenu(menuId) {
|
||||
return request({
|
||||
@ -75,4 +81,4 @@ export const getRouters = (query) => {
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,7 +25,11 @@
|
||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
|
||||
<el-table v-if="refreshTable" v-loading="loading" :data="menuList" :default-expand-all="isExpandAll" row-key="menuId" border
|
||||
<el-table v-if="refreshTable" v-loading="loading" :data="menuList" :default-expand-all="isExpandAll"
|
||||
row-key="menuId"
|
||||
border
|
||||
lazy
|
||||
:load="loadMenu"
|
||||
:tree-props="{children: 'children', hasChildren: 'hasChildren'}">
|
||||
<el-table-column prop="menuName" label="菜单名称" :show-overflow-tooltip="true" width="160"></el-table-column>
|
||||
<el-table-column prop="icon" label="图标" align="center" width="80">
|
||||
@ -217,6 +221,7 @@ import {
|
||||
addMenu,
|
||||
changeMenuSort,
|
||||
updateMenu,
|
||||
listMenuById
|
||||
} from "@/api/system/menu";
|
||||
import Treeselect from "@riophae/vue-treeselect";
|
||||
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
|
||||
@ -228,7 +233,7 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
// 遮罩层
|
||||
loading: true,
|
||||
loading: false,
|
||||
// 显示搜索条件
|
||||
showSearch: true,
|
||||
// 菜单表格树数据
|
||||
@ -274,13 +279,16 @@ export default {
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.getList();
|
||||
// this.getList();
|
||||
this.getDicts("sys_show_hide").then((response) => {
|
||||
this.visibleOptions = response.data;
|
||||
});
|
||||
this.getDicts("sys_normal_disable").then((response) => {
|
||||
this.statusOptions = response.data;
|
||||
});
|
||||
listMenuById(0).then((response) => {
|
||||
this.menuList = response.data
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
// 选择图标
|
||||
@ -309,7 +317,7 @@ export default {
|
||||
},
|
||||
/** 查询菜单下拉树结构 */
|
||||
getTreeselect() {
|
||||
listMenu().then((response) => {
|
||||
listMenu({ menuTypeIds: 'M,C,F' }).then((response) => {
|
||||
this.menuOptions = [];
|
||||
const menu = { menuId: 0, menuName: "根菜单", children: [] };
|
||||
menu.children = response.data;
|
||||
@ -453,6 +461,11 @@ export default {
|
||||
this.refreshTable = true;
|
||||
});
|
||||
},
|
||||
loadMenu (row, treeNode, resolve) {
|
||||
listMenuById(row.menuId).then((res) => {
|
||||
resolve(res.data)
|
||||
})
|
||||
}
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user