😎代码优化

This commit is contained in:
zuohuaijun 2024-08-10 03:54:29 +08:00
parent d621527805
commit 5295f1cd7a
17 changed files with 64 additions and 33 deletions

View File

@ -46,6 +46,7 @@
"PasswordStrengthValidation": "(?=^.{6,16}$)(?=.*\\d)(?=.*\\W+)(?=.*[A-Z])(?=.*[a-z])(?!.*\\n).*$", // 6-16 "PasswordStrengthValidation": "(?=^.{6,16}$)(?=.*\\d)(?=.*\\W+)(?=.*[A-Z])(?=.*[a-z])(?!.*\\n).*$", // 6-16
"PasswordStrengthValidationMsg": "密码必须包含大小写字母、数字和特殊字符的组合长度在6-16之间", // "PasswordStrengthValidationMsg": "密码必须包含大小写字母、数字和特殊字符的组合长度在6-16之间", //
"CryptoType": "SM2", // MD5SM2SM4 "CryptoType": "SM2", // MD5SM2SM4
// (http://localhost:5005/api/sysCommon/smKeyPair)VITE_SM_PUBLIC_KEY
"PublicKey": "04851D329AA3E38C2E7670AFE70E6E70E92F8769CA27C8766B12209A0FFBA4493B603EF7A0B9B1E16F0E8930C0406EA0B179B68DF28E25334BDEC4AE76D907E9E9", // "PublicKey": "04851D329AA3E38C2E7670AFE70E6E70E92F8769CA27C8766B12209A0FFBA4493B603EF7A0B9B1E16F0E8930C0406EA0B179B68DF28E25334BDEC4AE76D907E9E9", //
"PrivateKey": "3A61D1D30C6302DABFF36201D936D0143EEF0C850AF28C5CA6D5C045AF8C5C8A" // "PrivateKey": "3A61D1D30C6302DABFF36201D936D0143EEF0C850AF28C5CA6D5C045AF8C5C8A" //
} }

View File

@ -1,6 +1,7 @@
{ {
"$schema": "https://gitee.com/dotnetchina/Furion/raw/v4/schemas/v4/furion-schema.json", "$schema": "https://gitee.com/dotnetchina/Furion/raw/v4/schemas/v4/furion-schema.json",
// Lazy.Captcha.Core (https://api.gitee.com/pojianbing/lazy-captcha/)
"CaptchaOptions": { "CaptchaOptions": {
"CaptchaType": 10, // 01234567891011 "CaptchaType": 10, // 01234567891011
"CodeLength": 1, // , CaptchaType , 2 "CodeLength": 1, // , CaptchaType , 2

View File

@ -160,8 +160,9 @@ public class AppAuthService : IDynamicApiController, ITransient
[NonAction] [NonAction]
public virtual async Task<LoginOutput> CreateToken(SysUser user, LoginModeEnum loginMode) public virtual async Task<LoginOutput> CreateToken(SysUser user, LoginModeEnum loginMode)
{ {
// 兼容处理前端未传递loginMode,导致收不到消息 // 默认PC端登录模式
if (loginMode == 0) loginMode = LoginModeEnum.PC; if (loginMode == 0)
loginMode = LoginModeEnum.PC;
// 单用户登录 // 单用户登录
await _sysOnlineUserService.SingleLogin(user.Id, loginMode); await _sysOnlineUserService.SingleLogin(user.Id, loginMode);

View File

@ -17,10 +17,10 @@
<PackageReference Include="AngleSharp" Version="1.1.2" /> <PackageReference Include="AngleSharp" Version="1.1.2" />
<PackageReference Include="AspectCore.Extensions.Reflection" Version="2.4.0" /> <PackageReference Include="AspectCore.Extensions.Reflection" Version="2.4.0" />
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" /> <PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.14.8" /> <PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.15.0" />
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.4.11" /> <PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.5.1" />
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.4.11" /> <PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.5.1" />
<PackageReference Include="Furion.Pure" Version="4.9.4.11" /> <PackageReference Include="Furion.Pure" Version="4.9.5.1" />
<PackageReference Include="Hardware.Info" Version="100.1.0.1" /> <PackageReference Include="Hardware.Info" Version="100.1.0.1" />
<PackageReference Include="IPTools.China" Version="1.6.0" /> <PackageReference Include="IPTools.China" Version="1.6.0" />
<PackageReference Include="IPTools.International" Version="1.6.0" /> <PackageReference Include="IPTools.International" Version="1.6.0" />
@ -39,7 +39,7 @@
<PackageReference Include="SqlSugarCore" Version="5.1.4.166" /> <PackageReference Include="SqlSugarCore" Version="5.1.4.166" />
<PackageReference Include="SSH.NET" Version="2024.1.0" /> <PackageReference Include="SSH.NET" Version="2024.1.0" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.4.4" /> <PackageReference Include="System.Linq.Dynamic.Core" Version="1.4.4" />
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1064" /> <PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1065" />
<PackageReference Include="UAParser" Version="3.1.47" /> <PackageReference Include="UAParser" Version="3.1.47" />
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" /> <PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
</ItemGroup> </ItemGroup>

View File

@ -67,8 +67,8 @@ public partial class SysOnlineUser : EntityTenantId
public string? Os { get; set; } public string? Os { get; set; }
/// <summary> /// <summary>
/// 登模式 /// 登模式
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "登模式")] [SugarColumn(ColumnDescription = "登模式")]
public LoginModeEnum LoginMode { get; set; } public LoginModeEnum LoginMode { get; set; }
} }

View File

@ -346,7 +346,7 @@ public enum ErrorCodeEnum
/// <summary> /// <summary>
/// 权限标识格式错误 /// 权限标识格式错误
/// </summary> /// </summary>
[ErrorCodeItemMetadata("权限标识格式错误 如xxx:xxx")] [ErrorCodeItemMetadata("权限标识格式错误 如xxx/xxx")]
D4004, D4004,
/// <summary> /// <summary>

View File

@ -179,4 +179,24 @@ public static class RedisQueue
var queue = GetRedisReliableQueue<T>(topic); var queue = GetRedisReliableQueue<T>(topic);
return queue.Take(count).ToList(); return queue.Take(count).ToList();
} }
/// <summary>
/// 申请分布式锁
/// </summary>
/// <param name="key">要锁定的key</param>
/// <param name="msTimeout">申请锁等待的时间,单位毫秒</param>
/// <param name="msExpire">锁过期时间,超过该时间没有主动是放则自动是放,必须整数秒,单位毫秒</param>
/// <param name="throwOnFailure">失败时是否抛出异常,如不抛出异常可通过判断返回null得知申请锁失败</param>
/// <returns></returns>
public static IDisposable? BeginCacheLock(string key, int msTimeout = 500, int msExpire = 10000, bool throwOnFailure = true)
{
try
{
return _cacheProvider.Cache.AcquireLock(key, msTimeout, msExpire, throwOnFailure);
}
catch
{
return null;
}
}
} }

View File

@ -45,7 +45,7 @@ public static class LoggingSetup
options.WithTraceId = true; // 显示线程Id options.WithTraceId = true; // 显示线程Id
options.WithStackFrame = true; // 显示程序集 options.WithStackFrame = true; // 显示程序集
options.FileNameRule = fileName => string.Format(fileName, DateTime.Now, logLevel.ToString()); // 每天创建一个文件 options.FileNameRule = fileName => string.Format(fileName, DateTime.Now, logLevel.ToString()); // 每天创建一个文件
options.WriteFilter = logMsg => logMsg.LogLevel == logLevel; // 日志级别 options.WriteFilter = logMsg => logMsg.LogLevel >= logLevel; // 日志级别
options.HandleWriteError = (writeError) => // 写入失败时启用备用文件 options.HandleWriteError = (writeError) => // 写入失败时启用备用文件
{ {
writeError.UseRollbackFileName(Path.GetFileNameWithoutExtension(writeError.CurrentFileName) + "-oops" + Path.GetExtension(writeError.CurrentFileName)); writeError.UseRollbackFileName(Path.GetFileNameWithoutExtension(writeError.CurrentFileName) + "-oops" + Path.GetExtension(writeError.CurrentFileName));

View File

@ -36,7 +36,7 @@ public class LoginInput
public string Code { get; set; } public string Code { get; set; }
/// <summary> /// <summary>
/// 登模式 /// 登模式
/// </summary> /// </summary>
public LoginModeEnum LoginMode { get; set; } public LoginModeEnum LoginMode { get; set; }
} }
@ -59,7 +59,7 @@ public class LoginPhoneInput
public string Code { get; set; } public string Code { get; set; }
/// <summary> /// <summary>
/// 登模式 /// 登模式
/// </summary> /// </summary>
public LoginModeEnum LoginMode { get; set; } public LoginModeEnum LoginMode { get; set; }
} }

View File

@ -66,9 +66,9 @@ public class SysAuthService : IDynamicApiController, ITransient
var keyPasswordErrorTimes = $"{CacheConst.KeyPasswordErrorTimes}{input.Account}"; var keyPasswordErrorTimes = $"{CacheConst.KeyPasswordErrorTimes}{input.Account}";
var passwordErrorTimes = _sysCacheService.Get<int>(keyPasswordErrorTimes); var passwordErrorTimes = _sysCacheService.Get<int>(keyPasswordErrorTimes);
var passwordMaxErrorTimes = await _sysConfigService.GetConfigValue<int>(ConfigConst.SysPasswordMaxErrorTimes); var passwordMaxErrorTimes = await _sysConfigService.GetConfigValue<int>(ConfigConst.SysPasswordMaxErrorTimes);
// 若未配置或误配置为0、负数, 则默认密码错误次数最大为10 // 若未配置或误配置为0、负数, 则默认密码错误次数最大为5
if (passwordMaxErrorTimes < 1) if (passwordMaxErrorTimes < 1)
passwordMaxErrorTimes = 10; passwordMaxErrorTimes = 5;
if (passwordErrorTimes > passwordMaxErrorTimes) if (passwordErrorTimes > passwordMaxErrorTimes)
throw Oops.Oh(ErrorCodeEnum.D1027); throw Oops.Oh(ErrorCodeEnum.D1027);
@ -214,8 +214,9 @@ public class SysAuthService : IDynamicApiController, ITransient
[NonAction] [NonAction]
internal async Task<LoginOutput> CreateToken(SysUser user, LoginModeEnum loginMode) internal async Task<LoginOutput> CreateToken(SysUser user, LoginModeEnum loginMode)
{ {
// 兼容处理前端未传递loginMode,导致收不到消息 // 默认PC端登录模式
if (loginMode == 0) loginMode = LoginModeEnum.PC; if (loginMode == 0)
loginMode = LoginModeEnum.PC;
// 单用户登录 // 单用户登录
await _sysOnlineUserService.SingleLogin(user.Id, loginMode); await _sysOnlineUserService.SingleLogin(user.Id, loginMode);

View File

@ -109,7 +109,7 @@ public class SysOAuthService : IDynamicApiController, ITransient
wechatUser = await _sysOAuthUserRep.AsQueryable().Includes(u => u.SysUser).ClearFilter().FirstAsync(u => u.OpenId == openIdClaim.Value); wechatUser = await _sysOAuthUserRep.AsQueryable().Includes(u => u.SysUser).ClearFilter().FirstAsync(u => u.OpenId == openIdClaim.Value);
} }
// 构建Token令牌 TODO 这里先默认所有回调登陆的都是PC // 构建Token令牌默认回调登录为PC模式
var token = await App.GetRequiredService<SysAuthService>().CreateToken(wechatUser.SysUser, LoginModeEnum.PC); var token = await App.GetRequiredService<SysAuthService>().CreateToken(wechatUser.SysUser, LoginModeEnum.PC);
return new RedirectResult($"{redirectUrl}/#/login?token={token.AccessToken}"); return new RedirectResult($"{redirectUrl}/#/login?token={token.AccessToken}");

View File

@ -10,5 +10,11 @@ VITE_OPEN_CDN = false
# public path 配置线上环境路径(打包)、本地通过 http-server 访问时,请置空即可 # public path 配置线上环境路径(打包)、本地通过 http-server 访问时,请置空即可
VITE_PUBLIC_PATH = VITE_PUBLIC_PATH =
# SM公钥 # 登陆界面默认用户
VITE_DEFAULT_USER = superadmin
# 登陆界面默认密码
VITE_DEFAULT_USER_PASSWORD = 123456
# 国密SM公钥
VITE_SM_PUBLIC_KEY = "04851D329AA3E38C2E7670AFE70E6E70E92F8769CA27C8766B12209A0FFBA4493B603EF7A0B9B1E16F0E8930C0406EA0B179B68DF28E25334BDEC4AE76D907E9E9" VITE_SM_PUBLIC_KEY = "04851D329AA3E38C2E7670AFE70E6E70E92F8769CA27C8766B12209A0FFBA4493B603EF7A0B9B1E16F0E8930C0406EA0B179B68DF28E25334BDEC4AE76D907E9E9"

View File

@ -2,7 +2,7 @@
"name": "admin.net.pro", "name": "admin.net.pro",
"type": "module", "type": "module",
"version": "2.4.33", "version": "2.4.33",
"lastBuildTime": "2024.08.08", "lastBuildTime": "2024.08.10",
"description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架", "description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架",
"author": "zuohuaijun", "author": "zuohuaijun",
"license": "MIT", "license": "MIT",
@ -26,7 +26,7 @@
"@vue-office/docx": "^1.6.2", "@vue-office/docx": "^1.6.2",
"@vue-office/excel": "^1.7.11", "@vue-office/excel": "^1.7.11",
"@vue-office/pdf": "^2.0.2", "@vue-office/pdf": "^2.0.2",
"@vueuse/core": "^10.11.0", "@vueuse/core": "^10.11.1",
"@wangeditor/editor": "^5.1.23", "@wangeditor/editor": "^5.1.23",
"@wangeditor/editor-for-vue": "^5.1.12", "@wangeditor/editor-for-vue": "^5.1.12",
"animate.css": "^4.1.1", "animate.css": "^4.1.1",
@ -37,7 +37,7 @@
"echarts": "^5.5.1", "echarts": "^5.5.1",
"echarts-gl": "^2.0.9", "echarts-gl": "^2.0.9",
"echarts-wordcloud": "^2.1.0", "echarts-wordcloud": "^2.1.0",
"element-plus": "^2.7.8", "element-plus": "^2.8.0",
"exceljs": "^4.4.0", "exceljs": "^4.4.0",
"ezuikit": "^1.0.0", "ezuikit": "^1.0.0",
"ezuikit-js": "^8.0.8", "ezuikit-js": "^8.0.8",
@ -64,7 +64,7 @@
"splitpanes": "^3.1.5", "splitpanes": "^3.1.5",
"vcrontab-3": "^3.3.22", "vcrontab-3": "^3.3.22",
"vform3-builds": "^3.0.10", "vform3-builds": "^3.0.10",
"vue": "^3.4.36", "vue": "^3.4.37",
"vue-clipboard3": "^2.0.0", "vue-clipboard3": "^2.0.0",
"vue-demi": "0.14.6", "vue-demi": "0.14.6",
"vue-draggable-plus": "^0.5.3", "vue-draggable-plus": "^0.5.3",
@ -75,7 +75,7 @@
"vue-router": "^4.4.3", "vue-router": "^4.4.3",
"vue-signature-pad": "^3.0.2", "vue-signature-pad": "^3.0.2",
"vue3-tree-org": "^4.2.2", "vue3-tree-org": "^4.2.2",
"vxe-pc-ui": "^4.0.91", "vxe-pc-ui": "^4.0.93",
"vxe-table": "^4.7.59", "vxe-table": "^4.7.59",
"vxe-table-plugin-element": "^4.0.4", "vxe-table-plugin-element": "^4.0.4",
"vxe-table-plugin-export-xlsx": "^4.0.5", "vxe-table-plugin-export-xlsx": "^4.0.5",
@ -93,7 +93,7 @@
"@typescript-eslint/parser": "^8.0.0", "@typescript-eslint/parser": "^8.0.0",
"@vitejs/plugin-vue": "^5.1.2", "@vitejs/plugin-vue": "^5.1.2",
"@vitejs/plugin-vue-jsx": "^4.0.0", "@vitejs/plugin-vue-jsx": "^4.0.0",
"@vue/compiler-sfc": "^3.4.36", "@vue/compiler-sfc": "^3.4.37",
"code-inspector-plugin": "^0.15.2", "code-inspector-plugin": "^0.15.2",
"eslint": "^9.8.0", "eslint": "^9.8.0",
"eslint-plugin-vue": "^9.27.0", "eslint-plugin-vue": "^9.27.0",
@ -102,7 +102,7 @@
"prettier": "^3.3.3", "prettier": "^3.3.3",
"rollup-plugin-visualizer": "^5.12.0", "rollup-plugin-visualizer": "^5.12.0",
"sass": "^1.77.8", "sass": "^1.77.8",
"terser": "^5.31.4", "terser": "^5.31.5",
"typescript": "^5.5.4", "typescript": "^5.5.4",
"unocss": "^0.61.9", "unocss": "^0.61.9",
"vite": "^5.4.0", "vite": "^5.4.0",

View File

@ -7,7 +7,7 @@ import { i18n } from '/@/i18n/index';
import other from '/@/utils/other'; import other from '/@/utils/other';
import ElementPlus from 'element-plus'; import ElementPlus from 'element-plus';
import '/@/theme/index.scss'; import '/@/theme/index.scss';
import 'virtual:uno.css' import 'virtual:uno.css';
// 动画库 // 动画库
import 'animate.css'; import 'animate.css';
// 栅格布局 // 栅格布局

View File

@ -110,8 +110,8 @@ const dragRef: any = ref(null);
const state = reactive({ const state = reactive({
isShowPassword: false, isShowPassword: false,
ruleForm: { ruleForm: {
account: '', account: window.__env__.VITE_DEFAULT_USER,
password: '', password: window.__env__.VITE_DEFAULT_USER_PASSWORD,
code: '', code: '',
codeId: 0, codeId: 0,
}, },

View File

@ -16,7 +16,7 @@
<el-tree <el-tree
ref="treeRef" ref="treeRef"
class="filter-tree" class="filter-tree"
style="padding-bottom: 60px;" style="padding-bottom: 60px"
:data="state.cacheData" :data="state.cacheData"
node-key="id" node-key="id"
:props="{ children: 'children', label: 'name' }" :props="{ children: 'children', label: 'name' }"
@ -37,7 +37,7 @@
<el-button icon="ele-Delete" size="small" type="danger" @click="delCache" v-auth="'sysCache/delete'"> 删除缓存 </el-button> <el-button icon="ele-Delete" size="small" type="danger" @click="delCache" v-auth="'sysCache/delete'"> 删除缓存 </el-button>
</div> </div>
</template> </template>
<vue-json-pretty :data="state.cacheValue" showLength showIcon showLineNumber showSelectController style="padding-bottom: 60px;" /> <vue-json-pretty :data="state.cacheValue" showLength showIcon showLineNumber showSelectController style="padding-bottom: 60px" />
</el-card> </el-card>
</pane> </pane>
</splitpanes> </splitpanes>

View File

@ -9,7 +9,8 @@ import { CodeInspectorPlugin } from 'code-inspector-plugin';
import fs from 'fs'; import fs from 'fs';
import { visualizer } from 'rollup-plugin-visualizer'; import { visualizer } from 'rollup-plugin-visualizer';
import { webUpdateNotice } from '@plugin-web-update-notification/vite'; import { webUpdateNotice } from '@plugin-web-update-notification/vite';
import UnoCSS from 'unocss/vite' import UnoCSS from 'unocss/vite';
const pathResolve = (dir: string) => { const pathResolve = (dir: string) => {
return resolve(__dirname, '.', dir); return resolve(__dirname, '.', dir);
}; };