😎1、调整代码生成 2、用户管理增加token黑名单 3、获取角色列表排除禁用的 4、升级依赖

This commit is contained in:
zuohuaijun 2024-10-22 01:09:19 +08:00
parent b0bfe08ac8
commit fc2b3ee500
6 changed files with 91 additions and 86 deletions

View File

@ -18,9 +18,9 @@
<PackageReference Include="AspectCore.Extensions.Reflection" Version="2.4.0" />
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.15.10" />
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.5.16" />
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.5.16" />
<PackageReference Include="Furion.Pure" Version="4.9.5.16" />
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.5.17" />
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.5.17" />
<PackageReference Include="Furion.Pure" Version="4.9.5.17" />
<PackageReference Include="Hardware.Info" Version="101.0.0" />
<PackageReference Include="Hashids.net" Version="1.7.0" />
<PackageReference Include="IPTools.China" Version="1.6.0" />
@ -42,7 +42,7 @@
<PackageReference Include="SqlSugarCore" Version="5.1.4.169" />
<PackageReference Include="SSH.NET" Version="2024.1.0" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.4.6" />
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1108" />
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1109" />
<PackageReference Include="UAParser" Version="3.1.47" />
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
</ItemGroup>
@ -60,7 +60,7 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="AspNet.Security.OAuth.Gitee" Version="8.2.0" />
<PackageReference Include="AspNet.Security.OAuth.Weixin" Version="8.2.0" />
<PackageReference Include="Lazy.Captcha.Core" Version="2.0.8" />
<PackageReference Include="Lazy.Captcha.Core" Version="2.0.9" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="8.0.10" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="8.0.10" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="8.0.10" />

View File

@ -410,33 +410,36 @@ public class SysCodeGenService : IDynamicApiController, ITransient
var data = new CustomViewEngine(_db)
{
ConfigId = input.ConfigId!,//库定位器名
AuthorName = input.AuthorName!,//作者
BusName = input.BusName!,//业务名称
NameSpace = input.NameSpace!,//命名空间
ClassName = input.TableName!,//类名称
PagePath = input.PagePath!,//页面目录
ProjectLastName = input.NameSpace!.Split('.').Last(),//项目最后个名称,生成的时候赋值
QueryWhetherList = queryWhetherList,//查询条件
TableField = tableFieldList,//表字段配置信息
IsJoinTable = joinTableList.Count > 0,//是否联表
IsUpload = joinTableList.Where(u => u.EffectType == "Upload").Any(),//是否上传
PrintType = input.PrintType!,//支持打印类型
PrintName = input.PrintName!,//打印模板名称
ConfigId = input.ConfigId!, // 库定位器名
AuthorName = input.AuthorName!, // 作者
BusName = input.BusName!, // 业务名称
NameSpace = input.NameSpace!, // 命名空间
ClassName = input.TableName!, // 类名称
PagePath = input.PagePath!, // 页面目录
ProjectLastName = input.NameSpace!.Split('.').Last(), // 项目最后个名称,生成的时候赋值
QueryWhetherList = queryWhetherList, // 查询条件
TableField = tableFieldList, // 表字段配置信息
IsJoinTable = joinTableList.Count > 0, // 是否联表
IsUpload = joinTableList.Where(u => u.EffectType == "Upload").Any(), // 是否上传
PrintType = input.PrintType!, // 支持打印类型
PrintName = input.PrintName!, // 打印模板名称
IsApiService = input.IsApiService,
RemoteVerify = tableFieldList.Any(t => t.RemoteVerify == true),//远程验证
RemoteVerify = tableFieldList.Any(t => t.RemoteVerify == true), // 远程验证
};
// 获得菜单
var menuList = await GetMenus(input.TableName!, input.BusName!, input.MenuPid ?? 0, input.MenuIcon!, input.PagePath!, tableFieldList);
if (input.GenerateMenu)
{
await AddMenu(menuList, input.MenuPid ?? 0); // 添加菜单
}
// 模板
var templateList = GetTemplateList(input);
var templatePath = Path.Combine(App.WebHostEnvironment.WebRootPath, "template");
// 获得菜单
var menuList = await GetMenus(input.TableName!, input.BusName!, input.MenuPid ?? 0, input.MenuIcon!, input.PagePath!, tableFieldList);
for (var i = 0; i < templateList.Count; i++)
{
string tResult = string.Empty;//模板生成结果
string tResult = string.Empty; // 模板生成结果
var templateFilePath = Path.Combine(templatePath, templateList[i].Name);
if (!File.Exists(templateFilePath)) continue;
@ -444,15 +447,15 @@ public class SysCodeGenService : IDynamicApiController, ITransient
if (templateList[i].Type == CodeGenTypeEnum.SeedData)
{
//种子模板
// 种子模板
var seedData = new
{
AuthorName = input.AuthorName!,//作者
BusName = input.BusName!,//业务名称
NameSpace = input.NameSpace!,//命名空间
ClassName = input.TableName!,//类名称
AuthorName = input.AuthorName!, // 作者
BusName = input.BusName!, // 业务名称
NameSpace = input.NameSpace!, // 命名空间
ClassName = input.TableName!, // 类名称
input.ConfigId,
MenuList = menuList,//菜单集合
MenuList = menuList, // 菜单集合
};
tResult = await _viewEngine.RunCompileAsync(tContent, seedData, builderAction: builder =>
{
@ -497,24 +500,17 @@ public class SysCodeGenService : IDynamicApiController, ITransient
Directory.CreateDirectory(dirPath);
File.WriteAllText(targetFile, tResult, Encoding.UTF8);
}
if (input.GenerateMenu)
{
//添加菜单
await AddMenu(menuList, input.MenuPid ?? 0);
}
// 非ZIP压缩返回空
if (!input.GenerateType.StartsWith('1'))
return null;
else
{
string downloadPath = outputPath + ".zip";
// 判断是否存在同名称文件
if (File.Exists(downloadPath))
File.Delete(downloadPath);
ZipFile.CreateFromDirectory(outputPath, downloadPath);
return new { url = $"{App.HttpContext.Request.Scheme}://{App.HttpContext.Request.Host.Value}/codeGen/{input.TableName}.zip" };
}
var downloadPath = outputPath + ".zip";
// 判断是否存在同名称文件
if (File.Exists(downloadPath))
File.Delete(downloadPath);
ZipFile.CreateFromDirectory(outputPath, downloadPath);
return new { url = $"{App.HttpContext.Request.Scheme}://{App.HttpContext.Request.Host.Value}/codeGen/{input.TableName}.zip" };
}
/// <summary>
@ -556,21 +552,21 @@ public class SysCodeGenService : IDynamicApiController, ITransient
var data = new CustomViewEngine(_db)
{
ConfigId = input.ConfigId!,//库定位器名
AuthorName = input.AuthorName!,//作者
BusName = input.BusName!,//业务名称
NameSpace = input.NameSpace!,//命名空间
ClassName = input.TableName!,//类名称
PagePath = input.PagePath!,//页面目录
ProjectLastName = input.NameSpace!.Split('.').Last(),//项目最后个名称,生成的时候赋值
QueryWhetherList = queryWhetherList,//查询条件
TableField = tableFieldList,//表字段配置信息
ConfigId = input.ConfigId!, // 库定位器名
AuthorName = input.AuthorName!, // 作者
BusName = input.BusName!, // 业务名称
NameSpace = input.NameSpace!, // 命名空间
ClassName = input.TableName!, // 类名称
PagePath = input.PagePath!, // 页面目录
ProjectLastName = input.NameSpace!.Split('.').Last(), // 项目最后个名称,生成的时候赋值
QueryWhetherList = queryWhetherList, // 查询条件
TableField = tableFieldList, // 表字段配置信息
IsJoinTable = joinTableList.Count > 0,//是否联表
IsUpload = joinTableList.Where(u => u.EffectType == "Upload").Any(),//是否上传
PrintType = input.PrintType!,//支持打印类型
PrintName = input.PrintName!,//打印模板名称
IsUpload = joinTableList.Where(u => u.EffectType == "Upload").Any(), // 是否上传
PrintType = input.PrintType!, // 支持打印类型
PrintName = input.PrintName!, // 打印模板名称
IsApiService = input.IsApiService,
RemoteVerify = tableFieldList.Any(t => t.RemoteVerify == true)//远程验证
RemoteVerify = tableFieldList.Any(t => t.RemoteVerify == true) // 远程验证
};
// 获取模板文件并替换
@ -580,7 +576,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient
var result = new Dictionary<string, string>();
for (var i = 0; i < templateList.Count; i++)
{
string tResult = string.Empty;//模板生成结果
string tResult = string.Empty; // 模板生成结果
var templateFilePath = Path.Combine(templatePath, templateList[i].Name);
if (!File.Exists(templateFilePath)) continue;
@ -589,16 +585,15 @@ public class SysCodeGenService : IDynamicApiController, ITransient
if (templateList[i].Type == CodeGenTypeEnum.SeedData)
{
// 种子模板
// 获得菜单
var menuList = await GetMenus(input.TableName!, input.BusName!, input.MenuPid ?? 0, input.MenuIcon!, input.PagePath!, tableFieldList);
var seedData = new
{
AuthorName = input.AuthorName!,//作者
BusName = input.BusName!,//业务名称
NameSpace = input.NameSpace!,//命名空间
ClassName = input.TableName!,//类名称
AuthorName = input.AuthorName!, // 作者
BusName = input.BusName!, // 业务名称
NameSpace = input.NameSpace!, // 命名空间
ClassName = input.TableName!, // 类名称
input.ConfigId,
MenuList = menuList,//菜单集合
MenuList = menuList, // 菜单集合
};
tResult = await _viewEngine.RunCompileAsync(tContent, seedData, builderAction: builder =>
{
@ -661,9 +656,8 @@ public class SysCodeGenService : IDynamicApiController, ITransient
// 若 pid=0 为顶级则创建菜单目录
if (pid == 0)
{
// 顶级目录
// 若已存在相同目录则删除本级和下级
var menuType0 = menus.Where(u => u.Type == MenuTypeEnum.Dir && u.Pid == 0).FirstOrDefault();
// 若先前存在则删除本级和下级
var menuList0 = await _db.Queryable<SysMenu>().Where(u => u.Title == menuType0.Title && u.Type == menuType0.Type).ToListAsync();
if (menuList0.Count > 0)
{
@ -678,12 +672,10 @@ public class SysCodeGenService : IDynamicApiController, ITransient
await _db.Deleteable<SysMenu>().Where(u => listIds.Contains(u.Id)).ExecuteCommandAsync();
await _db.Deleteable<SysRoleMenu>().Where(u => listIds.Contains(u.MenuId)).ExecuteCommandAsync();
}
await _db.Insertable(menuType0).ExecuteReturnEntityAsync();
}
// 菜单
// 若已存在相同菜单则删除本级和下级
var menuType = menus.Where(u => u.Type == MenuTypeEnum.Menu).FirstOrDefault();
// 若先前存在则删除本级和下级
var menuListCurrent = await _db.Queryable<SysMenu>().Where(u => u.Title == menuType.Title && u.Type == menuType.Type).ToListAsync();
if (menuListCurrent.Count > 0)
{
@ -698,6 +690,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient
await _db.Deleteable<SysMenu>().Where(u => listIds.Contains(u.Id)).ExecuteCommandAsync();
await _db.Deleteable<SysRoleMenu>().Where(u => listIds.Contains(u.MenuId)).ExecuteCommandAsync();
}
await _db.Insertable(menus).ExecuteCommandAsync();
}
@ -716,7 +709,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient
var pPath = string.Empty;
// 若 pid=0 为顶级则创建菜单目录
SysMenu menuType0 = null;
long tempPid = pid;//暂存原始pid
long tempPid = pid;
if (pid == 0)
{
// 目录
@ -727,8 +720,8 @@ public class SysCodeGenService : IDynamicApiController, ITransient
Title = busName + "管理",
Type = MenuTypeEnum.Dir,
Icon = "robot",
Path = "/" + className.ToLower() + "/dir",
Name = className[..1].ToLower() + className[1..] + "Dir",
Path = "/" + className.ToLower(),
Name = className[..1].ToLower() + className[1..],
Component = "Layout",
OrderNo = 100,
CreateTime = DateTime.Now
@ -915,7 +908,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient
menuList.Insert(0, menuType);
if (tempPid == 0)
{
//顶级目录需要添加目录本身
// 顶级目录需要添加目录本身
menuList.Insert(0, menuType0);
}
return menuList;

View File

@ -79,6 +79,7 @@ public class SysRoleService : IDynamicApiController, ITransient
return await _sysRoleRep.AsQueryable()
.WhereIF(!_userManager.SuperAdmin, u => u.TenantId == _userManager.TenantId) // 若非超管,则只能操作本租户的角色
.WhereIF(!_userManager.SuperAdmin && !_userManager.SysAdmin, u => u.CreateUserId == _userManager.UserId || roleIdList.Contains(u.Id)) // 若非超管且非系统管理员,则只显示自己创建和已拥有的角色
.Where(u => u.Status != StatusEnum.Disable) // 非禁用的
.OrderBy(u => new { u.OrderNo, u.Id }).Select(u => new RoleOutput { Disabled = false }, true).ToListAsync();
}

View File

@ -182,8 +182,8 @@ public class SysUserService : IDynamicApiController, ITransient
if (isOpenAccessUser)
throw Oops.Oh(ErrorCodeEnum.D1030);
// 强制下线
await _sysOnlineUserService.ForceOffline(user.Id);
// 设置账号Token黑名单
await SetUserBalckList(user, StatusEnum.Disable);
await _sysUserRep.DeleteAsync(user);
@ -237,22 +237,33 @@ public class SysUserService : IDynamicApiController, ITransient
if (!Enum.IsDefined(typeof(StatusEnum), input.Status))
throw Oops.Oh(ErrorCodeEnum.D3005);
// 设置账号Token黑名单
await SetUserBalckList(user, input.Status);
user.Status = input.Status;
return await _sysUserRep.AsUpdateable(user).UpdateColumns(u => new { u.Status }).ExecuteCommandAsync();
}
/// <summary>
/// 设置账号Token黑名单
/// </summary>
/// <param name="user"></param>
/// <param name="status"></param>
/// <returns></returns>
[NonAction]
private async Task SetUserBalckList(SysUser user, StatusEnum status)
{
// 账号禁用则增加黑名单,账号启用则移除黑名单
var sysCacheService = App.GetRequiredService<SysCacheService>();
if (input.Status == StatusEnum.Disable)
if (status != StatusEnum.Enable)
{
sysCacheService.Set($"{CacheConst.KeyBlacklist}{user.Id}", $"{user.RealName}-{user.Phone}");
// 强制下线
await _sysOnlineUserService.ForceOffline(user.Id);
await _sysOnlineUserService.ForceOffline(user.Id); // 强制账号下线
}
else
{
sysCacheService.Remove($"{CacheConst.KeyBlacklist}{user.Id}");
}
user.Status = input.Status;
return await _sysUserRep.AsUpdateable(user).UpdateColumns(u => new { u.Status }).ExecuteCommandAsync();
}
/// <summary>

View File

@ -2,7 +2,7 @@
"name": "admin.net.pro",
"type": "module",
"version": "2.4.33",
"lastBuildTime": "2024.10.20",
"lastBuildTime": "2024.10.21",
"description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架",
"author": "zuohuaijun",
"license": "MIT",
@ -42,7 +42,7 @@
"jsplumb": "^2.15.6",
"jwchat": "^2.0.3",
"lodash-es": "^4.17.21",
"md-editor-v3": "^4.21.0",
"md-editor-v3": "^4.21.1",
"mitt": "^3.0.1",
"monaco-editor": "^0.52.0",
"mqtt": "^5.10.1",
@ -71,7 +71,7 @@
"vue-router": "^4.4.5",
"vue-signature-pad": "^3.0.2",
"vue3-tree-org": "^4.2.2",
"vxe-pc-ui": "^4.2.24",
"vxe-pc-ui": "^4.2.26",
"vxe-table": "^4.7.59",
"vxe-table-plugin-element": "^4.0.4",
"vxe-table-plugin-export-xlsx": "^4.0.7",

View File

@ -96,7 +96,7 @@ const viteConfig = defineConfig((mode: ConfigEnv) => {
...(JSON.parse(env.VITE_OPEN_CDN) ? { external: buildConfig.external } : {}),
},
},
css: { preprocessorOptions: { css: { charset: false }, scss: { silenceDeprecations: ['legacy-js-api'] } } },
css: { preprocessorOptions: { css: { charset: false }, scss: { silenceDeprecations: ['legacy-js-api', 'global-builtin', 'fs-importer-cwd', 'import'] } } },
define: {
__VUE_I18N_LEGACY_API__: JSON.stringify(false),
__VUE_I18N_FULL_INSTALL__: JSON.stringify(false),