Merge branch 'framework' of https://gitee.com/ccnetcore/Yi into framework

This commit is contained in:
橙子
2023-02-16 23:07:49 +08:00
50 changed files with 920 additions and 221 deletions

View File

@@ -43,7 +43,11 @@ namespace Yi.Framework.Core.Sqlsugar.Repositories
{
return await _DbQueryable.Where(whereExpression).OrderByIF(orderBy is not null, orderBy + " " + orderByType.ToString().ToLower()).ToPageListAsync(page.PageNum, page.PageSize);
}
public async Task<List<T>> GetPageListAsync(List<IConditionalModel> whereExpression, IPagedAndSortedResultRequestDto page, string? orderBy, OrderByEnum orderByType = OrderByEnum.Asc)
{
return await _DbQueryable.Where(whereExpression).OrderByIF(orderBy is not null, orderBy + " " + orderByType.ToString().ToLower()).ToPageListAsync(page.PageNum, page.PageSize);
}
public async Task<bool> UpdateIgnoreNullAsync(T updateObj)
{

View File

@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Core.Enums;
namespace Yi.Framework.Core.Attributes
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property)]
public class QueryParameterAttribute:Attribute
{
public QueryParameterAttribute()
{
}
public QueryParameterAttribute(QueryOperatorEnum queryOperatorEnum)
{
QueryOperator = queryOperatorEnum;
}
public QueryOperatorEnum QueryOperator { get; set; }
/// <summary>
/// 验证值为0时是否作为查询条件
/// true-作为查询条件 false-不作为查询条件
/// </summary>
public bool VerifyIsZero { get; set; } = false;
/// <summary>
///
/// </summary>
public string ColumnName { get; set; }
public ColumnTypeEnum ColumnType { get; set; }
}
public enum ColumnTypeEnum
{
datetime,
@bool
}
}

View File

@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Core.Enums
{
public enum QueryOperatorEnum
{
/// <summary>
/// 相等
/// </summary>
Equal,
/// <summary>
/// 匹配
/// </summary>
Like,
/// <summary>
/// 大于
/// </summary>
GreaterThan,
/// <summary>
/// 大于或等于
/// </summary>
GreaterThanOrEqual,
/// <summary>
/// 小于
/// </summary>
LessThan,
/// <summary>
/// 小于或等于
/// </summary>
LessThanOrEqual,
/// <summary>
/// 等于集合
/// </summary>
In,
/// <summary>
/// 不等于集合
/// </summary>
NotIn,
/// <summary>
/// 左边匹配
/// </summary>
LikeLeft,
/// <summary>
/// 右边匹配
/// </summary>
LikeRight,
/// <summary>
/// 不相等
/// </summary>
NoEqual,
/// <summary>
/// 为空或空
/// </summary>
IsNullOrEmpty,
/// <summary>
/// 不为空
/// </summary>
IsNot,
/// <summary>
/// 不匹配
/// </summary>
NoLike,
/// <summary>
/// 时间段 值用 "|" 隔开
/// </summary>
DateRange
}
}

View File

@@ -8,6 +8,6 @@ namespace Yi.Framework.Data.Entities
{
public interface IState
{
public bool? State { get; set; }
public bool State { get; set; }
}
}

View File

@@ -1,4 +1,5 @@
using System;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -14,5 +15,7 @@ namespace Yi.Framework.Ddd.Dtos
string? SortBy { get; set; }
OrderByEnum SortType { get; set; }
List<IConditionalModel> Conditions { get; set; }
}
}

View File

@@ -1,4 +1,5 @@
using System;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -13,5 +14,6 @@ namespace Yi.Framework.Ddd.Dtos
public int PageSize { get; set; } = int.MaxValue;
public string? SortBy { get; set; }
public OrderByEnum SortType { get; set; } = OrderByEnum.Desc;
public List<IConditionalModel> Conditions { get; set; }
}
}

View File

@@ -32,7 +32,8 @@ namespace Yi.Framework.Ddd.Repositories
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, IPagedAndSortedResultRequestDto page);
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, IPagedAndSortedResultRequestDto page, Expression<Func<T, object>>? orderByExpression = null, OrderByEnum orderByType = OrderByEnum.Asc);
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, IPagedAndSortedResultRequestDto page, string? orderBy, OrderByEnum orderByType = OrderByEnum.Asc);
Task<List<T>> GetPageListAsync(List<IConditionalModel> whereExpression, IPagedAndSortedResultRequestDto page, string? orderBy, OrderByEnum orderByType = OrderByEnum.Asc);
//插入
Task<bool> InsertAsync(T insertObj);

View File

@@ -6,6 +6,7 @@ using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Core.Attributes;
using Yi.Framework.Core.Helper;
using Yi.Framework.Core.Model;
using Yi.Framework.Ddd.Dtos;
@@ -84,38 +85,97 @@ where TEntityDto : IEntityDto<TKey>
/// <returns></returns>
public virtual async Task<PagedResultDto<TGetListOutputDto>> GetListAsync(TGetListInput input)
{
var totalCount = await _repository.CountAsync(_ => true);
var totalCount = -1;
var entities = new List<TEntity>();
var entityDtos = new List<TGetListOutputDto>();
if (totalCount > 0)
bool isPageList = true;
//这里还可以追加如果是审计日志,继续拼接条件即可
if (input is IPageTimeResultRequestDto timeInput)
{
//这里还可以追加如果是审计日志,继续拼接条件即可
if (input is IPageTimeResultRequestDto timeInput)
if (timeInput.StartTime is not null)
{
if (timeInput.StartTime is not null)
{
timeInput.EndTime = timeInput.EndTime ?? DateTime.Now;
}
timeInput.EndTime = timeInput.EndTime ?? DateTime.Now;
}
if (input is IPagedAndSortedResultRequestDto sortInput)
{
entities = await _repository.GetPageListAsync(_ => true, sortInput,sortInput.SortBy, sortInput.SortType);
}
else
{
entities = await _repository.GetListAsync();
}
entityDtos = await MapToGetListOutputDtosAsync(entities);
}
if (input is IPagedAndSortedResultRequestDto sortInput)
{
var dependsOnbuild = sortInput.GetType().GetCustomAttributes(typeof(QueryParameterAttribute), false).FirstOrDefault() as QueryParameterAttribute;
if (dependsOnbuild is null)
{
entities = await _repository.GetPageListAsync(_ => true, sortInput, sortInput.SortBy, sortInput.SortType);
}
else
{
sortInput.Conditions = new List<IConditionalModel>();
System.Reflection.PropertyInfo[] properties = sortInput.GetType().GetProperties();
foreach (System.Reflection.PropertyInfo item in properties)
{
var query = item.GetCustomAttributes(typeof(QueryParameterAttribute), false).FirstOrDefault() as QueryParameterAttribute;
if (query is not null)
{
object value = item.GetValue(sortInput, null);
if (value is not null)
{
if (value.ToString() == "0")
{
if (query.VerifyIsZero)
{
sortInput.Conditions.Add(new ConditionalModel { FieldValue = value.ToString(), FieldName = item.Name, ConditionalType = (ConditionalType)(int)query.QueryOperator });
}
}
else {
switch (query.ColumnType)
{
case ColumnTypeEnum.datetime:
if (!string.IsNullOrEmpty(query.ColumnName))
{
DateTime dt = DateTime.Now;
DateTime.TryParse(value.ToString(), out dt);
sortInput.Conditions.Add(new ConditionalModel { FieldValue = dt.ToString("yyyy-MM-dd HH:mm:ss"), FieldName = query.ColumnName, ConditionalType = (ConditionalType)(int)query.QueryOperator });
}
else
{
sortInput.Conditions.Add(new ConditionalModel { FieldValue = value.ToString(), FieldName = item.Name, ConditionalType = (ConditionalType)(int)query.QueryOperator });
}
break;
case ColumnTypeEnum.@bool:
string _Value = "";
if ((bool)value)
{
_Value = "1";
}
else {
_Value = "0";
}
sortInput.Conditions.Add(new ConditionalModel { FieldValue = _Value, FieldName = item.Name, ConditionalType = (ConditionalType)(int)query.QueryOperator });
break;
default:
sortInput.Conditions.Add(new ConditionalModel { FieldValue = value.ToString(), FieldName = item.Name, ConditionalType = (ConditionalType)(int)query.QueryOperator });
break;
}
}
}
}
}
entities = await _repository.GetPageListAsync(sortInput.Conditions, sortInput, sortInput.SortBy, sortInput.SortType);
}
}
else
{
isPageList = false;
entities = await _repository.GetListAsync();
}
entityDtos = await MapToGetListOutputDtosAsync(entities);
//如果是分页查询,还需要统计数量
if (isPageList)
{
totalCount = await _repository.CountAsync(_ => true);
}
return new PagedResultDto<TGetListOutputDto>(
totalCount,
entityDtos

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.RBAC.Application.Contracts.Identity.Dtos.Account
{
public class RestPasswordDto
{
public string Password = string.Empty;
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.RBAC.Application.Contracts.Identity.Dtos.Account
{
public class UpdatePasswordDto
{
public string NewPassword { get; set; } = string.Empty;
public string OldPassword { get; set; } = string.Empty;
}
}

View File

@@ -3,16 +3,28 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Core.Enums;
using Yi.Framework.Ddd.Dtos;
namespace Yi.RBAC.Application.Contracts.Identity.Dtos
{
[QueryParameter]
public class DeptGetListInputVo : PagedAllResultRequestDto
{
[QueryParameter(QueryOperatorEnum.Equal)]
public long Id { get; set; }
[QueryParameter(QueryOperatorEnum.Equal, ColumnType = ColumnTypeEnum.@bool)]
public bool? State { get; set; }
[QueryParameter(QueryOperatorEnum.Like)]
public string? DeptName { get; set; }
public string? DeptCode { get; set; }
[QueryParameter(QueryOperatorEnum.Equal)]
public string? DeptCode { get; set; }
[QueryParameter(QueryOperatorEnum.Equal)]
public string? Leader { get; set; }
[QueryParameter(QueryOperatorEnum.GreaterThanOrEqual, ColumnName = "CreationTime",ColumnType =ColumnTypeEnum.datetime)]
public DateTime? StartTime { get; set; }
[QueryParameter(QueryOperatorEnum.LessThanOrEqual, ColumnName = "CreationTime", ColumnType = ColumnTypeEnum.datetime)]
public DateTime? EndTime { get; set; }
}
}

View File

@@ -10,13 +10,12 @@ namespace Yi.RBAC.Application.Contracts.Identity.Dtos
public class DeptGetOutputDto : IEntityDto<long>
{
public long Id { get; set; }
public DateTime CreationTime { get; set; } = DateTime.Now;
public long? CreatorId { get; set; }
public bool State { get; set; }
public string DeptName { get; set; }=string.Empty;
public string DeptCode { get; set; } = string.Empty;
public string? Leader { get; set; }
public long ParentId { get; set; }
public string? Remark { get; set; }
public long? deptId { get; set; }
}
}

View File

@@ -11,7 +11,6 @@ namespace Yi.RBAC.Application.Contracts.Identity.Dtos
{
public long Id { get; set; }
public DateTime CreationTime { get; set; } = DateTime.Now;
public long? CreatorId { get; set; }
public bool State { get; set; }
public string PostCode { get; set; }=string.Empty;
public string PostName { get; set; } = string.Empty;

View File

@@ -12,13 +12,16 @@ namespace Yi.RBAC.Application.Contracts.Identity.Dtos
/// </summary>
public class RoleCreateInputVo
{
public long Id { get; set; }
public DateTime CreationTime { get; set; } = DateTime.Now;
public long? CreatorId { get; set; }
public string? RoleName { get; set; }
public string? RoleCode { get; set; }
public string? Remark { get; set; }
public DataScopeEnum DataScope { get; set; } = DataScopeEnum.ALL;
public bool State { get; set; }
public bool State { get; set; } = true;
public int OrderNum { get; set; }
public List<long> DeptIds { get; set; }
public List<long> MenuIds { get; set; }
}
}

View File

@@ -18,5 +18,7 @@ namespace Yi.RBAC.Application.Contracts.Identity.Dtos
public string? Remark { get; set; }
public DataScopeEnum DataScope { get; set; } = DataScopeEnum.ALL;
public bool State { get; set; }
public int OrderNum { get; set; }
}
}

View File

@@ -18,5 +18,7 @@ namespace Yi.RBAC.Application.Contracts.Identity.Dtos
public string? Remark { get; set; }
public DataScopeEnum DataScope { get; set; } = DataScopeEnum.ALL;
public bool State { get; set; }
public int OrderNum { get; set; }
}
}

View File

@@ -9,13 +9,16 @@ namespace Yi.RBAC.Application.Contracts.Identity.Dtos
{
public class RoleUpdateInputVo
{
public long Id { get; set; }
public DateTime CreationTime { get; set; } = DateTime.Now;
public long? CreatorId { get; set; }
public string? RoleName { get; set; }
public string? RoleCode { get; set; }
public string? Remark { get; set; }
public DataScopeEnum DataScope { get; set; } = DataScopeEnum.ALL;
public bool State { get; set; }
public int OrderNum { get; set; }
public List<long> DeptIds { get; set; }
public List<long> MenuIds { get; set; }
}
}

View File

@@ -27,5 +27,6 @@ namespace Yi.RBAC.Application.Contracts.Identity.Dtos
public List<long>? RoleIds { get; set; }
public List<long>? PostIds { get; set; }
public long? DeptId { get; set; }
public bool State { get; set; } = true;
}
}

View File

@@ -14,8 +14,6 @@ namespace Yi.RBAC.Application.Contracts.Identity.Dtos
public string? Name { get; set; }
public int? Age { get; set; }
public string UserName { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public string Salt { get; set; } = string.Empty;
public string? Icon { get; set; }
public string? Nick { get; set; }
public string? Email { get; set; }
@@ -25,10 +23,15 @@ namespace Yi.RBAC.Application.Contracts.Identity.Dtos
public string? Introduction { get; set; }
public string? Remark { get; set; }
public SexEnum Sex { get; set; } = SexEnum.Unknown;
public long? DeptId { get; set; }
public DateTime CreationTime { get; set; } = DateTime.Now;
public long? CreatorId { get; set; }
public bool State { get; set; }
public DateTime CreationTime { get; set; }
public long DeptId { get; set; }
public DeptGetOutputDto Dept { get; set; }
public List<PostGetListOutputDto> Posts { get; set; }
public List<RoleGetListOutputDto> Roles { get; set; }
}
}

View File

@@ -1,3 +1,4 @@
using Mapster;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -9,12 +10,12 @@ namespace Yi.RBAC.Application.Contracts.Identity.Dtos
{
public class UserUpdateInputVo
{
public long Id { get; set; }
public string? Name { get; set; }
public int? Age { get; set; }
public string UserName { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public string Salt { get; set; } = string.Empty;
public string? UserName { get; set; }
[AdaptIgnore]
public string? Password { get; set; }
public string? Icon { get; set; }
public string? Nick { get; set; }
public string? Email { get; set; }
@@ -23,11 +24,11 @@ namespace Yi.RBAC.Application.Contracts.Identity.Dtos
public long? Phone { get; set; }
public string? Introduction { get; set; }
public string? Remark { get; set; }
public SexEnum Sex { get; set; } = SexEnum.Unknown;
public SexEnum? Sex { get; set; }
public long? DeptId { get; set; }
public DateTime CreationTime { get; set; } = DateTime.Now;
public long? CreatorId { get; set; }
public List<long>? PostIds { get; set; }
public bool State { get; set; }
public List<long>? RoleIds { get; set; }
public bool? State { get; set; }
}
}

View File

@@ -58,6 +58,21 @@
</summary>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.AccountService.UpdatePasswordAsync(Yi.RBAC.Application.Contracts.Identity.Dtos.Account.UpdatePasswordDto)">
<summary>
更新密码
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.AccountService.RestPasswordAsync(System.Int64,Yi.RBAC.Application.Contracts.Identity.Dtos.Account.RestPasswordDto)">
<summary>
重置密码
</summary>
<param name="userId"></param>
<param name="input"></param>
<returns></returns>
</member>
<member name="T:Yi.RBAC.Application.Identity.DeptService">
<summary>
Dept服务实现
@@ -69,18 +84,18 @@
</summary>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.DeptService.GetListAsync(Yi.RBAC.Application.Contracts.Identity.Dtos.DeptGetListInputVo)">
<summary>
多查
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="T:Yi.RBAC.Application.Identity.MenuService">
<summary>
Menu服务实现
</summary>
</member>
<member name="M:Yi.RBAC.Application.Identity.MenuService.GetListRoleIdAsync(System.Int64)">
<summary>
查询当前角色的菜单
</summary>
<param name="roleId"></param>
<returns></returns>
</member>
<member name="T:Yi.RBAC.Application.Identity.PostService">
<summary>
Post服务实现
@@ -91,6 +106,13 @@
Role服务实现
</summary>
</member>
<member name="M:Yi.RBAC.Application.Identity.RoleService.CreateAsync(Yi.RBAC.Application.Contracts.Identity.Dtos.RoleCreateInputVo)">
<summary>
添加角色
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="T:Yi.RBAC.Application.Identity.UserService">
<summary>
User服务实现
@@ -111,5 +133,20 @@
<returns></returns>
<exception cref="T:Yi.Framework.Core.Exceptions.UserFriendlyException"></exception>
</member>
<member name="M:Yi.RBAC.Application.Identity.UserService.GetAsync(System.Int64)">
<summary>
单查
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.UserService.UpdateAsync(System.Int64,Yi.RBAC.Application.Contracts.Identity.Dtos.UserUpdateInputVo)">
<summary>
更新用户
</summary>
<param name="id"></param>
<param name="input"></param>
<returns></returns>
</member>
</members>
</doc>

View File

@@ -140,5 +140,37 @@ namespace Yi.RBAC.Application.Identity
var imgbyte = _securityCode.GetEnDigitalCodeByte(code);
return new CaptchaImageDto { Img = imgbyte, Uuid = code };
}
/// <summary>
/// 更新密码
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<bool> UpdatePasswordAsync(UpdatePasswordDto input)
{
if (input.OldPassword.Equals(input.NewPassword))
{
throw new UserFriendlyException("无效更新!输入的数据,新密码不能与老密码相同");
}
await _accountManager.UpdatePasswordAsync(_currentUser.Id, input.NewPassword, input.OldPassword);
return true;
}
/// <summary>
/// 重置密码
/// </summary>
/// <param name="userId"></param>
/// <param name="input"></param>
/// <returns></returns>
[HttpPut]
public async Task<bool> RestPasswordAsync(long userId, RestPasswordDto input)
{
if (!string.IsNullOrEmpty(input.Password))
{
throw new UserFriendlyException("重置密码不能为空!");
}
await _accountManager.RestPasswordAsync(userId, input.Password);
return true;
}
}
}

View File

@@ -28,24 +28,24 @@ namespace Yi.RBAC.Application.Identity
return await MapToGetListOutputDtosAsync(entities);
}
/// <summary>
/// 多查
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public override async Task<PagedResultDto<DeptGetListOutputDto>> GetListAsync(DeptGetListInputVo input)
{
RefAsync<int> total = 0;
var entities = await _DbQueryable
.WhereIF(!string.IsNullOrEmpty(input.DeptName), u => u.DeptName.Contains(input.DeptName!))
.WhereIF(input.State is not null, u => u.State == input.State)
.OrderBy(u => u.OrderNum, OrderByType.Asc)
.ToPageListAsync(input.PageNum, input.PageSize, total);
return new PagedResultDto<DeptGetListOutputDto>
{
Items = await MapToGetListOutputDtosAsync(entities),
Total = total
};
}
///// <summary>
///// 多查
///// </summary>
///// <param name="input"></param>
///// <returns></returns>
//public override async Task<PagedResultDto<DeptGetListOutputDto>> GetListAsync(DeptGetListInputVo input)
//{
// RefAsync<int> total = 0;
// var entities = await _DbQueryable
// .WhereIF(!string.IsNullOrEmpty(input.DeptName), u => u.DeptName.Contains(input.DeptName!))
// .WhereIF(input.State is not null, u => u.State == input.State)
// .OrderBy(u => u.OrderNum, OrderByType.Asc)
// .ToPageListAsync(input.PageNum, input.PageSize, total);
// return new PagedResultDto<DeptGetListOutputDto>
// {
// Items = await MapToGetListOutputDtosAsync(entities),
// Total = total
// };
//}
}
}

View File

@@ -3,6 +3,7 @@ using NET.AutoWebApi.Setting;
using Yi.RBAC.Application.Contracts.Identity.Dtos;
using Yi.RBAC.Domain.Identity.Entities;
using Yi.Framework.Ddd.Services;
using SqlSugar;
namespace Yi.RBAC.Application.Identity
{
@@ -13,5 +14,16 @@ namespace Yi.RBAC.Application.Identity
public class MenuService : CrudAppService<MenuEntity, MenuGetOutputDto, MenuGetListOutputDto, long, MenuGetListInputVo, MenuCreateInputVo, MenuUpdateInputVo>,
IMenuService, IAutoApiService
{
/// <summary>
/// 查询当前角色的菜单
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public async Task<List<MenuGetListOutputDto>> GetListRoleIdAsync(long roleId)
{
var entities= await _DbQueryable.Where(m => SqlFunc.Subqueryable<RoleMenuEntity>().Where(rm => rm.RoleId == roleId && rm.MenuId == m.Id).Any()).ToListAsync();
return await MapToGetListOutputDtosAsync(entities);
}
}
}

View File

@@ -3,6 +3,9 @@ using NET.AutoWebApi.Setting;
using Yi.RBAC.Application.Contracts.Identity.Dtos;
using Yi.RBAC.Domain.Identity.Entities;
using Yi.Framework.Ddd.Services;
using Yi.RBAC.Domain.Identity;
using Microsoft.AspNetCore.Identity;
using Yi.Framework.Uow;
namespace Yi.RBAC.Application.Identity
{
@@ -13,5 +16,30 @@ namespace Yi.RBAC.Application.Identity
public class RoleService : CrudAppService<RoleEntity, RoleGetOutputDto, RoleGetListOutputDto, long, RoleGetListInputVo, RoleCreateInputVo, RoleUpdateInputVo>,
IRoleService, IAutoApiService
{
[Autowired]
private RoleManager _roleManager { get; set; }
[Autowired]
private IUnitOfWorkManager _unitOfWorkManager { get; set; }
/// <summary>
/// 添加角色
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public override async Task<RoleGetOutputDto> CreateAsync(RoleCreateInputVo input)
{
RoleGetOutputDto outputDto;
using (var uow = _unitOfWorkManager.CreateContext())
{
var entity = await MapToEntityAsync(input);
await _repository.InsertAsync(entity);
outputDto = await MapToGetOutputDtoAsync(entity);
await _roleManager.GiveRoleSetMenuAsync(new List<long> { entity.Id }, input.MenuIds);
uow.Commit();
}
return outputDto;
}
}
}

View File

@@ -8,6 +8,8 @@ using Yi.RBAC.Domain.Identity;
using Yi.Framework.Uow;
using Yi.Framework.Ddd.Dtos;
using Yi.RBAC.Domain.Identity.Repositories;
using SqlSugar;
using Mapster;
namespace Yi.RBAC.Application.Identity
{
@@ -36,7 +38,7 @@ namespace Yi.RBAC.Application.Identity
{
var entity = await MapToEntityAsync(input);
int total = 0;
RefAsync<int> total = 0;
var entities = await _DbQueryable.WhereIF(!string.IsNullOrEmpty(input.UserName), x => x.UserName.Contains(input.UserName!)).
WhereIF(input.Phone is not null, x => x.Phone.ToString()!.Contains(input.Phone.ToString()!)).
@@ -80,5 +82,47 @@ namespace Yi.RBAC.Application.Identity
return result;
}
}
/// <summary>
/// 单查
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public override async Task<UserGetOutputDto> GetAsync(long id)
{
//使用导航树形查询
var entity = await _DbQueryable.Includes(u => u.Roles).Includes(u => u.Posts).Includes(u => u.Dept).InSingleAsync(id);
return await MapToGetOutputDtoAsync(entity);
}
/// <summary>
/// 更新用户
/// </summary>
/// <param name="id"></param>
/// <param name="input"></param>
/// <returns></returns>
public async override Task<UserGetOutputDto> UpdateAsync(long id, UserUpdateInputVo input)
{
if (await _repository.IsAnyAsync(u => input.UserName!.Equals(u.UserName) && !id.Equals(u.Id)))
{
throw new UserFriendlyException("用户已经在,更新失败");
}
var entity = await _repository.GetByIdAsync(id);
//更新密码,特殊处理
if (input.Password is not null)
{
entity.Password = input.Password;
entity.BuildPassword();
}
await MapToEntityAsync(input, entity);
using (var uow = _unitOfWorkManager.CreateContext())
{
var res1 = await _repository.UpdateAsync(entity);
await _userManager.GiveUserSetRoleAsync(new List<long> { id }, input.RoleIds);
await _userManager.GiveUserSetPostAsync(new List<long> { id }, input.PostIds);
uow.Commit();
}
return await MapToGetOutputDtoAsync(entity);
}
}
}

View File

@@ -0,0 +1,138 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Data.DataSeeds;
using Yi.Framework.Ddd.Repositories;
using Yi.RBAC.Domain.Dictionary.Entities;
using Yi.RBAC.Domain.Identity.Entities;
namespace Yi.RBAC.Domain.DataSeeds
{
[AppService(typeof(IDataSeed))]
public class DeptDataSeed : AbstractDataSeed<DeptEntity>
{
public DeptDataSeed(IRepository<DeptEntity> repository) : base(repository)
{
}
public override List<DeptEntity> GetSeedData()
{
var entities =new List<DeptEntity>();
DeptEntity chengziDept = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "橙子科技",
DeptCode = "Yi",
OrderNum = 100,
IsDeleted = false,
ParentId = 0,
Leader = "橙子",
Remark = "如名所指"
};
entities.Add(chengziDept);
DeptEntity shenzhenDept = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "深圳总公司",
OrderNum = 100,
IsDeleted = false,
ParentId = chengziDept.Id
};
entities.Add(shenzhenDept);
DeptEntity jiangxiDept = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "江西总公司",
OrderNum = 100,
IsDeleted = false,
ParentId = chengziDept.Id
};
entities.Add(jiangxiDept);
DeptEntity szDept1 = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "研发部门",
OrderNum = 100,
IsDeleted = false,
ParentId = shenzhenDept.Id
};
entities.Add(szDept1);
DeptEntity szDept2 = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "市场部门",
OrderNum = 100,
IsDeleted = false,
ParentId = shenzhenDept.Id
};
entities.Add(szDept2);
DeptEntity szDept3 = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "测试部门",
OrderNum = 100,
IsDeleted = false,
ParentId = shenzhenDept.Id
};
entities.Add(szDept3);
DeptEntity szDept4 = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "财务部门",
OrderNum = 100,
IsDeleted = false,
ParentId = shenzhenDept.Id
};
entities.Add(szDept4);
DeptEntity szDept5 = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "运维部门",
OrderNum = 100,
IsDeleted = false,
ParentId = shenzhenDept.Id
};
entities.Add(szDept5);
DeptEntity jxDept1 = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "市场部门",
OrderNum = 100,
IsDeleted = false,
ParentId = jiangxiDept.Id
};
entities.Add(jxDept1);
DeptEntity jxDept2 = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "财务部门",
OrderNum = 100,
IsDeleted = false,
ParentId = jiangxiDept.Id
};
entities.Add(jxDept2);
return entities;
}
}
}

View File

@@ -0,0 +1,69 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Data.DataSeeds;
using Yi.Framework.Ddd.Repositories;
using Yi.RBAC.Domain.Identity.Entities;
namespace Yi.RBAC.Domain.DataSeeds
{
[AppService(typeof(IDataSeed))]
public class PostDataSeed : AbstractDataSeed<PostEntity>
{
public PostDataSeed(IRepository<PostEntity> repository) : base(repository)
{
}
public override List<PostEntity> GetSeedData()
{
var entites=new List<PostEntity>();
PostEntity Post1 = new PostEntity()
{
Id = SnowflakeHelper.NextId,
PostName = "董事长",
PostCode = "ceo",
OrderNum = 100,
IsDeleted = false
};
entites.Add(Post1);
PostEntity Post2 = new PostEntity()
{
Id = SnowflakeHelper.NextId,
PostName = "项目经理",
PostCode = "se",
OrderNum = 100,
IsDeleted = false
};
entites.Add(Post2);
PostEntity Post3 = new PostEntity()
{
Id = SnowflakeHelper.NextId,
PostName = "人力资源",
PostCode = "hr",
OrderNum = 100,
IsDeleted = false
};
entites.Add(Post3);
PostEntity Post4 = new PostEntity()
{
Id = SnowflakeHelper.NextId,
PostName = "普通员工",
PostCode = "user",
OrderNum = 100,
IsDeleted = false
};
entites.Add(Post4);
return entites;
}
}
}

View File

@@ -0,0 +1,51 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Data.DataSeeds;
using Yi.Framework.Ddd.Repositories;
using Yi.RBAC.Domain.Identity.Entities;
using Yi.RBAC.Domain.Shared.Identity.EnumClasses;
namespace Yi.RBAC.Domain.DataSeeds
{
[AppService(typeof(IDataSeed))]
public class RoleDataSeed : AbstractDataSeed<RoleEntity>
{
public RoleDataSeed(IRepository<RoleEntity> repository) : base(repository)
{
}
public override List<RoleEntity> GetSeedData()
{
var entities = new List<RoleEntity>();
RoleEntity role1 = new RoleEntity()
{
Id = SnowflakeHelper.NextId,
RoleName = "管理员",
RoleCode = "admin",
DataScope = DataScopeEnum.ALL,
OrderNum = 999,
Remark = "管理员",
IsDeleted = false
};
entities.Add(role1);
RoleEntity role2 = new RoleEntity()
{
Id = SnowflakeHelper.NextId,
RoleName = "测试角色",
RoleCode = "test",
DataScope = DataScopeEnum.ALL,
OrderNum = 1,
Remark = "测试用的角色",
IsDeleted = false
};
entities.Add(role2);
return entities;
}
}
}

View File

@@ -33,7 +33,7 @@ namespace Yi.RBAC.Domain.Dictionary.Entities
/// <summary>
/// 状态
/// </summary>
public bool? State { get; set; } = true;
public bool State { get; set; } = true;
/// <summary>
/// 描述

View File

@@ -669,6 +669,14 @@
<param name="userId"></param>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Domain.Identity.RoleManager.GiveRoleSetMenuAsync(System.Collections.Generic.List{System.Int64},System.Collections.Generic.List{System.Int64})">
<summary>
给角色设置菜单
</summary>
<param name="roleIds"></param>
<param name="menuIds"></param>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Domain.Identity.UserManager.GiveUserSetRoleAsync(System.Collections.Generic.List{System.Int64},System.Collections.Generic.List{System.Int64})">
<summary>
给用户设置角色

View File

@@ -1,4 +1,5 @@
using System;
using Mapster;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
@@ -103,6 +104,30 @@ namespace Yi.RBAC.Domain.Identity
return claims;
}
public async Task UpdatePasswordAsync(long userId, string newPassword, string oldPassword)
{
var user = await _repository.GetByIdAsync(userId);
if (!user.JudgePassword(oldPassword))
{
throw new UserFriendlyException("无效更新!新密码不能与老密码相同");
}
user.Password = newPassword;
user.BuildPassword();
await _repository.UpdateAsync(user);
}
public async Task<bool> RestPasswordAsync(long userId, string password)
{
var user = await _repository.GetByIdAsync(userId);
user.Id = userId;
user.Password = password;
user.BuildPassword();
return await _repository.UpdateAsync(user);
}
}
}

View File

@@ -54,7 +54,7 @@ namespace Yi.RBAC.Domain.Identity.Entities
/// <summary>
/// 状态
/// </summary>
public bool? State { get; set; }
public bool State { get; set; } = true;
/// <summary>
/// 部门名称

View File

@@ -56,7 +56,7 @@ namespace Yi.RBAC.Domain.Identity.Entities
/// <summary>
/// 状态
/// </summary>
public bool? State { get; set; }
public bool State { get; set; }
/// <summary>
/// 菜单名

View File

@@ -55,7 +55,7 @@ namespace Yi.RBAC.Domain.Identity.Entities
/// <summary>
/// 状态
/// </summary>
public bool? State { get; set; }
public bool State { get; set; }=true;
/// <summary>
/// 岗位编码

View File

@@ -79,7 +79,7 @@ namespace Yi.RBAC.Domain.Identity.Entities
/// <summary>
/// 状态
/// </summary>
public bool? State { get; set; }
public bool State { get; set; }=true;
[Navigate(typeof(RoleMenuEntity), nameof(RoleMenuEntity.RoleId), nameof(RoleMenuEntity.MenuId))]

View File

@@ -133,7 +133,7 @@ namespace Yi.RBAC.Domain.Identity.Entities
/// <summary>
/// 状态
/// </summary>
public bool? State { get; set; } = true;
public bool State { get; set; } = true;
/// <summary>

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Ddd.Repositories;
using Yi.RBAC.Domain.Identity.Entities;
namespace Yi.RBAC.Domain.Identity
{
[AppService]
public class RoleManager
{
private IRepository<RoleEntity> _repository;
private IRepository<RoleMenuEntity> _roleMenuRepository;
public RoleManager(IRepository<RoleEntity> repository, IRepository<RoleMenuEntity> roleMenuRepository)
{
_repository = repository;
_roleMenuRepository = roleMenuRepository;
}
/// <summary>
/// 给角色设置菜单
/// </summary>
/// <param name="roleIds"></param>
/// <param name="menuIds"></param>
/// <returns></returns>
public async Task GiveRoleSetMenuAsync(List<long> roleIds, List<long> menuIds)
{
//这个是需要事务的在service中进行工作单元
await _roleMenuRepository.DeleteAsync(u => roleIds.Contains(u.RoleId));
//遍历用户
foreach (var roleId in roleIds)
{
//添加新的关系
List<RoleMenuEntity> roleMenuEntity = new();
foreach (var menu in menuIds)
{
roleMenuEntity.Add(new RoleMenuEntity() {Id=SnowflakeHelper.NextId, RoleId = roleId, MenuId = menu });
}
//一次性批量添加
await _roleMenuRepository.InsertRangeAsync(roleMenuEntity);
}
}
}
}

View File

@@ -3,7 +3,7 @@ import request from '@/utils/request'
// 查询部门列表
export function listDept(query) {
return request({
url: '/dept/SelctGetList',
url: '/dept',
method: 'get',
params: query
})
@@ -20,7 +20,7 @@ export function listDept(query) {
// 查询部门详细
export function getDept(deptId) {
return request({
url: '/dept/getById/' + deptId,
url: '/dept/' + deptId,
method: 'get'
})
}
@@ -28,7 +28,7 @@ export function getDept(deptId) {
// 新增部门
export function addDept(data) {
return request({
url: '/dept/add',
url: '/dept',
method: 'post',
data: data
})
@@ -37,7 +37,7 @@ export function addDept(data) {
// 修改部门
export function updateDept(data) {
return request({
url: '/dept/update',
url: '/dept',
method: 'put',
data: data
})
@@ -45,14 +45,9 @@ export function updateDept(data) {
// 删除部门
export function delDept(deptId) {
if("string"==typeof(deptId))
{
deptId=[deptId];
}
return request({
url: '/dept/delList',
method: 'delete',
data:deptId
url: `/dept/${deptId}`,
method: 'delete'
})
}
@@ -60,7 +55,7 @@ export function delDept(deptId) {
// 根据角色ID查询菜单下拉树结构
export function roleDeptTreeselect(roleId) {
return request({
url: '/dept/getListByRoleId/' + roleId,
url: '/dept/role-id/' + roleId,
method: 'get'
})
}

View File

@@ -3,7 +3,7 @@ import request from '@/utils/request'
// 查询菜单列表
export function listMenu(query) {
return request({
url: '/menu/selctGetList',
url: '/menu',
method: 'get',
params: query
})
@@ -12,7 +12,7 @@ export function listMenu(query) {
// 查询菜单详细
export function getMenu(menuId) {
return request({
url: '/menu/getById/' + menuId,
url: '/menu/' + menuId,
method: 'get'
})
}
@@ -28,7 +28,7 @@ export function treeselect() {
// 根据角色ID查询菜单下拉树结构
export function roleMenuTreeselect(roleId) {
return request({
url: '/menu/getListByRoleId/' + roleId,
url: '/menu/role-id/' + roleId,
method: 'get'
})
}
@@ -36,7 +36,7 @@ export function roleMenuTreeselect(roleId) {
// 新增菜单
export function addMenu(data) {
return request({
url: '/menu/add',
url: '/menu',
method: 'post',
data: data
})
@@ -45,7 +45,7 @@ export function addMenu(data) {
// 修改菜单
export function updateMenu(data) {
return request({
url: '/menu/update',
url: '/menu',
method: 'put',
data: data
})
@@ -53,13 +53,9 @@ export function updateMenu(data) {
// 删除菜单
export function delMenu(menuId) {
if("string"==typeof(menuId))
{
menuId=[menuId];
}
return request({
url: '/menu/delList',
method: 'delete',
data:menuId
url: `/menu/${menuId}`,
method: 'delete'
})
}

View File

@@ -3,7 +3,7 @@ import request from '@/utils/request'
// 查询岗位列表
export function listPost(query) {
return request({
url: '/post/pageList',
url: '/post',
method: 'get',
params: query
})
@@ -12,7 +12,7 @@ export function listPost(query) {
// 查询岗位详细
export function getPost(postId) {
return request({
url: '/post/getById/' + postId,
url: '/post/' + postId,
method: 'get'
})
}
@@ -20,7 +20,7 @@ export function getPost(postId) {
// 新增岗位
export function addPost(data) {
return request({
url: '/post/add',
url: '/post',
method: 'post',
data: data
})
@@ -29,7 +29,7 @@ export function addPost(data) {
// 修改岗位
export function updatePost(data) {
return request({
url: '/post/update',
url: '/post',
method: 'put',
data: data
})
@@ -37,21 +37,16 @@ export function updatePost(data) {
// 删除岗位
export function delPost(postId) {
if("string"==typeof(postId))
{
postId=[postId];
}
return request({
url: '/post/delList',
method: 'delete',
data:postId
url: `/post/${postId}`,
method: 'delete'
})
}
// 获取角色选择框列表
export function postOptionselect() {
return request({
url: '/post/getList',
url: '/post',
method: 'get'
})

View File

@@ -3,7 +3,7 @@ import request from '@/utils/request'
// 查询角色列表
export function listRole(query) {
return request({
url: '/role/pageList',
url: '/role',
method: 'get',
params: query
})
@@ -14,7 +14,7 @@ export function listRole(query) {
// 查询角色详细
export function getRole(roleId) {
return request({
url: '/role/getById/' + roleId,
url: '/role/' + roleId,
method: 'get'
})
}
@@ -22,7 +22,7 @@ export function getRole(roleId) {
// 新增角色
export function addRole(data) {
return request({
url: '/role/add',
url: '/role',
method: 'post',
data: data
})
@@ -31,7 +31,7 @@ export function addRole(data) {
// 修改角色
export function updateRole(data) {
return request({
url: '/role/update',
url: '/role',
method: 'put',
data: data
})
@@ -56,14 +56,9 @@ export function changeRoleStatus(roleId, isDel) {
// 删除角色
export function delRole(roleId) {
if("string"==typeof(roleId))
{
roleId=[roleId];
}
return request({
url: '/role/delList',
url: `/role/${roleId}`,
method: 'delete',
data:roleId
})
}
@@ -122,7 +117,7 @@ export function authUserSelectAll(data) {
// 获取角色选择框列表
export function roleOptionselect() {
return request({
url: '/role/getList',
url: '/role',
method: 'get'
})

View File

@@ -4,7 +4,7 @@ import { parseStrEmpty } from "@/utils/ruoyi";
// 查询用户列表
export function listUser(query) {
return request({
url: '/user/pageList',
url: '/user',
method: 'get',
params: query
})
@@ -13,7 +13,7 @@ export function listUser(query) {
// 查询用户详细
export function getUser(userId) {
return request({
url: '/user/getById/' + parseStrEmpty(userId),
url: '/user/' + parseStrEmpty(userId),
method: 'get'
})
}
@@ -21,16 +21,16 @@ export function getUser(userId) {
// 新增用户
export function addUser(data) {
return request({
url: '/user/add',
url: '/user',
method: 'post',
data: data
})
}
// 修改用户
export function updateUser(data) {
export function updateUser(id, data) {
return request({
url: '/user/update',
url: `/user/${id}`,
method: 'put',
data: data
})
@@ -38,27 +38,21 @@ export function updateUser(data) {
// 删除用户
export function delUser(userId) {
if("string"==typeof(userId))
{
userId=[userId];
}
return request({
url: '/user/delList',
url: `/user/${userId}`,
method: 'delete',
data:userId
})
}
// 用户密码重置
export function resetUserPwd(id, password) {
const data = {
id,
password
}
return request({
url: '/user/restPassword',
url: `/account/rest-password/${id}`,
method: 'put',
data: data
})
@@ -85,7 +79,7 @@ export function updateUserProfile(data) {
return request({
url: '/user/UpdateProfile',
method: 'put',
data: {user:data}
data: { user: data }
})
}
@@ -96,7 +90,7 @@ export function updateUserPwd(oldPassword, newPassword) {
newPassword
}
return request({
url: '/account/UpdatePassword',
url: '/account/password',
method: 'put',
data: data
})

View File

@@ -191,7 +191,7 @@ const { queryParams, form, rules } = toRefs(data);
function getList() {
loading.value = true;
listDept(queryParams.value).then(response => {
deptList.value = proxy.handleTree(response.data, "id");
deptList.value = proxy.handleTree(response.data.items, "id");
loading.value = false;
});
}

View File

@@ -329,7 +329,7 @@ const { queryParams, form, rules } = toRefs(data);
function getList() {
loading.value = true;
listMenu(queryParams.value).then(response => {
menuList.value = proxy.handleTree(response.data, "id");
menuList.value = proxy.handleTree(response.data.items, "id");
loading.value = false;
});
}
@@ -338,7 +338,7 @@ function getTreeselect() {
menuOptions.value = [];
listMenu().then(response => {
const menu = { id: 0, menuName: "主类目", children: [] };
menu.children = proxy.handleTree(response.data, "id");
menu.children = proxy.handleTree(response.data.items, "id");
menuOptions.value.push(menu);
});
}

View File

@@ -186,7 +186,7 @@ const { queryParams, form, rules } = toRefs(data);
function getList() {
loading.value = true;
listPost(queryParams.value).then(response => {
postList.value = response.data.data;
postList.value = response.data.items;
total.value = response.data.total;
loading.value = false;
});

View File

@@ -24,9 +24,9 @@
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="状态" prop="isDeleted">
<el-form-item label="状态" prop="state">
<el-select
v-model="queryParams.isDeleted"
v-model="queryParams.state"
placeholder="角色状态"
clearable
style="width: 240px"
@@ -129,7 +129,7 @@
<el-table-column label="状态" align="center" width="100">
<template #default="scope">
<el-switch
v-model="scope.row.isDeleted"
v-model="scope.row.state"
:active-value="false"
:inactive-value="true"
@change="handleStatusChange(scope.row)"
@@ -214,12 +214,12 @@
<el-dialog :title="title" v-model="open" width="500px" append-to-body>
<el-form
ref="roleRef"
:model="form.role"
:model="form"
:rules="rules"
label-width="100px"
>
<el-form-item label="角色名称" prop="roleName">
<el-input v-model="form.role.roleName" placeholder="请输入角色名称" />
<el-input v-model="form.roleName" placeholder="请输入角色名称" />
</el-form-item>
<el-form-item prop="roleCode">
<template #label>
@@ -235,17 +235,17 @@
权限字符
</span>
</template>
<el-input v-model="form.role.roleCode" placeholder="请输入权限字符" />
<el-input v-model="form.roleCode" placeholder="请输入权限字符" />
</el-form-item>
<el-form-item label="角色顺序" prop="orderNum">
<el-input-number
v-model="form.role.orderNum"
v-model="form.orderNum"
controls-position="right"
:min="0"
/>
</el-form-item>
<el-form-item label="状态">
<el-radio-group v-model="form.role.isDeleted">
<el-radio-group v-model="form.state">
<el-radio
v-for="dict in sys_normal_disable"
:key="dict.value"
@@ -266,7 +266,7 @@
>全选/全不选</el-checkbox
>
<el-checkbox
v-model="form.role.menuCheckStrictly"
v-model="form.menuCheckStrictly"
@change="handleCheckedTreeConnect($event, 'menu')"
>父子联动
</el-checkbox>
@@ -276,14 +276,14 @@
show-checkbox
ref="menuRef"
node-key="id"
:check-strictly="!form.role.menuCheckStrictly"
:check-strictly="!form.menuCheckStrictly"
empty-text="加载中请稍候"
:props="{ label: 'label', children: 'children' }"
></el-tree>
</el-form-item>
<el-form-item label="备注">
<el-input
v-model="form.role.remark"
v-model="form.remark"
type="textarea"
placeholder="请输入内容"
></el-input>
@@ -306,14 +306,14 @@
>
<el-form :model="form" label-width="80px">
<el-form-item label="角色名称">
<el-input v-model="form.role.roleName" :disabled="true" />
<el-input v-model="form.roleName" :disabled="true" />
</el-form-item>
<el-form-item label="权限字符">
<el-input v-model="form.role.roleCode" :disabled="true" />
<el-input v-model="form.roleCode" :disabled="true" />
</el-form-item>
<el-form-item label="权限范围">
<el-select
v-model="form.role.dataScope"
v-model="form.dataScope"
@change="dataScopeSelectChange"
>
<el-option
@@ -325,7 +325,7 @@
</el-option>
</el-select>
</el-form-item>
<el-form-item label="数据权限" v-show="form.role.dataScope == 1">
<el-form-item label="数据权限" v-show="form.dataScope == 1">
<el-checkbox
v-model="deptExpand"
@change="handleCheckedTreeExpand($event, 'dept')"
@@ -420,7 +420,7 @@ const data = reactive({
pageSize: 10,
roleName: undefined,
roleCode: undefined,
isDeleted: undefined,
state: undefined,
},
rules: {
roleName: [
@@ -442,7 +442,7 @@ function getList() {
loading.value = true;
listRole(proxy.addDateRange(queryParams.value, dateRange.value)).then(
(response) => {
roleList.value = response.data.data;
roleList.value = response.data.items;
total.value = response.data.total;
loading.value = false;
}
@@ -491,17 +491,17 @@ function handleSelectionChange(selection) {
}
/** 角色状态修改 */
function handleStatusChange(row) {
let text = row.isDeleted === false ? "启用" : "停用";
let text = row.state === false ? "启用" : "停用";
proxy.$modal
.confirm('确认要"' + text + '""' + row.roleName + '"角色吗?')
.then(function () {
return changeRoleStatus(row.id, row.isDeleted);
return changeRoleStatus(row.id, row.state);
})
.then(() => {
proxy.$modal.msgSuccess(text + "成功");
})
.catch(function () {
row.isDeleted = row.isDeleted === "0" ? "1" : "0";
row.state = row.state === "0" ? "1" : "0";
});
}
/** 更多操作 */
@@ -525,7 +525,7 @@ function handleAuthUser(row) {
function getMenuTreeselect() {
listMenu().then((response) => {
const options = [];
response.data.forEach((m) => {
response.data.items.forEach((m) => {
options.push({
id: m.id,
label: m.menuName,
@@ -555,17 +555,16 @@ function reset() {
deptExpand.value = true;
deptNodeAll.value = false;
form.value = {
role: {
id: undefined,
roleName: undefined,
roleCode: undefined,
orderNum: 0,
IsDeleted: false,
state: false,
menuCheckStrictly: false,
deptCheckStrictly: false,
remark: undefined,
dataScope: 0,
},
menuIds: [],
deptIds: [],
};
@@ -584,8 +583,8 @@ function handleUpdate(row) {
const roleId = row.id || ids.value;
getRoleMenuTreeselect(roleId);
getRole(roleId).then((response) => {
form.value.role = response.data;
form.value.role.orderNum = Number(form.value.role.orderNum);
form.value= response.data;
form.value.orderNum = Number(form.value.orderNum);
open.value = true;
title.value = "修改角色";
});
@@ -598,7 +597,7 @@ function getRoleMenuTreeselect(roleId) {
roleMenuTreeselect(roleId).then((response) => {
const menuIds = [];
response.data.forEach((m) => {
response.data.item.forEach((m) => {
menuIds.push(m.id);
});
@@ -680,7 +679,7 @@ function getMenuAllCheckedKeys() {
function submitForm() {
proxy.$refs["roleRef"].validate((valid) => {
if (valid) {
if (form.value.role.id != undefined) {
if (form.value.id != undefined) {
form.value.menuIds = getMenuAllCheckedKeys();
updateRole(form.value).then((response) => {
proxy.$modal.msgSuccess("修改成功");
@@ -714,14 +713,14 @@ function handleDataScope(row) {
reset();
getDeptTree(row.id);
getRole(row.id).then((response) => {
form.value.role = response.data;
form.value = response.data;
openDataScope.value = true;
title.value = "分配数据权限";
});
}
/** 提交按钮(数据权限) */
function submitDataScope() {
if (form.value.role.id != undefined) {
if (form.value.id != undefined) {
form.value.deptIds = getDeptAllCheckedKeys();
dataScope(form.value).then((response) => {
proxy.$modal.msgSuccess("修改成功");

View File

@@ -24,8 +24,8 @@
<el-input v-model="queryParams.phone" placeholder="请输入手机号码" clearable style="width: 240px"
@keyup.enter="handleQuery" />
</el-form-item>
<el-form-item label="状态" prop="isDeleted">
<el-select v-model="queryParams.isDeleted" placeholder="用户状态" clearable style="width: 240px">
<el-form-item label="状态" prop="state">
<el-select v-model="queryParams.state" placeholder="用户状态" clearable style="width: 240px">
<el-option v-for="dict in sys_normal_disable" :key="dict.value" :label="dict.label"
:value="dict.value" />
</el-select>
@@ -75,15 +75,15 @@
:show-overflow-tooltip="true" />
<el-table-column label="手机号码" align="center" key="phone" prop="phone" v-if="columns[4].visible"
width="120" />
<el-table-column label="状态" align="isDeleted" key="isDeleted" v-if="columns[5].visible">
<el-table-column label="状态" align="state" key="state" v-if="columns[5].visible">
<template #default="scope">
<el-switch v-model="scope.row.isDeleted" :active-value=false :inactive-value=true
<el-switch v-model="scope.row.state" :active-value=false :inactive-value=true
@change="handleStatusChange(scope.row)"></el-switch>
</template>
</el-table-column>
<el-table-column label="创建时间" align="center" prop="createTime" v-if="columns[6].visible" width="160">
<el-table-column label="创建时间" align="center" prop="creationTime" v-if="columns[6].visible" width="160">
<template #default="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
<span>{{ parseTime(scope.row.creationTime) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width">
@@ -114,11 +114,11 @@
<!-- 添加或修改用户配置对话框 -->
<el-dialog :title="title" v-model="open" width="600px" append-to-body>
<el-form :model="form.user" :rules="rules" ref="userRef" label-width="80px">
<el-form :model="form" :rules="rules" ref="userRef" label-width="80px">
<el-row>
<el-col :span="12">
<el-form-item label="用户昵称" prop="nick">
<el-input v-model="form.user.nick" placeholder="请输入用户昵称" maxlength="30" />
<el-input v-model="form.nick" placeholder="请输入用户昵称" maxlength="30" />
</el-form-item>
</el-col>
<el-col :span="12">
@@ -132,24 +132,24 @@
<el-row>
<el-col :span="12">
<el-form-item label="手机号码" prop="phone">
<el-input v-model="form.user.phone" placeholder="请输入手机号码" maxlength="11" />
<el-input v-model="form.phone" placeholder="请输入手机号码" maxlength="11" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="邮箱" prop="email">
<el-input v-model="form.user.email" placeholder="请输入邮箱" maxlength="50" />
<el-input v-model="form.email" placeholder="请输入邮箱" maxlength="50" />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item v-if="form.id == undefined" label="用户账号" prop="userName">
<el-input v-model="form.user.userName" placeholder="请输入用户账号" maxlength="30" />
<el-input v-model="form.userName" placeholder="请输入用户账号" maxlength="30" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item v-if="form.id == undefined" label="用户密码" prop="password">
<el-input v-model="form.user.password" placeholder="请输入用户密码" type="password" maxlength="20"
<el-input v-model="form.password" placeholder="请输入用户密码" type="password" maxlength="20"
show-password />
</el-form-item>
</el-col>
@@ -157,14 +157,14 @@
<el-row>
<el-col :span="12">
<el-form-item label="用户性别">
<el-select v-model="form.user.sex" placeholder="请选择">
<el-select v-model="form.sex" placeholder="请选择">
<el-option v-for="dict in sys_user_sex" :key="dict.value" :label="dict.label" :value="JSON.parse(dict.value) "></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="状态">
<el-radio-group v-model="form.user.isDeleted">
<el-radio-group v-model="form.state">
<el-radio v-for="dict in sys_normal_disable" :key="dict.value" :label="JSON.parse(dict.value)">{{dict.label}}</el-radio>
</el-radio-group>
</el-form-item>
@@ -175,7 +175,7 @@
<el-form-item label="岗位">
<el-select v-model="form.postIds" multiple placeholder="请选择">
<el-option v-for="item in postOptions" :key="item.id" :label="item.postName"
:value="item.id" :disabled="item.isDeleted == true"></el-option>
:value="item.id" :disabled="item.state == false"></el-option>
</el-select>
</el-form-item>
</el-col>
@@ -183,7 +183,7 @@
<el-form-item label="角色">
<el-select v-model="form.roleIds" multiple placeholder="请选择">
<el-option v-for="item in roleOptions" :key="item.id" :label="item.roleName" :value="item.id"
:disabled="item.isDeleted ==true"></el-option>
:disabled="item.state ==false"></el-option>
</el-select>
</el-form-item>
</el-col>
@@ -191,7 +191,7 @@
<el-row>
<el-col :span="24">
<el-form-item label="备注">
<el-input v-model="form.user.remark" type="textarea" placeholder="请输入内容"></el-input>
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
</el-form-item>
</el-col>
</el-row>
@@ -288,13 +288,14 @@ const columns = ref([
]);
const data = reactive({
form: {},
form : {
},
queryParams: {
pageNum: 1,
pageSize: 10,
userName: undefined,
phone: undefined,
isDeleted: undefined,
state: true,
deptId: undefined
},
rules: {
@@ -321,7 +322,7 @@ watch(deptName, val => {
function getDeptTree() {
listDept().then(response => {
const selectList = [];
response.data.forEach(res => {
response.data.items.forEach(res => {
selectList.push({ id: res.id, label: res.deptName, parentId: res.parentId, orderNum: res.orderNum, children: [] })
}
@@ -335,7 +336,7 @@ function getList() {
listUser(proxy.addDateRange(queryParams.value, dateRange.value)).then(res => {
loading.value = false;
userList.value = res.data.data;
userList.value = res.data.items;
total.value = res.data.total;
});
};
@@ -374,14 +375,13 @@ function handleExport() {
};
/** 用户状态修改 */
function handleStatusChange(row) {
console.log(row)
let text = row.isDeleted === false ? "启用" : "停用";
let text = row.state === false ? "启用" : "停用";
proxy.$modal.confirm('确认要"' + text + '""' + row.userName + '"用户吗?').then(function () {
return changeUserStatus(row.id, row.isDeleted);
return changeUserStatus(row.id, row.state);
}).then(() => {
proxy.$modal.msgSuccess(text + "成功");
}).catch(function () {
row.isDeleted = row.isDeleted === true ? false : true;
row.state = row.state === true ? false : true;
});
};
/** 更多操作 */
@@ -450,16 +450,14 @@ function submitFileForm() {
/** 重置操作表单 */
function reset() {
form.value = {
user: {
userName: undefined,
nick: undefined,
password: undefined,
phone: undefined,
email: undefined,
sex: undefined,
isDeleted: false,
state: true,
remark: undefined,
},
postIds: [],
roleIds: [],
deptId: undefined
@@ -469,10 +467,10 @@ function reset() {
if (postOptions.value.length == 0 || roleOptions.value.length == 0) {
roleOptionselect().then(response => {
//岗位从另一个接口获取全量
roleOptions.value = response.data;
roleOptions.value = response.data.items;
})
postOptionselect().then(response => {
postOptions.value = response.data;
postOptions.value = response.data.items;
}
@@ -505,20 +503,20 @@ function handleUpdate(row) {
getUser(userId).then(response => {
form.value.user = response.data;
form.value = response.data;
form.value.postIds=[];
response.data.posts.forEach(post => {
form.value.postIds.push(post.id)
});
form.value.deptId= response.data.deptId;
form.value.roleIds=[];
response.data.roles.forEach(role => {
form.value.roleIds.push(role.id)
});
open.value = true;
title.value = "修改用户";
form.value.user.password = null;
form.value.password = null;
@@ -528,8 +526,8 @@ form.value.user.password = null;
function submitForm() {
proxy.$refs["userRef"].validate(valid => {
if (valid) {
if (form.value.user.id != undefined) {
updateUser(form.value).then(response => {
if (form.value.id != undefined) {
updateUser(form.value.id,form.value).then(response => {
proxy.$modal.msgSuccess("修改成功");
open.value = false;
getList();

View File

@@ -269,7 +269,7 @@ function setSubTableColumns(value) {
/** 查询菜单下拉树结构 */
function getMenuTreeselect() {
listMenu().then(response => {
menuOptions.value = proxy.handleTree(response.data, "menuId");
menuOptions.value = proxy.handleTree(response.data.items, "menuId");
});
}