From 5295f1cd7a0ead82006d738cf23a4ba2e1b83263 Mon Sep 17 00:00:00 2001 From: zuohuaijun Date: Sat, 10 Aug 2024 03:54:29 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=98=8E=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Configuration/App.json | 1 + .../Configuration/Captcha.json | 1 + .../Service/App/Auth/AppAuthService.cs | 5 +++-- .../Admin.NET.Core/Admin.NET.Core.csproj | 10 +++++----- .../Admin.NET.Core/Entity/SysOnlineUser.cs | 4 ++-- .../Admin.NET.Core/Enum/ErrorCodeEnum.cs | 2 +- .../Admin.NET.Core/EventBus/RedisQueue.cs | 20 +++++++++++++++++++ .../Admin.NET.Core/Logging/LoggingSetup.cs | 2 +- .../Service/Auth/Dto/LoginInput.cs | 4 ++-- .../Service/Auth/SysAuthService.cs | 9 +++++---- .../Service/OAuth/SysOAuthService.cs | 2 +- Web/.env | 8 +++++++- Web/package.json | 16 +++++++-------- Web/src/main.ts | 2 +- Web/src/views/login/component/account.vue | 4 ++-- Web/src/views/system/cache/index.vue | 4 ++-- Web/vite.config.ts | 3 ++- 17 files changed, 64 insertions(+), 33 deletions(-) diff --git a/Admin.NET/Admin.NET.Application/Configuration/App.json b/Admin.NET/Admin.NET.Application/Configuration/App.json index 94b48a05..5ea29260 100644 --- a/Admin.NET/Admin.NET.Application/Configuration/App.json +++ b/Admin.NET/Admin.NET.Application/Configuration/App.json @@ -46,6 +46,7 @@ "PasswordStrengthValidation": "(?=^.{6,16}$)(?=.*\\d)(?=.*\\W+)(?=.*[A-Z])(?=.*[a-z])(?!.*\\n).*$", // 密码强度验证正则表达式,必须须包含大小写字母、数字和特殊字符的组合,长度在6-16之间 "PasswordStrengthValidationMsg": "密码必须包含大小写字母、数字和特殊字符的组合,长度在6-16之间", // 密码强度验证消息提示 "CryptoType": "SM2", // 密码加密算法:MD5、SM2、SM4 + // 新业务系统记得改密匙,通过接口(http://localhost:5005/api/sysCommon/smKeyPair)获取。记得同步修改前端公钥配置:VITE_SM_PUBLIC_KEY "PublicKey": "04851D329AA3E38C2E7670AFE70E6E70E92F8769CA27C8766B12209A0FFBA4493B603EF7A0B9B1E16F0E8930C0406EA0B179B68DF28E25334BDEC4AE76D907E9E9", // 公钥 "PrivateKey": "3A61D1D30C6302DABFF36201D936D0143EEF0C850AF28C5CA6D5C045AF8C5C8A" // 私钥 } diff --git a/Admin.NET/Admin.NET.Application/Configuration/Captcha.json b/Admin.NET/Admin.NET.Application/Configuration/Captcha.json index 0d8646fd..fcb10588 100644 --- a/Admin.NET/Admin.NET.Application/Configuration/Captcha.json +++ b/Admin.NET/Admin.NET.Application/Configuration/Captcha.json @@ -1,6 +1,7 @@ { "$schema": "https://gitee.com/dotnetchina/Furion/raw/v4/schemas/v4/furion-schema.json", + // Lazy.Captcha.Core 组件详细文档(https://api.gitee.com/pojianbing/lazy-captcha/) "CaptchaOptions": { "CaptchaType": 10, // 验证码类型0、1、2、3、4、5、6、7、8、9、10、11 "CodeLength": 1, // 验证码长度, 要放在CaptchaType设置后 当类型为算术表达式时,长度代表操作的个数, 例如2 diff --git a/Admin.NET/Admin.NET.Application/Service/App/Auth/AppAuthService.cs b/Admin.NET/Admin.NET.Application/Service/App/Auth/AppAuthService.cs index 0d350738..75bbecf6 100644 --- a/Admin.NET/Admin.NET.Application/Service/App/Auth/AppAuthService.cs +++ b/Admin.NET/Admin.NET.Application/Service/App/Auth/AppAuthService.cs @@ -160,8 +160,9 @@ public class AppAuthService : IDynamicApiController, ITransient [NonAction] public virtual async Task CreateToken(SysUser user, LoginModeEnum loginMode) { - // 兼容处理前端未传递loginMode,导致收不到消息 - if (loginMode == 0) loginMode = LoginModeEnum.PC; + // 默认PC端登录模式 + if (loginMode == 0) + loginMode = LoginModeEnum.PC; // 单用户登录 await _sysOnlineUserService.SingleLogin(user.Id, loginMode); diff --git a/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj b/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj index 6ac0e682..517fd894 100644 --- a/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj +++ b/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj @@ -17,10 +17,10 @@ - - - - + + + + @@ -39,7 +39,7 @@ - + diff --git a/Admin.NET/Admin.NET.Core/Entity/SysOnlineUser.cs b/Admin.NET/Admin.NET.Core/Entity/SysOnlineUser.cs index f2d2075e..574cfed0 100644 --- a/Admin.NET/Admin.NET.Core/Entity/SysOnlineUser.cs +++ b/Admin.NET/Admin.NET.Core/Entity/SysOnlineUser.cs @@ -67,8 +67,8 @@ public partial class SysOnlineUser : EntityTenantId public string? Os { get; set; } /// - /// 登陆模式 + /// 登录模式 /// - [SugarColumn(ColumnDescription = "登陆模式")] + [SugarColumn(ColumnDescription = "登录模式")] public LoginModeEnum LoginMode { get; set; } } \ No newline at end of file diff --git a/Admin.NET/Admin.NET.Core/Enum/ErrorCodeEnum.cs b/Admin.NET/Admin.NET.Core/Enum/ErrorCodeEnum.cs index 208384b6..28d8a6f8 100644 --- a/Admin.NET/Admin.NET.Core/Enum/ErrorCodeEnum.cs +++ b/Admin.NET/Admin.NET.Core/Enum/ErrorCodeEnum.cs @@ -346,7 +346,7 @@ public enum ErrorCodeEnum /// /// 权限标识格式错误 /// - [ErrorCodeItemMetadata("权限标识格式错误 如xxx:xxx")] + [ErrorCodeItemMetadata("权限标识格式错误 如xxx/xxx")] D4004, /// diff --git a/Admin.NET/Admin.NET.Core/EventBus/RedisQueue.cs b/Admin.NET/Admin.NET.Core/EventBus/RedisQueue.cs index 932ce6d8..3478e253 100644 --- a/Admin.NET/Admin.NET.Core/EventBus/RedisQueue.cs +++ b/Admin.NET/Admin.NET.Core/EventBus/RedisQueue.cs @@ -179,4 +179,24 @@ public static class RedisQueue var queue = GetRedisReliableQueue(topic); return queue.Take(count).ToList(); } + + /// + /// 申请分布式锁 + /// + /// 要锁定的key + /// 申请锁等待的时间,单位毫秒 + /// 锁过期时间,超过该时间没有主动是放则自动是放,必须整数秒,单位毫秒 + /// 失败时是否抛出异常,如不抛出异常,可通过判断返回null得知申请锁失败 + /// + 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; + } + } } \ No newline at end of file diff --git a/Admin.NET/Admin.NET.Core/Logging/LoggingSetup.cs b/Admin.NET/Admin.NET.Core/Logging/LoggingSetup.cs index b0e502df..99e372f7 100644 --- a/Admin.NET/Admin.NET.Core/Logging/LoggingSetup.cs +++ b/Admin.NET/Admin.NET.Core/Logging/LoggingSetup.cs @@ -45,7 +45,7 @@ public static class LoggingSetup options.WithTraceId = true; // 显示线程Id options.WithStackFrame = true; // 显示程序集 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) => // 写入失败时启用备用文件 { writeError.UseRollbackFileName(Path.GetFileNameWithoutExtension(writeError.CurrentFileName) + "-oops" + Path.GetExtension(writeError.CurrentFileName)); diff --git a/Admin.NET/Admin.NET.Core/Service/Auth/Dto/LoginInput.cs b/Admin.NET/Admin.NET.Core/Service/Auth/Dto/LoginInput.cs index 22154196..931c6221 100644 --- a/Admin.NET/Admin.NET.Core/Service/Auth/Dto/LoginInput.cs +++ b/Admin.NET/Admin.NET.Core/Service/Auth/Dto/LoginInput.cs @@ -36,7 +36,7 @@ public class LoginInput public string Code { get; set; } /// - /// 登陆模式 + /// 登录模式 /// public LoginModeEnum LoginMode { get; set; } } @@ -59,7 +59,7 @@ public class LoginPhoneInput public string Code { get; set; } /// - /// 登陆模式 + /// 登录模式 /// public LoginModeEnum LoginMode { get; set; } } \ No newline at end of file diff --git a/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs b/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs index ac49cf26..c5faa156 100644 --- a/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs +++ b/Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs @@ -66,9 +66,9 @@ public class SysAuthService : IDynamicApiController, ITransient var keyPasswordErrorTimes = $"{CacheConst.KeyPasswordErrorTimes}{input.Account}"; var passwordErrorTimes = _sysCacheService.Get(keyPasswordErrorTimes); var passwordMaxErrorTimes = await _sysConfigService.GetConfigValue(ConfigConst.SysPasswordMaxErrorTimes); - // 若未配置或误配置为0、负数, 则默认密码错误次数最大为10次 + // 若未配置或误配置为0、负数, 则默认密码错误次数最大为5次 if (passwordMaxErrorTimes < 1) - passwordMaxErrorTimes = 10; + passwordMaxErrorTimes = 5; if (passwordErrorTimes > passwordMaxErrorTimes) throw Oops.Oh(ErrorCodeEnum.D1027); @@ -214,8 +214,9 @@ public class SysAuthService : IDynamicApiController, ITransient [NonAction] internal async Task CreateToken(SysUser user, LoginModeEnum loginMode) { - // 兼容处理前端未传递loginMode,导致收不到消息 - if (loginMode == 0) loginMode = LoginModeEnum.PC; + // 默认PC端登录模式 + if (loginMode == 0) + loginMode = LoginModeEnum.PC; // 单用户登录 await _sysOnlineUserService.SingleLogin(user.Id, loginMode); diff --git a/Admin.NET/Admin.NET.Core/Service/OAuth/SysOAuthService.cs b/Admin.NET/Admin.NET.Core/Service/OAuth/SysOAuthService.cs index 49d419d4..91acbacb 100644 --- a/Admin.NET/Admin.NET.Core/Service/OAuth/SysOAuthService.cs +++ b/Admin.NET/Admin.NET.Core/Service/OAuth/SysOAuthService.cs @@ -109,7 +109,7 @@ public class SysOAuthService : IDynamicApiController, ITransient 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().CreateToken(wechatUser.SysUser, LoginModeEnum.PC); return new RedirectResult($"{redirectUrl}/#/login?token={token.AccessToken}"); diff --git a/Web/.env b/Web/.env index fd90760f..db1b0f50 100644 --- a/Web/.env +++ b/Web/.env @@ -10,5 +10,11 @@ VITE_OPEN_CDN = false # public path 配置线上环境路径(打包)、本地通过 http-server 访问时,请置空即可 VITE_PUBLIC_PATH = -# SM公钥 +# 登陆界面默认用户 +VITE_DEFAULT_USER = superadmin + +# 登陆界面默认密码 +VITE_DEFAULT_USER_PASSWORD = 123456 + +# 国密SM公钥 VITE_SM_PUBLIC_KEY = "04851D329AA3E38C2E7670AFE70E6E70E92F8769CA27C8766B12209A0FFBA4493B603EF7A0B9B1E16F0E8930C0406EA0B179B68DF28E25334BDEC4AE76D907E9E9" \ No newline at end of file diff --git a/Web/package.json b/Web/package.json index eb1dbe9f..180539a4 100644 --- a/Web/package.json +++ b/Web/package.json @@ -2,7 +2,7 @@ "name": "admin.net.pro", "type": "module", "version": "2.4.33", - "lastBuildTime": "2024.08.08", + "lastBuildTime": "2024.08.10", "description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架", "author": "zuohuaijun", "license": "MIT", @@ -26,7 +26,7 @@ "@vue-office/docx": "^1.6.2", "@vue-office/excel": "^1.7.11", "@vue-office/pdf": "^2.0.2", - "@vueuse/core": "^10.11.0", + "@vueuse/core": "^10.11.1", "@wangeditor/editor": "^5.1.23", "@wangeditor/editor-for-vue": "^5.1.12", "animate.css": "^4.1.1", @@ -37,7 +37,7 @@ "echarts": "^5.5.1", "echarts-gl": "^2.0.9", "echarts-wordcloud": "^2.1.0", - "element-plus": "^2.7.8", + "element-plus": "^2.8.0", "exceljs": "^4.4.0", "ezuikit": "^1.0.0", "ezuikit-js": "^8.0.8", @@ -64,7 +64,7 @@ "splitpanes": "^3.1.5", "vcrontab-3": "^3.3.22", "vform3-builds": "^3.0.10", - "vue": "^3.4.36", + "vue": "^3.4.37", "vue-clipboard3": "^2.0.0", "vue-demi": "0.14.6", "vue-draggable-plus": "^0.5.3", @@ -75,7 +75,7 @@ "vue-router": "^4.4.3", "vue-signature-pad": "^3.0.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-plugin-element": "^4.0.4", "vxe-table-plugin-export-xlsx": "^4.0.5", @@ -93,7 +93,7 @@ "@typescript-eslint/parser": "^8.0.0", "@vitejs/plugin-vue": "^5.1.2", "@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", "eslint": "^9.8.0", "eslint-plugin-vue": "^9.27.0", @@ -102,8 +102,8 @@ "prettier": "^3.3.3", "rollup-plugin-visualizer": "^5.12.0", "sass": "^1.77.8", - "terser": "^5.31.4", - "typescript": "^5.5.4", + "terser": "^5.31.5", + "typescript": "^5.5.4", "unocss": "^0.61.9", "vite": "^5.4.0", "vite-plugin-cdn-import": "^1.0.1", diff --git a/Web/src/main.ts b/Web/src/main.ts index aa150ed4..13da80eb 100644 --- a/Web/src/main.ts +++ b/Web/src/main.ts @@ -7,7 +7,7 @@ import { i18n } from '/@/i18n/index'; import other from '/@/utils/other'; import ElementPlus from 'element-plus'; import '/@/theme/index.scss'; -import 'virtual:uno.css' +import 'virtual:uno.css'; // 动画库 import 'animate.css'; // 栅格布局 diff --git a/Web/src/views/login/component/account.vue b/Web/src/views/login/component/account.vue index 2142a500..b2b47b73 100644 --- a/Web/src/views/login/component/account.vue +++ b/Web/src/views/login/component/account.vue @@ -110,8 +110,8 @@ const dragRef: any = ref(null); const state = reactive({ isShowPassword: false, ruleForm: { - account: '', - password: '', + account: window.__env__.VITE_DEFAULT_USER, + password: window.__env__.VITE_DEFAULT_USER_PASSWORD, code: '', codeId: 0, }, diff --git a/Web/src/views/system/cache/index.vue b/Web/src/views/system/cache/index.vue index 51dc1d43..7cddda37 100644 --- a/Web/src/views/system/cache/index.vue +++ b/Web/src/views/system/cache/index.vue @@ -16,7 +16,7 @@ 删除缓存 - + diff --git a/Web/vite.config.ts b/Web/vite.config.ts index e2a8d72e..4a14a74b 100644 --- a/Web/vite.config.ts +++ b/Web/vite.config.ts @@ -9,7 +9,8 @@ import { CodeInspectorPlugin } from 'code-inspector-plugin'; import fs from 'fs'; import { visualizer } from 'rollup-plugin-visualizer'; import { webUpdateNotice } from '@plugin-web-update-notification/vite'; -import UnoCSS from 'unocss/vite' +import UnoCSS from 'unocss/vite'; + const pathResolve = (dir: string) => { return resolve(__dirname, '.', dir); };