增加数据权限
This commit is contained in:
parent
f5f5000854
commit
bf26823a85
@ -3,6 +3,7 @@ using Infrastructure.Attribute;
|
|||||||
using Infrastructure.Enums;
|
using Infrastructure.Enums;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using ZR.Admin.WebApi.Extensions;
|
||||||
using ZR.Admin.WebApi.Filters;
|
using ZR.Admin.WebApi.Filters;
|
||||||
using ZR.Common;
|
using ZR.Common;
|
||||||
using ZR.Model.System;
|
using ZR.Model.System;
|
||||||
@ -73,6 +74,24 @@ namespace ZR.Admin.WebApi.Controllers.System
|
|||||||
return SUCCESS(DeptService.BuildDeptTreeSelect(depts), TIME_FORMAT_FULL);
|
return SUCCESS(DeptService.BuildDeptTreeSelect(depts), TIME_FORMAT_FULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取角色部门信息
|
||||||
|
/// 加载对应角色部门列表树
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("roleDeptTreeselect/{roleId}")]
|
||||||
|
public IActionResult RoleMenuTreeselect(int roleId)
|
||||||
|
{
|
||||||
|
var depts = DeptService.GetSysDepts(new SysDept());
|
||||||
|
var checkedKeys = DeptService.SelectRoleDepts(roleId);
|
||||||
|
return SUCCESS(new
|
||||||
|
{
|
||||||
|
checkedKeys,
|
||||||
|
depts = DeptService.BuildDeptTreeSelect(depts),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 根据部门编号获取详细信息
|
/// 根据部门编号获取详细信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -103,13 +103,10 @@ namespace ZR.Admin.WebApi.Controllers.System
|
|||||||
return ToResponse(ApiResult.Error($"编辑角色'{sysRoleDto.RoleName}'失败,角色权限已存在"));
|
return ToResponse(ApiResult.Error($"编辑角色'{sysRoleDto.RoleName}'失败,角色权限已存在"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sysRoleDto.Update_by = User.Identity.Name;
|
sysRoleDto.Update_by = User.Identity.Name;
|
||||||
int upResult = sysRoleService.UpdateRole(sysRoleDto);
|
int upResult = sysRoleService.UpdateRole(sysRoleDto);
|
||||||
if (upResult > 0)
|
if (upResult > 0)
|
||||||
{
|
{
|
||||||
//TODO 更新缓存用户权限信息
|
|
||||||
|
|
||||||
return SUCCESS(upResult);
|
return SUCCESS(upResult);
|
||||||
}
|
}
|
||||||
return ToResponse(ApiResult.Error($"修改角色'{sysRoleDto.RoleName}'失败,请联系管理员"));
|
return ToResponse(ApiResult.Error($"修改角色'{sysRoleDto.RoleName}'失败,请联系管理员"));
|
||||||
|
|||||||
@ -46,12 +46,11 @@ namespace ZR.Admin.WebApi.Extensions
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
//每次Sql执行前事件
|
//每次Sql执行前事件
|
||||||
|
|
||||||
DbScoped.SugarScope.GetConnection(0).Aop.OnLogExecuting = (sql, pars) =>
|
DbScoped.SugarScope.GetConnection(0).Aop.OnLogExecuting = (sql, pars) =>
|
||||||
{
|
{
|
||||||
var param = DbScoped.SugarScope.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value));
|
var param = DbScoped.SugarScope.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value));
|
||||||
|
|
||||||
FilterData(DbScoped.SugarScope.GetConnection(0));
|
FilterData();
|
||||||
|
|
||||||
logger.Info($"{sql},{param}");
|
logger.Info($"{sql},{param}");
|
||||||
};
|
};
|
||||||
@ -79,7 +78,10 @@ namespace ZR.Admin.WebApi.Extensions
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void FilterData(SqlSugarProvider db0)
|
/// <summary>
|
||||||
|
/// 分页获取count 不会追加sql
|
||||||
|
/// </summary>
|
||||||
|
private static void FilterData()
|
||||||
{
|
{
|
||||||
var u = App.User;
|
var u = App.User;
|
||||||
if (u == null) return;
|
if (u == null) return;
|
||||||
@ -98,9 +100,11 @@ namespace ZR.Admin.WebApi.Extensions
|
|||||||
}
|
}
|
||||||
else if (DATA_SCOPE_CUSTOM.Equals(dataScope))//自定数据权限
|
else if (DATA_SCOPE_CUSTOM.Equals(dataScope))//自定数据权限
|
||||||
{
|
{
|
||||||
|
//有问题
|
||||||
//var roleDepts = db0.Queryable<SysRoleDept>()
|
//var roleDepts = db0.Queryable<SysRoleDept>()
|
||||||
//.Where(f => f.RoleId == role.RoleId).Select(f => f.DeptId).ToList();
|
//.Where(f => f.RoleId == role.RoleId).Select(f => f.DeptId).ToList();
|
||||||
//var filter1 = new TableFilterItem<SysDept>(it => roleDepts.Contains(it.DeptId));
|
//var filter1 = new TableFilterItem<SysDept>(it => roleDepts.Contains(it.DeptId));
|
||||||
|
//DbScoped.SugarScope.GetConnection(0).QueryFilter.Add(filter1);
|
||||||
}
|
}
|
||||||
else if (DATA_SCOPE_DEPT.Equals(dataScope))//本部门数据
|
else if (DATA_SCOPE_DEPT.Equals(dataScope))//本部门数据
|
||||||
{
|
{
|
||||||
|
|||||||
@ -45,10 +45,20 @@ namespace ZR.Model.System
|
|||||||
[SugarColumn(IsOnlyIgnoreInsert = true, IsOnlyIgnoreUpdate = true)]
|
[SugarColumn(IsOnlyIgnoreInsert = true, IsOnlyIgnoreUpdate = true)]
|
||||||
public string DelFlag { get; set; }
|
public string DelFlag { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 )
|
/// 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限))
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string DataScope { get; set; }
|
public string DataScope { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// 菜单树选择项是否关联显示
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnName = "menu_check_strictly")]
|
||||||
|
public bool MenuCheckStrictly { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 部门树选择项是否关联显示
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnName = "dept_check_strictly")]
|
||||||
|
public bool DeptCheckStrictly { get; set; }
|
||||||
|
/// <summary>
|
||||||
/// 菜单组
|
/// 菜单组
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(IsIgnore = true)]
|
[SugarColumn(IsIgnore = true)]
|
||||||
@ -58,6 +68,11 @@ namespace ZR.Model.System
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(IsIgnore = true)]
|
[SugarColumn(IsIgnore = true)]
|
||||||
public long[] DeptIds { get; set; }
|
public long[] DeptIds { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 用户个数
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsIgnore = true)]
|
||||||
|
public int UserNum { get; set; }
|
||||||
|
|
||||||
public SysRole() { }
|
public SysRole() { }
|
||||||
|
|
||||||
|
|||||||
@ -28,4 +28,21 @@ namespace ZR.Repository.System
|
|||||||
.UpdateColumns(it => new { it.Ancestors }).ExecuteCommand();
|
.UpdateColumns(it => new { it.Ancestors }).ExecuteCommand();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 角色部门
|
||||||
|
/// </summary>
|
||||||
|
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||||
|
public class SysRoleDeptRepository : BaseRepository<SysRoleDept>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 根据角色获取菜单id
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public List<SysRoleDept> SelectRoleDeptByRoleId(long roleId)
|
||||||
|
{
|
||||||
|
return Context.Queryable<SysRoleDept>().Where(it => it.RoleId == roleId).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,9 +15,8 @@ namespace ZR.Repository.System
|
|||||||
public class SysRoleRepository : BaseRepository<SysRole>
|
public class SysRoleRepository : BaseRepository<SysRole>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 根据条件分页查询角色数据
|
/// 查询所有角色数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sysRole"></param>
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public List<SysRole> SelectRoleList()
|
public List<SysRole> SelectRoleList()
|
||||||
{
|
{
|
||||||
@ -40,7 +39,16 @@ namespace ZR.Repository.System
|
|||||||
exp.AndIF(!string.IsNullOrEmpty(sysRole.Status), role => role.Status == sysRole.Status);
|
exp.AndIF(!string.IsNullOrEmpty(sysRole.Status), role => role.Status == sysRole.Status);
|
||||||
exp.AndIF(!string.IsNullOrEmpty(sysRole.RoleKey), role => role.RoleKey == sysRole.RoleKey);
|
exp.AndIF(!string.IsNullOrEmpty(sysRole.RoleKey), role => role.RoleKey == sysRole.RoleKey);
|
||||||
|
|
||||||
return GetPages(exp.ToExpression(), pager, x => x.RoleSort);
|
var query = Context.Queryable<SysRole>()
|
||||||
|
.Where(exp.ToExpression())
|
||||||
|
.OrderBy(x => x.RoleSort)
|
||||||
|
.Select((role) => new SysRole
|
||||||
|
{
|
||||||
|
RoleId = role.RoleId.SelectAll(),
|
||||||
|
UserNum = SqlFunc.Subqueryable<SysUserRole>().Where(f => f.RoleId == role.RoleId).Count()
|
||||||
|
});
|
||||||
|
|
||||||
|
return query.ToPage(pager);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -57,15 +65,6 @@ namespace ZR.Repository.System
|
|||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 查询所有角色
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public List<SysRole> SelectRoleAll()
|
|
||||||
{
|
|
||||||
return Context.Queryable<SysRole>().OrderBy(it => it.RoleSort).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 通过角色ID查询角色
|
/// 通过角色ID查询角色
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -93,8 +92,8 @@ namespace ZR.Repository.System
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public List<SysRole> SelectUserRoleListByUserId(long userId)
|
public List<SysRole> SelectUserRoleListByUserId(long userId)
|
||||||
{
|
{
|
||||||
return Context.Queryable<SysUserRole, SysRole>((ur, r) => new SqlSugar.JoinQueryInfos(
|
return Context.Queryable<SysUserRole, SysRole>((ur, r) => new JoinQueryInfos(
|
||||||
SqlSugar.JoinType.Left, ur.RoleId == r.RoleId
|
JoinType.Left, ur.RoleId == r.RoleId
|
||||||
)).Where((ur, r) => ur.UserId == userId)
|
)).Where((ur, r) => ur.UserId == userId)
|
||||||
.Select((ur, r) => r).ToList();
|
.Select((ur, r) => r).ToList();
|
||||||
}
|
}
|
||||||
@ -166,8 +165,11 @@ namespace ZR.Repository.System
|
|||||||
|
|
||||||
return db.Updateable<SysRole>()
|
return db.Updateable<SysRole>()
|
||||||
.SetColumns(it => it.Update_time == sysRole.Update_time)
|
.SetColumns(it => it.Update_time == sysRole.Update_time)
|
||||||
|
.SetColumns(it => it.DataScope == sysRole.DataScope)
|
||||||
.SetColumns(it => it.Remark == sysRole.Remark)
|
.SetColumns(it => it.Remark == sysRole.Remark)
|
||||||
.SetColumns(it => it.Update_by == sysRole.Update_by)
|
.SetColumns(it => it.Update_by == sysRole.Update_by)
|
||||||
|
//.SetColumns(it => it.MenuCheckStrictly == sysRole.MenuCheckStrictly)
|
||||||
|
.SetColumns(it => it.DeptCheckStrictly == sysRole.DeptCheckStrictly)
|
||||||
.SetColumnsIF(!string.IsNullOrEmpty(sysRole.RoleName), it => it.RoleName == sysRole.RoleName)
|
.SetColumnsIF(!string.IsNullOrEmpty(sysRole.RoleName), it => it.RoleName == sysRole.RoleName)
|
||||||
.SetColumnsIF(!string.IsNullOrEmpty(sysRole.RoleKey), it => it.RoleKey == sysRole.RoleKey)
|
.SetColumnsIF(!string.IsNullOrEmpty(sysRole.RoleKey), it => it.RoleKey == sysRole.RoleKey)
|
||||||
.SetColumnsIF(sysRole.RoleSort >= 0, it => it.RoleSort == sysRole.RoleSort)
|
.SetColumnsIF(sysRole.RoleSort >= 0, it => it.RoleSort == sysRole.RoleSort)
|
||||||
|
|||||||
@ -16,5 +16,10 @@ namespace ZR.Service.System.IService
|
|||||||
List<SysDept> GetChildrenDepts(List<SysDept> depts, long deptId);
|
List<SysDept> GetChildrenDepts(List<SysDept> depts, long deptId);
|
||||||
List<SysDept> BuildDeptTree(List<SysDept> depts);
|
List<SysDept> BuildDeptTree(List<SysDept> depts);
|
||||||
List<TreeSelectVo> BuildDeptTreeSelect(List<SysDept> depts);
|
List<TreeSelectVo> BuildDeptTreeSelect(List<SysDept> depts);
|
||||||
|
List<SysRoleDept> SelectRoleDeptByRoleId(long roleId);
|
||||||
|
|
||||||
|
List<long> SelectRoleDepts(long roleId);
|
||||||
|
int DeleteRoleDeptByRoleId(long roleId);
|
||||||
|
int InsertRoleDepts(SysRole role);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,10 +21,11 @@ namespace ZR.Service.System
|
|||||||
public class SysDeptService : BaseService<SysDept>, ISysDeptService
|
public class SysDeptService : BaseService<SysDept>, ISysDeptService
|
||||||
{
|
{
|
||||||
public SysDeptRepository DeptRepository;
|
public SysDeptRepository DeptRepository;
|
||||||
|
public SysRoleDeptRepository RoleDeptRepository;
|
||||||
public SysDeptService(SysDeptRepository deptRepository) : base(deptRepository)
|
public SysDeptService(SysDeptRepository deptRepository, SysRoleDeptRepository roleDeptRepository) : base(deptRepository)
|
||||||
{
|
{
|
||||||
DeptRepository = deptRepository;
|
DeptRepository = deptRepository;
|
||||||
|
RoleDeptRepository = roleDeptRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -225,5 +226,60 @@ namespace ZR.Service.System
|
|||||||
{
|
{
|
||||||
return list.Where(p => p.ParentId == dept.DeptId).ToList();
|
return list.Where(p => p.ParentId == dept.DeptId).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region 角色部门
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据角色获取菜单id
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public List<SysRoleDept> SelectRoleDeptByRoleId(long roleId)
|
||||||
|
{
|
||||||
|
return RoleDeptRepository.SelectRoleDeptByRoleId(roleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取角色部门id集合
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public List<long> SelectRoleDepts(long roleId)
|
||||||
|
{
|
||||||
|
var list = SelectRoleDeptByRoleId(roleId);
|
||||||
|
|
||||||
|
return list.Select(x => x.DeptId).Distinct().ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除角色部门数据
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int DeleteRoleDeptByRoleId(long roleId)
|
||||||
|
{
|
||||||
|
return RoleDeptRepository.Delete(f => f.RoleId == roleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 批量插入角色部门
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="role"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int InsertRoleDepts(SysRole role)
|
||||||
|
{
|
||||||
|
int rows = 1;
|
||||||
|
List<SysRoleDept> list = new();
|
||||||
|
foreach (var item in role.DeptIds)
|
||||||
|
{
|
||||||
|
list.Add(new SysRoleDept() { DeptId = item, RoleId = role.RoleId });
|
||||||
|
}
|
||||||
|
if (list.Count > 0)
|
||||||
|
{
|
||||||
|
rows = RoleDeptRepository.Insert(list);
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,19 +21,23 @@ namespace ZR.Service
|
|||||||
{
|
{
|
||||||
private SysRoleRepository SysRoleRepository;
|
private SysRoleRepository SysRoleRepository;
|
||||||
private ISysUserRoleService SysUserRoleService;
|
private ISysUserRoleService SysUserRoleService;
|
||||||
|
private ISysDeptService DeptService;
|
||||||
|
|
||||||
public SysRoleService(
|
public SysRoleService(
|
||||||
SysRoleRepository sysRoleRepository,
|
SysRoleRepository sysRoleRepository,
|
||||||
ISysUserRoleService sysUserRoleService) : base(sysRoleRepository)
|
ISysUserRoleService sysUserRoleService,
|
||||||
|
ISysDeptService deptService) : base(sysRoleRepository)
|
||||||
{
|
{
|
||||||
SysRoleRepository = sysRoleRepository;
|
SysRoleRepository = sysRoleRepository;
|
||||||
SysUserRoleService = sysUserRoleService;
|
SysUserRoleService = sysUserRoleService;
|
||||||
|
DeptService = deptService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 根据条件分页查询角色数据
|
/// 根据条件分页查询角色数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="role">角色信息</param>
|
/// <param name="role">角色信息</param>
|
||||||
|
/// <param name="pager">分页信息</param>
|
||||||
/// <returns>角色数据集合信息</returns>
|
/// <returns>角色数据集合信息</returns>
|
||||||
public PagedInfo<SysRole> SelectRoleList(SysRole role, PagerInfo pager)
|
public PagedInfo<SysRole> SelectRoleList(SysRole role, PagerInfo pager)
|
||||||
{
|
{
|
||||||
@ -157,17 +161,9 @@ namespace ZR.Service
|
|||||||
{
|
{
|
||||||
return UseTran2(() =>
|
return UseTran2(() =>
|
||||||
{
|
{
|
||||||
int result = Update(sysRoleDto, it => new
|
|
||||||
{
|
|
||||||
it.DataScope
|
|
||||||
}, f => f.RoleId == sysRoleDto.RoleId);
|
|
||||||
|
|
||||||
//if (result > 0 && sysRoleDto.DataScope == "2")
|
|
||||||
//{
|
|
||||||
//删除角色菜单
|
//删除角色菜单
|
||||||
DeleteRoleMenuByRoleId(sysRoleDto.RoleId);
|
DeleteRoleMenuByRoleId(sysRoleDto.RoleId);
|
||||||
InsertRoleMenu(sysRoleDto);
|
InsertRoleMenu(sysRoleDto);
|
||||||
//}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
#region Service
|
#region Service
|
||||||
@ -185,11 +181,13 @@ namespace ZR.Service
|
|||||||
List<SysRoleMenu> sysRoleMenus = new List<SysRoleMenu>();
|
List<SysRoleMenu> sysRoleMenus = new List<SysRoleMenu>();
|
||||||
foreach (var item in sysRoleDto.MenuIds)
|
foreach (var item in sysRoleDto.MenuIds)
|
||||||
{
|
{
|
||||||
SysRoleMenu rm = new SysRoleMenu();
|
SysRoleMenu rm = new SysRoleMenu
|
||||||
rm.Menu_id = item;
|
{
|
||||||
rm.Role_id = sysRoleDto.RoleId;
|
Menu_id = item,
|
||||||
rm.Create_by = sysRoleDto.Create_by;
|
Role_id = sysRoleDto.RoleId,
|
||||||
rm.Create_time = DateTime.Now;
|
Create_by = sysRoleDto.Create_by,
|
||||||
|
Create_time = DateTime.Now
|
||||||
|
};
|
||||||
sysRoleMenus.Add(rm);
|
sysRoleMenus.Add(rm);
|
||||||
}
|
}
|
||||||
//添加角色菜单
|
//添加角色菜单
|
||||||
@ -301,7 +299,17 @@ namespace ZR.Service
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int UpdateRole(SysRole sysRole)
|
public int UpdateRole(SysRole sysRole)
|
||||||
{
|
{
|
||||||
return SysRoleRepository.UpdateSysRole(sysRole);
|
var result = UseTran(() =>
|
||||||
|
{
|
||||||
|
//修改角色信息
|
||||||
|
SysRoleRepository.UpdateSysRole(sysRole);
|
||||||
|
//删除角色与部门管理
|
||||||
|
DeptService.DeleteRoleDeptByRoleId(sysRole.RoleId);
|
||||||
|
//插入角色部门数据
|
||||||
|
DeptService.InsertRoleDepts(sysRole);
|
||||||
|
});
|
||||||
|
|
||||||
|
return result.IsSuccess ? 1 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,15 +26,19 @@
|
|||||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
<el-table v-loading="loading" :data="roleList" border highlight-current-row @selection-change="handleSelectionChange">
|
<el-table v-loading="loading" :data="roleList" highlight-current-row @selection-change="handleSelectionChange">
|
||||||
<el-table-column label="编号" prop="roleId" width="80" />
|
<el-table-column label="编号" prop="roleId" width="80" />
|
||||||
<el-table-column label="名称" prop="roleName" />
|
<el-table-column label="名称" prop="roleName" />
|
||||||
|
<el-table-column label="显示顺序" prop="roleSort"></el-table-column>
|
||||||
<el-table-column label="权限字符" prop="roleKey" />
|
<el-table-column label="权限字符" prop="roleKey" />
|
||||||
<el-table-column label="状态" align="center">
|
<el-table-column label="权限范围" prop="dataScope" :formatter="dataScopeFormat"></el-table-column>
|
||||||
|
<el-table-column label="状态" align="center" width="90">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-switch v-model="scope.row.status" active-value="0" inactive-value="1" @change="handleStatusChange(scope.row)"></el-switch>
|
<el-switch v-model="scope.row.status" :disabled="scope.row.roleKey == 'admin'" active-value="0" inactive-value="1"
|
||||||
|
@change="handleStatusChange(scope.row)"></el-switch>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
<el-table-column label="用户个数" align="center" prop="userNum" width="90" />
|
||||||
<el-table-column label="创建时间" align="center" prop="createTime" width="150" />
|
<el-table-column label="创建时间" align="center" prop="createTime" width="150" />
|
||||||
<el-table-column label="备注" align="center" prop="remark" width="150" :show-overflow-tooltip="true" />
|
<el-table-column label="备注" align="center" prop="remark" width="150" :show-overflow-tooltip="true" />
|
||||||
<el-table-column label="操作" align="center" width="200">
|
<el-table-column label="操作" align="center" width="200">
|
||||||
@ -49,7 +53,7 @@
|
|||||||
<i class="el-icon-d-arrow-right el-icon--right"></i>更多
|
<i class="el-icon-d-arrow-right el-icon--right"></i>更多
|
||||||
</span>
|
</span>
|
||||||
<el-dropdown-menu slot="dropdown">
|
<el-dropdown-menu slot="dropdown">
|
||||||
<el-dropdown-item command="handleDataScope" icon="el-icon-circle-check" v-hasPermi="['system:role:authorize']">数据权限</el-dropdown-item>
|
<el-dropdown-item command="handleDataScope" icon="el-icon-circle-check" v-hasPermi="['system:role:authorize']">菜单权限</el-dropdown-item>
|
||||||
<el-dropdown-item command="handleAuthUser" icon="el-icon-user" v-hasPermi="['system:roleusers:list']">分配用户</el-dropdown-item>
|
<el-dropdown-item command="handleAuthUser" icon="el-icon-user" v-hasPermi="['system:roleusers:list']">分配用户</el-dropdown-item>
|
||||||
</el-dropdown-menu>
|
</el-dropdown-menu>
|
||||||
</el-dropdown>
|
</el-dropdown>
|
||||||
@ -58,17 +62,13 @@
|
|||||||
</el-table>
|
</el-table>
|
||||||
<pagination :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
|
<pagination :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
|
||||||
|
|
||||||
<el-dialog title="角色权限分配" :visible.sync="showRoleScope" width="600px">
|
<!-- 角色菜单弹框 -->
|
||||||
|
<el-dialog title="角色权限分配" :visible.sync="showRoleScope" width="500px">
|
||||||
<el-form :model="form" label-width="80px">
|
<el-form :model="form" label-width="80px">
|
||||||
<el-form-item label="权限字符">
|
<el-form-item label="权限字符">
|
||||||
{{form.roleKey}}
|
{{form.roleKey}}
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="权限范围">
|
<el-form-item label="数据权限">
|
||||||
<el-select v-model="form.dataScope" @change="dataScopeSelectChange">
|
|
||||||
<el-option v-for="item in dataScopeOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="数据权限" v-show="form.dataScope == 2">
|
|
||||||
<el-checkbox v-model="menuExpand" @change="handleCheckedTreeExpand($event, 'menu')">展开/折叠</el-checkbox>
|
<el-checkbox v-model="menuExpand" @change="handleCheckedTreeExpand($event, 'menu')">展开/折叠</el-checkbox>
|
||||||
<el-checkbox v-model="menuNodeAll" @change="handleCheckedTreeNodeAll($event, 'menu')">全选/全不选</el-checkbox>
|
<el-checkbox v-model="menuNodeAll" @change="handleCheckedTreeNodeAll($event, 'menu')">全选/全不选</el-checkbox>
|
||||||
<el-checkbox v-model="form.menuCheckStrictly" @change="handleCheckedTreeConnect($event, 'menu')">父子联动</el-checkbox>
|
<el-checkbox v-model="form.menuCheckStrictly" @change="handleCheckedTreeConnect($event, 'menu')">父子联动</el-checkbox>
|
||||||
@ -83,25 +83,53 @@
|
|||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
<!-- 添加或修改角色配置对话框 -->
|
<!-- 添加或修改角色配置对话框 -->
|
||||||
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
|
<el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
|
||||||
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
||||||
|
<el-row>
|
||||||
|
<el-col :lg="12">
|
||||||
<el-form-item label="角色名称" prop="roleName">
|
<el-form-item label="角色名称" prop="roleName">
|
||||||
<el-input v-model="form.roleName" placeholder="请输入角色名称" />
|
<el-input v-model="form.roleName" placeholder="请输入角色名称" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
<el-col :lg="12">
|
||||||
<el-form-item label="权限字符" prop="roleKey">
|
<el-form-item label="权限字符" prop="roleKey">
|
||||||
<el-input v-model="form.roleKey" placeholder="请输入权限字符" />
|
<el-input v-model="form.roleKey" placeholder="请输入权限字符" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
<el-col :lg="12">
|
||||||
<el-form-item label="角色顺序" prop="roleSort">
|
<el-form-item label="角色顺序" prop="roleSort">
|
||||||
<el-input-number v-model="form.roleSort" controls-position="right" :min="0" />
|
<el-input-number v-model="form.roleSort" controls-position="right" :min="0" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
<el-col :lg="12">
|
||||||
|
<el-form-item label="数据范围">
|
||||||
|
<el-select v-model="form.dataScope" @change="dataScopeSelectChange">
|
||||||
|
<el-option v-for="item in dataScopeOptions" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue"></el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
<el-col :lg="12">
|
||||||
<el-form-item label="状态">
|
<el-form-item label="状态">
|
||||||
<el-radio-group v-model="form.status">
|
<el-radio-group v-model="form.status">
|
||||||
<el-radio v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictValue">{{ dict.dictLabel }}</el-radio>
|
<el-radio v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictValue">{{ dict.dictLabel }}</el-radio>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
<el-col :lg="24">
|
||||||
|
<el-form-item label="数据权限" v-show="form.dataScope == 2">
|
||||||
|
<el-checkbox v-model="deptExpand" @change="handleCheckedTreeExpand($event, 'dept')">展开/折叠</el-checkbox>
|
||||||
|
<el-checkbox v-model="deptNodeAll" @change="handleCheckedTreeNodeAll($event, 'dept')">全选/全不选</el-checkbox>
|
||||||
|
<el-checkbox v-model="form.deptCheckStrictly" @change="handleCheckedTreeConnect($event, 'dept')">父子联动</el-checkbox>
|
||||||
|
<el-tree class="tree-border" :data="deptOptions" show-checkbox default-expand-all ref="dept" node-key="id"
|
||||||
|
:check-strictly="!form.deptCheckStrictly" empty-text="加载中,请稍候" :props="defaultProps"></el-tree>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
<el-col :lg="24">
|
||||||
<el-form-item label="备注">
|
<el-form-item label="备注">
|
||||||
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
|
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
</el-form>
|
</el-form>
|
||||||
<div slot="footer" class="dialog-footer">
|
<div slot="footer" class="dialog-footer">
|
||||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||||
@ -127,17 +155,15 @@ import {
|
|||||||
treeselect as menuTreeselect,
|
treeselect as menuTreeselect,
|
||||||
roleMenuTreeselect,
|
roleMenuTreeselect,
|
||||||
} from "@/api/system/menu";
|
} from "@/api/system/menu";
|
||||||
// import {
|
import {
|
||||||
// treeselect as deptTreeselect,
|
treeselect as deptTreeselect,
|
||||||
// roleDeptTreeselect,
|
roleDeptTreeselect,
|
||||||
// } from "@/api/system/dept";
|
} from "@/api/system/dept";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "role",
|
name: "role",
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
// 添加、修改模式是否显示菜单分配
|
|
||||||
showMenuTree: false,
|
|
||||||
// 遮罩层
|
// 遮罩层
|
||||||
loading: true,
|
loading: true,
|
||||||
// 选中数组
|
// 选中数组
|
||||||
@ -166,30 +192,30 @@ export default {
|
|||||||
dateRange: [],
|
dateRange: [],
|
||||||
// 状态数据字典
|
// 状态数据字典
|
||||||
statusOptions: [],
|
statusOptions: [],
|
||||||
// 是否下那是菜单分配
|
// 是否显示下拉菜单分配
|
||||||
showRoleScope: false,
|
showRoleScope: false,
|
||||||
// 数据范围选项
|
// 数据范围选项
|
||||||
dataScopeOptions: [
|
dataScopeOptions: [
|
||||||
// {
|
|
||||||
// value: "1",
|
|
||||||
// label: "全部数据权限",
|
|
||||||
// },
|
|
||||||
{
|
{
|
||||||
value: "2",
|
dictValue: "1",
|
||||||
label: "自定数据权限",
|
dictLabel: "全部",
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
// value: "3",
|
// dictValue: "2",
|
||||||
// label: "本部门数据权限",
|
// dictLabel: "自定义",
|
||||||
// },
|
// },
|
||||||
|
{
|
||||||
|
dictValue: "3",
|
||||||
|
dictLabel: "本部门",
|
||||||
|
},
|
||||||
// {
|
// {
|
||||||
// value: "4",
|
// dictValue: "4",
|
||||||
// label: "本部门及以下数据权限",
|
// dictLabel: "本部门及以下数据权限",
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// value: "5",
|
|
||||||
// label: "仅本人数据权限",
|
|
||||||
// },
|
// },
|
||||||
|
{
|
||||||
|
dictValue: "5",
|
||||||
|
dictLabel: "仅本人",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
// 菜单列表
|
// 菜单列表
|
||||||
menuOptions: [],
|
menuOptions: [],
|
||||||
@ -249,11 +275,11 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
/** 查询部门树结构 */
|
/** 查询部门树结构 */
|
||||||
// getDeptTreeselect() {
|
getDeptTreeselect() {
|
||||||
// deptTreeselect().then((response) => {
|
deptTreeselect().then((response) => {
|
||||||
// this.deptOptions = response.data;
|
this.deptOptions = response.data;
|
||||||
// });
|
});
|
||||||
// },
|
},
|
||||||
// 所有菜单节点数据
|
// 所有菜单节点数据
|
||||||
getMenuAllCheckedKeys() {
|
getMenuAllCheckedKeys() {
|
||||||
// 目前被选中的菜单节点
|
// 目前被选中的菜单节点
|
||||||
@ -264,14 +290,14 @@ export default {
|
|||||||
return checkedKeys;
|
return checkedKeys;
|
||||||
},
|
},
|
||||||
// 所有部门节点数据
|
// 所有部门节点数据
|
||||||
// getDeptAllCheckedKeys() {
|
getDeptAllCheckedKeys() {
|
||||||
// // 目前被选中的部门节点
|
// 目前被选中的部门节点
|
||||||
// let checkedKeys = this.$refs.dept.getCheckedKeys();
|
let checkedKeys = this.$refs.dept.getCheckedKeys();
|
||||||
// // 半选中的部门节点
|
// 半选中的部门节点
|
||||||
// let halfCheckedKeys = this.$refs.dept.getHalfCheckedKeys();
|
let halfCheckedKeys = this.$refs.dept.getHalfCheckedKeys();
|
||||||
// checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
|
checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
|
||||||
// return checkedKeys;
|
return checkedKeys;
|
||||||
// },
|
},
|
||||||
/** 根据角色ID查询菜单树结构 */
|
/** 根据角色ID查询菜单树结构 */
|
||||||
getRoleMenuTreeselect(roleId) {
|
getRoleMenuTreeselect(roleId) {
|
||||||
return roleMenuTreeselect(roleId).then((response) => {
|
return roleMenuTreeselect(roleId).then((response) => {
|
||||||
@ -280,12 +306,13 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
/** 根据角色ID查询部门树结构 */
|
/** 根据角色ID查询部门树结构 */
|
||||||
// getRoleDeptTreeselect(roleId) {
|
getRoleDeptTreeselect(roleId) {
|
||||||
// return roleDeptTreeselect(roleId).then((response) => {
|
return roleDeptTreeselect(roleId).then((response) => {
|
||||||
// this.deptOptions = response.depts;
|
console.log('角色', response);
|
||||||
// return response;
|
this.deptOptions = response.data.depts;
|
||||||
// });
|
return response;
|
||||||
// },
|
});
|
||||||
|
},
|
||||||
// 角色状态修改
|
// 角色状态修改
|
||||||
handleStatusChange(row) {
|
handleStatusChange(row) {
|
||||||
let text = row.status === "0" ? "启用" : "停用";
|
let text = row.status === "0" ? "启用" : "停用";
|
||||||
@ -329,10 +356,11 @@ export default {
|
|||||||
roleId: undefined,
|
roleId: undefined,
|
||||||
roleName: undefined,
|
roleName: undefined,
|
||||||
roleKey: undefined,
|
roleKey: undefined,
|
||||||
roleSort: 0,
|
roleSort: 99,
|
||||||
status: "0",
|
status: "0",
|
||||||
menuIds: [],
|
menuIds: [],
|
||||||
deptIds: [],
|
deptIds: [],
|
||||||
|
dataScope: "1",
|
||||||
menuCheckStrictly: true,
|
menuCheckStrictly: true,
|
||||||
deptCheckStrictly: true,
|
deptCheckStrictly: true,
|
||||||
remark: undefined,
|
remark: undefined,
|
||||||
@ -402,23 +430,27 @@ export default {
|
|||||||
/** 新增按钮操作 */
|
/** 新增按钮操作 */
|
||||||
handleAdd() {
|
handleAdd() {
|
||||||
this.reset();
|
this.reset();
|
||||||
// this.getMenuTreeselect();
|
this.getDeptTreeselect();
|
||||||
this.open = true;
|
this.open = true;
|
||||||
this.title = "添加角色";
|
this.title = "添加角色";
|
||||||
this.showRoleScope = false;
|
this.showRoleScope = false;
|
||||||
this.showMenuTree = true;
|
|
||||||
},
|
},
|
||||||
/** 修改按钮操作 ok */
|
/** 修改按钮操作 ok */
|
||||||
handleUpdate(row) {
|
handleUpdate(row) {
|
||||||
this.reset();
|
this.reset();
|
||||||
this.showRoleScope = false;
|
this.showRoleScope = false;
|
||||||
this.showMenuTree = false; //新加
|
|
||||||
const roleId = row.roleId || this.ids;
|
const roleId = row.roleId || this.ids;
|
||||||
// const roleMenu = this.getRoleMenuTreeselect(roleId);
|
const roleDeptTreeselect = this.getRoleDeptTreeselect(row.roleId);
|
||||||
getRole(roleId).then((response) => {
|
getRole(roleId).then((response) => {
|
||||||
this.form = response.data;
|
this.form = response.data;
|
||||||
this.open = true;
|
this.open = true;
|
||||||
this.title = "修改角色";
|
this.title = "修改角色";
|
||||||
|
|
||||||
|
this.$nextTick(() => {
|
||||||
|
roleDeptTreeselect.then((res) => {
|
||||||
|
this.$refs.dept.setCheckedKeys(res.data.checkedKeys);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/** 选择角色权限范围触发 */
|
/** 选择角色权限范围触发 */
|
||||||
@ -427,6 +459,10 @@ export default {
|
|||||||
this.$refs.dept.setCheckedKeys([]);
|
this.$refs.dept.setCheckedKeys([]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// 数据权限
|
||||||
|
dataScopeFormat(row, column) {
|
||||||
|
return this.selectDictLabel(this.dataScopeOptions, row.dataScope);
|
||||||
|
},
|
||||||
/** 分配角色权限按钮操作 */
|
/** 分配角色权限按钮操作 */
|
||||||
//新增 和上面代码基本相同
|
//新增 和上面代码基本相同
|
||||||
handleDataScope(row) {
|
handleDataScope(row) {
|
||||||
@ -451,8 +487,7 @@ export default {
|
|||||||
roleId: row.roleId,
|
roleId: row.roleId,
|
||||||
roleName: row.roleName,
|
roleName: row.roleName,
|
||||||
roleKey: row.roleKey,
|
roleKey: row.roleKey,
|
||||||
dataScope: row.dataScope,
|
menuCheckStrictly: row.menuCheckStrictly,
|
||||||
menuCheckStrictly: true,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
/** 分配用户操作 */
|
/** 分配用户操作 */
|
||||||
@ -466,7 +501,7 @@ export default {
|
|||||||
if (valid) {
|
if (valid) {
|
||||||
if (this.form.roleId != undefined && this.form.roleId > 0) {
|
if (this.form.roleId != undefined && this.form.roleId > 0) {
|
||||||
this.form.type = "edit";
|
this.form.type = "edit";
|
||||||
// this.form.menuIds = this.getMenuAllCheckedKeys();
|
this.form.deptIds = this.getDeptAllCheckedKeys();
|
||||||
updateRole(this.form).then((response) => {
|
updateRole(this.form).then((response) => {
|
||||||
this.msgSuccess("修改成功");
|
this.msgSuccess("修改成功");
|
||||||
this.open = false;
|
this.open = false;
|
||||||
@ -474,7 +509,7 @@ export default {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.form.type = "add";
|
this.form.type = "add";
|
||||||
//this.form.menuIds = this.getMenuAllCheckedKeys();
|
this.form.deptIds = this.getDeptAllCheckedKeys();
|
||||||
addRole(this.form).then((response) => {
|
addRole(this.form).then((response) => {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
this.open = false;
|
this.open = false;
|
||||||
@ -493,7 +528,6 @@ export default {
|
|||||||
submitDataScope: function () {
|
submitDataScope: function () {
|
||||||
if (this.form.roleId != undefined) {
|
if (this.form.roleId != undefined) {
|
||||||
this.form.menuIds = this.getMenuAllCheckedKeys();
|
this.form.menuIds = this.getMenuAllCheckedKeys();
|
||||||
// this.form.deptIds = this.getDeptAllCheckedKeys();
|
|
||||||
dataScope(this.form).then((response) => {
|
dataScope(this.form).then((response) => {
|
||||||
this.msgSuccess("修改成功");
|
this.msgSuccess("修改成功");
|
||||||
this.getList();
|
this.getList();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user