From 6b52615df43e123cad1cb9a0955b45e2bec8b167 Mon Sep 17 00:00:00 2001 From: Adee Date: Sat, 17 Sep 2022 14:38:15 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E4=B8=8E=E4=BB=A3=E7=A0=81=E6=98=A0=E5=B0=84?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E4=B8=8D=E4=B8=80=E8=87=B4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vben28/build/vite/plugin/index.ts | 4 ++-- vben28/build/vite/plugin/styleImport.ts | 6 +++--- vben28/src/main.ts | 6 ++++++ vben28/vite.config.ts | 5 +++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/vben28/build/vite/plugin/index.ts b/vben28/build/vite/plugin/index.ts index 0efe660d..989b84e2 100644 --- a/vben28/build/vite/plugin/index.ts +++ b/vben28/build/vite/plugin/index.ts @@ -5,7 +5,7 @@ import legacy from '@vitejs/plugin-legacy'; import purgeIcons from 'vite-plugin-purge-icons'; import windiCSS from 'vite-plugin-windicss'; import VitePluginCertificate from 'vite-plugin-mkcert'; -import vueSetupExtend from 'vite-plugin-vue-setup-extend'; +//import vueSetupExtend from 'vite-plugin-vue-setup-extend'; import { configHtmlPlugin } from './html'; import { configPwaConfig } from './pwa'; import { configMockPlugin } from './mock'; @@ -31,7 +31,7 @@ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) { // have to vueJsx(), // support name - vueSetupExtend(), + //vueSetupExtend(), VitePluginCertificate({ source: 'coding', }), diff --git a/vben28/build/vite/plugin/styleImport.ts b/vben28/build/vite/plugin/styleImport.ts index 1f606c4d..d4bafeb6 100644 --- a/vben28/build/vite/plugin/styleImport.ts +++ b/vben28/build/vite/plugin/styleImport.ts @@ -5,9 +5,9 @@ import { createStyleImportPlugin } from 'vite-plugin-style-import'; export function configStyleImportPlugin(_isBuild: boolean) { - // if (!isBuild) { - // return []; - // } + if (!_isBuild) { + return []; + } const styleImportPlugin = createStyleImportPlugin({ libs: [ { diff --git a/vben28/src/main.ts b/vben28/src/main.ts index 8d11d586..b3bd6848 100644 --- a/vben28/src/main.ts +++ b/vben28/src/main.ts @@ -15,6 +15,12 @@ import { setupGlobDirectives } from '/@/directives'; import { setupI18n } from '/@/locales/setupI18n'; import { registerGlobComp } from '/@/components/registerGlobComp'; import Antd from 'ant-design-vue'; + +import { isDevMode } from './utils/env'; +if (isDevMode()) { + import('ant-design-vue/es/style'); +} + async function bootstrap() { const app = createApp(App); app.use(Antd); diff --git a/vben28/vite.config.ts b/vben28/vite.config.ts index d315597c..1fbce4cf 100644 --- a/vben28/vite.config.ts +++ b/vben28/vite.config.ts @@ -109,6 +109,11 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { '@iconify/iconify', 'ant-design-vue/es/locale/zh_CN', 'ant-design-vue/es/locale/en_US', + 'ant-design-vue/es/style', + 'echarts/core', + 'echarts/charts', + 'echarts/components', + 'echarts/renderers', ], }, }; From d2e0d76479047e498e7d4a1a73bf5753308e1c98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=86=9B?= <510423039@qq.com> Date: Thu, 27 Oct 2022 09:11:15 +0800 Subject: [PATCH 2/9] =?UTF-8?q?fix:=20=E7=94=A8=E6=88=B7=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E5=A4=9A=E8=AF=AD=E8=A8=80=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Users/UserAppService.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Users/UserAppService.cs b/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Users/UserAppService.cs index e1bc4e76..b9e1a2c5 100644 --- a/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Users/UserAppService.cs +++ b/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Users/UserAppService.cs @@ -1,9 +1,11 @@ +using Lion.AbpPro.BasicManagement.Localization; using Lion.AbpPro.BasicManagement.Users.Dtos; using Magicodes.ExporterAndImporter.Excel; using Magicodes.ExporterAndImporter.Excel.AspNetCore; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Volo.Abp.Account; +using Volo.Abp.Identity.Localization; namespace Lion.AbpPro.BasicManagement.Users { @@ -15,18 +17,22 @@ namespace Lion.AbpPro.BasicManagement.Users private readonly IIdentityUserRepository _identityUserRepository; private readonly IExcelExporter _excelExporter; private readonly IOptions _options; + private readonly IStringLocalizer _localizer; + public UserAppService( IIdentityUserAppService identityUserAppService, IdentityUserManager userManager, IIdentityUserRepository userRepository, IExcelExporter excelExporter, - IOptions options) + IOptions options, + IStringLocalizer localizer) { _identityUserAppService = identityUserAppService; _userManager = userManager; _identityUserRepository = userRepository; _excelExporter = excelExporter; _options = options; + _localizer = localizer; } /// @@ -117,8 +123,6 @@ namespace Lion.AbpPro.BasicManagement.Users /// /// 修改密码 /// - /// - /// public async Task ChangePasswordAsync(ChangePasswordInput input) { await _options.SetAsync(); @@ -134,7 +138,7 @@ namespace Lion.AbpPro.BasicManagement.Users } return !result.Succeeded - ? throw new UserFriendlyException(result?.Errors?.FirstOrDefault()?.Description) + ? throw new BusinessException("Volo.Abp.Identity:" + result?.Errors?.FirstOrDefault()?.Code) : result.Succeeded; } @@ -151,4 +155,4 @@ namespace Lion.AbpPro.BasicManagement.Users await _userManager.UpdateAsync(identityUser); } } -} +} \ No newline at end of file From 92c796989d38baba81381c1bb8b1ec6735f2820d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=86=9B?= <510423039@qq.com> Date: Thu, 27 Oct 2022 09:11:38 +0800 Subject: [PATCH 3/9] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E8=BF=87=E6=BB=A4=E5=99=A8=E5=92=8C=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Customs/Dtos/WrapResultAttribute.cs | 6 ++ .../AbpProHttpApiHostModule.cs | 14 +-- .../MVC/Filters/ResultExceptionFilter.cs | 99 ------------------- .../System/DontWrapResultAttribute.cs | 6 -- .../Lion.AbpPro.HttpApi.Host/GlobalUsings.cs | 2 - .../Lion.AbpPro.HttpApi.Host.csproj | 80 +++++++-------- .../GlobalUsings.cs | 10 ++ ...AbpPro.Shared.Hosting.Microservices.csproj | 2 +- .../Mvc/Filters/LionExceptionFilter.cs | 87 ++++++++++++++++ .../Mvc/Filters/LionResultFilter.cs | 33 +++++++ .../SharedHostingMicroserviceModule.cs | 31 ++++-- 11 files changed, 199 insertions(+), 171 deletions(-) create mode 100644 aspnet-core/frameworks/Extensions/src/Lion.AbpPro.Extension/Customs/Dtos/WrapResultAttribute.cs delete mode 100644 aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/MVC/Filters/ResultExceptionFilter.cs delete mode 100644 aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/System/DontWrapResultAttribute.cs create mode 100644 aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/Microsoft/AspNetCore/Mvc/Filters/LionExceptionFilter.cs create mode 100644 aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/Microsoft/AspNetCore/Mvc/Filters/LionResultFilter.cs diff --git a/aspnet-core/frameworks/Extensions/src/Lion.AbpPro.Extension/Customs/Dtos/WrapResultAttribute.cs b/aspnet-core/frameworks/Extensions/src/Lion.AbpPro.Extension/Customs/Dtos/WrapResultAttribute.cs new file mode 100644 index 00000000..2cbd5027 --- /dev/null +++ b/aspnet-core/frameworks/Extensions/src/Lion.AbpPro.Extension/Customs/Dtos/WrapResultAttribute.cs @@ -0,0 +1,6 @@ +namespace Lion.AbpPro.Extension.Customs.Dtos +{ + public class WrapResultAttribute : Attribute + { + } +} \ No newline at end of file diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs index 8904e1a2..954621c2 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs @@ -34,7 +34,6 @@ namespace Lion.AbpPro ConfigureJwtAuthentication(context, configuration); ConfigureHangfireMysql(context); ConfigureMiniProfiler(context); - ConfigureAbpExceptions(context); ConfigureIdentity(context); ConfigureCap(context); ConfigureAuditLog(context); @@ -84,16 +83,6 @@ namespace Lion.AbpPro } } - /// - /// 异常处理 - /// - /// - private void ConfigureAbpExceptions(ServiceConfigurationContext context) - { - context.Services.AddMvc(options => { options.Filters.Add(typeof(ResultExceptionFilter)); }); - } - - private void ConfigureHangfireMysql(ServiceConfigurationContext context) { @@ -198,7 +187,6 @@ namespace Lion.AbpPro }); } - /// /// Redis缓存 @@ -323,7 +311,7 @@ namespace Lion.AbpPro }); } } - + /// /// 审计日志 /// diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/MVC/Filters/ResultExceptionFilter.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/MVC/Filters/ResultExceptionFilter.cs deleted file mode 100644 index d3f220b8..00000000 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/MVC/Filters/ResultExceptionFilter.cs +++ /dev/null @@ -1,99 +0,0 @@ -namespace Lion.AbpPro.Extensions.MVC.Filters -{ - public sealed class ResultExceptionFilter : IAsyncExceptionFilter, ITransientDependency - { - public async Task OnExceptionAsync(ExceptionContext context) - { - if (!ShouldHandleException(context)) - { - return; - } - - await HandleAndWrapException(context); - } - - private bool ShouldHandleException(ExceptionContext context) - { - if (context.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.GetCustomAttributes(typeof(DontWrapResultAttribute), true).Any()) - { - return true; - } - - if (context.ActionDescriptor.GetMethodInfo().GetCustomAttributes(typeof(DontWrapResultAttribute), true).Any()) - { - return true; - } - - return false; - } - - private async Task HandleAndWrapException(ExceptionContext context) - { - var exceptionHandlingOptions = context.GetRequiredService>().Value; - var exceptionToErrorInfoConverter = context.GetRequiredService(); - var remoteServiceErrorInfo = exceptionToErrorInfoConverter.Convert(context.Exception, options => - { - options.SendExceptionsDetailsToClients = exceptionHandlingOptions.SendExceptionsDetailsToClients; - options.SendStackTraceToClients = exceptionHandlingOptions.SendStackTraceToClients; - }); - - var logLevel = context.Exception.GetLogLevel(); - - var remoteServiceErrorInfoBuilder = new StringBuilder(); - remoteServiceErrorInfoBuilder.AppendLine($"---------- {nameof(RemoteServiceErrorInfo)} ----------"); - remoteServiceErrorInfoBuilder.AppendLine(context.GetRequiredService().Serialize(remoteServiceErrorInfo, indented: true)); - - var logger = context.GetService>(NullLogger.Instance); - - logger.LogWithLevel(logLevel, remoteServiceErrorInfoBuilder.ToString()); - - logger.LogException(context.Exception, logLevel); - - await context.GetRequiredService().NotifyAsync(new ExceptionNotificationContext(context.Exception)); - context.HttpContext.Response.StatusCode = 200; - var result = SimplifyMessage(context); - context.Result = new ObjectResult(result); - context.Exception = null; //Handled! - } - - private WrapResult SimplifyMessage(ExceptionContext context) - { - var result = new WrapResult(); - var localizer = context.GetService>(); - switch (context.Exception) - { - case AbpAuthorizationException: - result.SetFail("权限不足", 401); - break; - case AbpValidationException: - result.SetFail("请求参数验证失败", 400); - break; - case EntityNotFoundException: - result.SetFail("实体不存在", 506); - break; - case NotImplementedException: - result.SetFail("未实现功能", 507); - break; - default: - { - if (context.Exception is IHasErrorCode codeException) - { - result.SetFail(localizer[codeException.Code]); - foreach (var key in context.Exception.Data.Keys) - { - result.SetFail(result.Message.Replace("{" + key + "}", context.Exception.Data[key]?.ToString())); - } - } - else - { - result.SetFail(context.Exception.Message); - } - - break; - } - } - - return result; - } - } -} \ No newline at end of file diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/System/DontWrapResultAttribute.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/System/DontWrapResultAttribute.cs deleted file mode 100644 index 32cb31e5..00000000 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/System/DontWrapResultAttribute.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Lion.AbpPro.Extensions.System -{ - public class DontWrapResultAttribute : Attribute - { - } -} \ No newline at end of file diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/GlobalUsings.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/GlobalUsings.cs index 914c3e17..c2d5718b 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/GlobalUsings.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/GlobalUsings.cs @@ -19,8 +19,6 @@ global using Lion.AbpPro.Extension.Customs.Dtos; global using Lion.AbpPro.Extensions; global using Lion.AbpPro.Extensions.Hangfire; global using Lion.AbpPro.Extensions.Middlewares; -global using Lion.AbpPro.Extensions.MVC.Filters; -global using Lion.AbpPro.Extensions.System; global using Lion.AbpPro.MultiTenancy; global using Lion.AbpPro.Shared.Hosting.Microservices; global using Lion.AbpPro.Shared.Hosting.Microservices.Microsoft.AspNetCore.Builder; diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj index 11e46c6e..75991b9a 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj @@ -10,53 +10,53 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - - - - + + + + diff --git a/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/GlobalUsings.cs b/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/GlobalUsings.cs index a71b1759..3cbb2286 100644 --- a/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/GlobalUsings.cs +++ b/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/GlobalUsings.cs @@ -6,26 +6,36 @@ global using System.Linq; global using System.Net; global using System.Reflection; global using Consul; +global using Lion.AbpPro.Extension.Customs.Dtos; global using Lion.AbpPro.Shared.Hosting.Microservices.Microsoft.Extensions.DependencyInjection; global using Microsoft.AspNetCore.Builder; global using Microsoft.AspNetCore.Cors; global using Microsoft.AspNetCore.Http; +global using Microsoft.AspNetCore.Mvc; +global using Microsoft.AspNetCore.Mvc.Abstractions; global using Microsoft.AspNetCore.Mvc.ApiExplorer; +global using Microsoft.AspNetCore.Mvc.Filters; global using Microsoft.Extensions.Configuration; global using Microsoft.Extensions.DependencyInjection; global using Microsoft.Extensions.Hosting; +global using Microsoft.Extensions.Logging; +global using Microsoft.Extensions.Logging.Abstractions; global using Microsoft.Extensions.Options; global using Microsoft.OpenApi.Any; global using Microsoft.OpenApi.Models; +global using Newtonsoft.Json; global using Swashbuckle.AspNetCore.SwaggerGen; global using Volo.Abp; global using Volo.Abp.AspNetCore.ExceptionHandling; +global using Volo.Abp.AspNetCore.Mvc; global using Volo.Abp.AspNetCore.Mvc.AntiForgery; global using Volo.Abp.Authorization; global using Volo.Abp.Autofac; global using Volo.Abp.DependencyInjection; global using Volo.Abp.Domain.Entities; global using Volo.Abp.ExceptionHandling; +global using Volo.Abp.Http; +global using Volo.Abp.Json; global using Volo.Abp.Localization; global using Volo.Abp.Modularity; global using Volo.Abp.Swashbuckle; diff --git a/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/Lion.AbpPro.Shared.Hosting.Microservices.csproj b/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/Lion.AbpPro.Shared.Hosting.Microservices.csproj index 69d876a6..e7e198e4 100644 --- a/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/Lion.AbpPro.Shared.Hosting.Microservices.csproj +++ b/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/Lion.AbpPro.Shared.Hosting.Microservices.csproj @@ -2,7 +2,7 @@ net6.0 - + / diff --git a/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/Microsoft/AspNetCore/Mvc/Filters/LionExceptionFilter.cs b/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/Microsoft/AspNetCore/Mvc/Filters/LionExceptionFilter.cs new file mode 100644 index 00000000..e88f7216 --- /dev/null +++ b/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/Microsoft/AspNetCore/Mvc/Filters/LionExceptionFilter.cs @@ -0,0 +1,87 @@ +using System.Text; + +namespace Microservices.Microsoft.AspNetCore.Mvc.Filters; + +public sealed class LionExceptionFilter : IAsyncExceptionFilter, ITransientDependency +{ + public async Task OnExceptionAsync(ExceptionContext context) + { + if (!ShouldHandleException(context)) + { + return; + } + + await HandleAndWrapException(context); + } + + private bool ShouldHandleException(ExceptionContext context) + { + if (context.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.GetCustomAttributes(typeof(WrapResultAttribute), true).Any()) + { + return true; + } + + if (context.ActionDescriptor.GetMethodInfo().GetCustomAttributes(typeof(WrapResultAttribute), true).Any()) + { + return true; + } + + return false; + } + + private async Task HandleAndWrapException(ExceptionContext context) + { + var exceptionHandlingOptions = context.GetRequiredService>().Value; + var exceptionToErrorInfoConverter = context.GetRequiredService(); + var remoteServiceErrorInfo = exceptionToErrorInfoConverter.Convert(context.Exception, options => + { + options.SendExceptionsDetailsToClients = exceptionHandlingOptions.SendExceptionsDetailsToClients; + options.SendStackTraceToClients = exceptionHandlingOptions.SendStackTraceToClients; + }); + + var logLevel = context.Exception.GetLogLevel(); + + var remoteServiceErrorInfoBuilder = new StringBuilder(); + remoteServiceErrorInfoBuilder.AppendLine($"---------- {nameof(RemoteServiceErrorInfo)} ----------"); + remoteServiceErrorInfoBuilder.AppendLine(context.GetRequiredService().Serialize(remoteServiceErrorInfo, indented: true)); + + var logger = context.GetService>(NullLogger.Instance); + + logger.LogWithLevel(logLevel, remoteServiceErrorInfoBuilder.ToString()); + + logger.LogException(context.Exception, logLevel); + + await context.GetRequiredService().NotifyAsync(new ExceptionNotificationContext(context.Exception)); + context.HttpContext.Response.StatusCode = 200; + var result = SimplifyMessage(context); + context.Result = new ObjectResult(result); + context.Exception = null; //Handled! + } + + private WrapResult SimplifyMessage(ExceptionContext context) + { + var result = new WrapResult(); + switch (context.Exception) + { + case AbpAuthorizationException: + result.SetFail("权限不足", 401); + break; + case AbpValidationException: + result.SetFail("请求参数验证失败", 400); + break; + case EntityNotFoundException: + result.SetFail("实体不存在", 506); + break; + case NotImplementedException: + result.SetFail("未实现功能", 507); + break; + default: + { + result.SetFail(context.Exception.Message); + break; + } + } + + return result; + } +} \ No newline at end of file diff --git a/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/Microsoft/AspNetCore/Mvc/Filters/LionResultFilter.cs b/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/Microsoft/AspNetCore/Mvc/Filters/LionResultFilter.cs new file mode 100644 index 00000000..15c35779 --- /dev/null +++ b/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/Microsoft/AspNetCore/Mvc/Filters/LionResultFilter.cs @@ -0,0 +1,33 @@ +namespace Microservices.Microsoft.AspNetCore.Mvc.Filters; + +public class LionResultFilter : IResultFilter, ITransientDependency +{ + public void OnResultExecuting(ResultExecutingContext context) + { + // 如果是page 直接return + if (context.ActionDescriptor.IsPageAction()) return; + + var controllerHasDontWrapResultAttribute = context.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.GetCustomAttributes(typeof(WrapResultAttribute), true).Any(); + var controllerActionHasDontWrapResultAttribute = context.ActionDescriptor.GetMethodInfo().GetCustomAttributes(typeof(WrapResultAttribute), true).Any(); + if (controllerHasDontWrapResultAttribute || controllerActionHasDontWrapResultAttribute) + { + context.HttpContext.Response.StatusCode = 200; + var result = new WrapResult(); + if (context.Result is not EmptyResult) + { + result.SetSuccess(((ObjectResult)context.Result).Value); + } + + context.Result = new ContentResult() + { + StatusCode = (int)HttpStatusCode.OK, + ContentType = "application/json;charset=utf-8", + Content = JsonConvert.SerializeObject(result) + }; + } + } + + public void OnResultExecuted(ResultExecutedContext context) + { + } +} \ No newline at end of file diff --git a/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/SharedHostingMicroserviceModule.cs b/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/SharedHostingMicroserviceModule.cs index 91f72d2b..c8629570 100644 --- a/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/SharedHostingMicroserviceModule.cs +++ b/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/SharedHostingMicroserviceModule.cs @@ -1,3 +1,5 @@ +using Microservices.Microsoft.AspNetCore.Mvc.Filters; + namespace Lion.AbpPro.Shared.Hosting.Microservices { [DependsOn( @@ -17,20 +19,33 @@ namespace Lion.AbpPro.Shared.Hosting.Microservices ConfigureUrls(configuration); ConfigureConsul(context, configuration); ConfigAntiForgery(); + ConfigureAbpExceptions(context); + } + + /// + /// 异常处理 + /// + private void ConfigureAbpExceptions(ServiceConfigurationContext context) + { + context.Services.AddMvc + ( + options => + { + options.Filters.Add(typeof(LionExceptionFilter)); + options.Filters.Add(typeof(LionResultFilter)); + } + ); } - /// /// 阻止跨站点请求伪造 /// https://docs.microsoft.com/zh-cn/aspnet/core/security/anti-request-forgery?view=aspnetcore-6.0 /// private void ConfigAntiForgery() { - Configure(options => - { - options.AutoValidate = false; - }); + Configure(options => { options.AutoValidate = false; }); } + private void ConfigureConsul(ServiceConfigurationContext context, IConfiguration configuration) { @@ -41,7 +56,6 @@ namespace Lion.AbpPro.Shared.Hosting.Microservices } - /// /// 配置跨域 /// @@ -75,10 +89,7 @@ namespace Lion.AbpPro.Shared.Hosting.Microservices /// private void ConfigureUrls(IConfiguration configuration) { - Configure(options => - { - options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"]; - }); + Configure(options => { options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"]; }); } /// From 63c6e6b5c246fe6d76ae6ba2b6081f75217ef0bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=86=9B?= <510423039@qq.com> Date: Mon, 7 Nov 2022 17:09:25 +0800 Subject: [PATCH 4/9] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=AD=97=E5=85=B8=E6=98=8E=E6=98=BE=E6=9F=A5=E8=AF=A2=20#76?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataDictionaries/DataDictionaryAppService.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/aspnet-core/modules/DataDictionaryManagement/src/Lion.AbpPro.DataDictionaryManagement.Application/DataDictionaries/DataDictionaryAppService.cs b/aspnet-core/modules/DataDictionaryManagement/src/Lion.AbpPro.DataDictionaryManagement.Application/DataDictionaries/DataDictionaryAppService.cs index a99f07b9..d523a0e4 100644 --- a/aspnet-core/modules/DataDictionaryManagement/src/Lion.AbpPro.DataDictionaryManagement.Application/DataDictionaries/DataDictionaryAppService.cs +++ b/aspnet-core/modules/DataDictionaryManagement/src/Lion.AbpPro.DataDictionaryManagement.Application/DataDictionaries/DataDictionaryAppService.cs @@ -56,7 +56,10 @@ namespace Lion.AbpPro.DataDictionaryManagement.DataDictionaries var details = entity.Details .WhereIf(input.Filter.IsNotNullOrWhiteSpace(), e => (e.Code.Contains(input.Filter) || e.DisplayText.Contains(input.Filter))) .OrderBy(e => e.Order) - .Take(input.PageSize).Skip(input.SkipCount).ToList(); + .ThenBy(e=> e.CreationTime) + .Skip(input.SkipCount) + .Take(input.PageSize) + .ToList(); if (details.Count == 0) { return new PagedResultDto(); From fb66a3837743f1d4c4c1d384bbfacbf4149088ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=86=9B?= <510423039@qq.com> Date: Mon, 7 Nov 2022 17:11:28 +0800 Subject: [PATCH 5/9] =?UTF-8?q?fix:=20=E9=94=81=E5=B1=8F=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vben28/src/views/sys/lock/useNow.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/vben28/src/views/sys/lock/useNow.ts b/vben28/src/views/sys/lock/useNow.ts index 2fac748d..e42a805b 100644 --- a/vben28/src/views/sys/lock/useNow.ts +++ b/vben28/src/views/sys/lock/useNow.ts @@ -1,11 +1,8 @@ import { dateUtil } from '/@/utils/dateUtil'; import { reactive, toRefs } from 'vue'; -import { useLocaleStore } from '/@/store/modules/locale'; import { tryOnMounted, tryOnUnmounted } from '@vueuse/core'; export function useNow(immediate = true) { - const localeStore = useLocaleStore(); - const localData = dateUtil.localeData(localeStore.getLocale); let timer: IntervalHandle; const state = reactive({ @@ -28,13 +25,13 @@ export function useNow(immediate = true) { state.year = now.get('y'); state.month = now.get('M') + 1; - state.week = localData.weekdays()[now.day()]; - state.day = now.get('D'); + state.week = '星期' + ['日', '一', '二', '三', '四', '五', '六'][now.day()]; + state.day = now.get('date'); state.hour = h; state.minute = m; state.second = s; - state.meridiem = localData.meridiem(Number(h), Number(h), true); + state.meridiem = now.format('A'); }; function start() { @@ -60,4 +57,4 @@ export function useNow(immediate = true) { start, stop, }; -} +} \ No newline at end of file From 149797368bd96f0d419298f58d717cab253c3700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=86=9B?= <510423039@qq.com> Date: Mon, 7 Nov 2022 17:24:12 +0800 Subject: [PATCH 6/9] =?UTF-8?q?feat:=20Hangfire=E5=88=87=E6=8D=A2redis?= =?UTF-8?q?=E5=81=9A=E6=8C=81=E4=B9=85=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aspnet-core/Directory.Build.targets | 1 - .../AbpProHttpApiHostModule.cs | 17 +++-------------- .../Lion.AbpPro.HttpApi.Host/GlobalUsings.cs | 1 - .../Lion.AbpPro.HttpApi.Host.csproj | 2 +- .../Lion.AbpPro.HttpApi.Host/appsettings.json | 3 ++- 5 files changed, 6 insertions(+), 18 deletions(-) diff --git a/aspnet-core/Directory.Build.targets b/aspnet-core/Directory.Build.targets index 2f57249c..241a3818 100644 --- a/aspnet-core/Directory.Build.targets +++ b/aspnet-core/Directory.Build.targets @@ -41,7 +41,6 @@ - diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs index 954621c2..33526c96 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs @@ -32,7 +32,7 @@ namespace Lion.AbpPro ConfigureCache(context); ConfigureSwaggerServices(context); ConfigureJwtAuthentication(context, configuration); - ConfigureHangfireMysql(context); + ConfigureHangfire(context); ConfigureMiniProfiler(context); ConfigureIdentity(context); ConfigureCap(context); @@ -84,24 +84,13 @@ namespace Lion.AbpPro } - private void ConfigureHangfireMysql(ServiceConfigurationContext context) + private void ConfigureHangfire(ServiceConfigurationContext context) { Configure(options => { options.IsJobExecutionEnabled = true; }); context.Services.AddHangfireServer(); context.Services.AddHangfire(config => { - config.UseStorage(new MySqlStorage( - context.Services.GetConfiguration().GetConnectionString("Default"), - new MySqlStorageOptions() - { - //CommandBatchMaxTimeout = TimeSpan.FromMinutes(5), - //SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5), - //QueuePollInterval = TimeSpan.Zero, - //UseRecommendedIsolationLevel = true, - //DisableGlobalLocks = true - JobExpirationCheckInterval = TimeSpan.FromMinutes(30), - TablesPrefix = "Hangfire_" - })); + config.UseRedisStorage(ConnectionMultiplexer.Connect(context.Services.GetConfiguration().GetConnectionString("Hangfire"))); var delaysInSeconds = new[] { 10, 60, 60 * 3 }; // 重试时间间隔 const int Attempts = 3; // 重试次数 config.UseFilter(new AutomaticRetryAttribute() { Attempts = Attempts, DelaysInSeconds = delaysInSeconds }); diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/GlobalUsings.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/GlobalUsings.cs index c2d5718b..68b96b4e 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/GlobalUsings.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/GlobalUsings.cs @@ -10,7 +10,6 @@ global using System.Threading.Tasks; global using Hangfire; global using Hangfire.Common; global using Hangfire.Dashboard; -global using Hangfire.MySql; global using Hangfire.States; global using Hangfire.Storage; global using Lion.AbpPro.CAP; diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj index 75991b9a..a54d269b 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj @@ -29,7 +29,7 @@ - + diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/appsettings.json b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/appsettings.json index 0bafe67d..87d1f3f5 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/appsettings.json +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/appsettings.json @@ -34,7 +34,8 @@ "CorsOrigins": "https://*.AbpPro.com,http://localhost:4200,http://localhost:3100" }, "ConnectionStrings": { - "Default": "Data Source=localhost;Port=3306;Database=LionAbpProDB;uid=root;pwd=1q2w3E*;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true" + "Default": "Data Source=localhost;Port=3306;Database=LionAbpProDB;uid=root;pwd=1q2w3E*;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true", + "Hangfire": "localhost:6379,defaultdatabase=1" }, "Redis": { "Configuration": "localhost,password=1q2w3E*,defaultdatabase=1" From 2c5c3d6ac1e8b3a7131f1a62ff01edccb14e5f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=86=9B?= <510423039@qq.com> Date: Mon, 7 Nov 2022 20:57:36 +0800 Subject: [PATCH 7/9] =?UTF-8?q?doc:=20=E4=BF=AE=E6=94=B9=E6=BC=94=E7=A4=BA?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Readme.md | 1 - 1 file changed, 1 deletion(-) diff --git a/Readme.md b/Readme.md index 44252413..61c5fe27 100644 --- a/Readme.md +++ b/Readme.md @@ -11,7 +11,6 @@ ## 🔗 链接 - [文档地址](http://doc.cncore.club/) -- [演示地址](http://116.205.176.173/) - [视频教程](https://www.bilibili.com/video/BV1pt4y1E7aZ) From 3933d0d05387b6db5e7d61e4cda4e878ceea5baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=86=9B?= <510423039@qq.com> Date: Tue, 8 Nov 2022 15:53:41 +0800 Subject: [PATCH 8/9] =?UTF-8?q?feat:=20=E5=8D=87=E7=BA=A7abp=206.0.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aspnet-core/Directory.Build.Volo.targets | 176 +++++++++++------------ aspnet-core/Directory.Build.targets | 37 +++-- 2 files changed, 105 insertions(+), 108 deletions(-) diff --git a/aspnet-core/Directory.Build.Volo.targets b/aspnet-core/Directory.Build.Volo.targets index a74edab0..c51f5abe 100644 --- a/aspnet-core/Directory.Build.Volo.targets +++ b/aspnet-core/Directory.Build.Volo.targets @@ -1,92 +1,92 @@  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/aspnet-core/Directory.Build.targets b/aspnet-core/Directory.Build.targets index 241a3818..53ef2d19 100644 --- a/aspnet-core/Directory.Build.targets +++ b/aspnet-core/Directory.Build.targets @@ -6,7 +6,7 @@ latest 1.0.0 - $(NoWarn);CS1591;CS0436 + $(NoWarn);CS1591;CS0436;NU1504 app true WangJunZzz @@ -32,23 +32,22 @@ - - - + + + - - + - - - - - - + + + + + + @@ -65,8 +64,9 @@ - - + + + @@ -75,16 +75,13 @@ - - - + + - - - + From f151cc66f9683af576296e37126f914014be79fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=86=9B?= <510423039@qq.com> Date: Mon, 14 Nov 2022 15:49:35 +0800 Subject: [PATCH 9/9] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9eslint=E8=A7=84?= =?UTF-8?q?=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vben28/.eslintignore | 1 + vben28/src/services/ServiceProxyBase.ts | 18 +++++++++--------- vben28/tsconfig.json | 8 +++++++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/vben28/.eslintignore b/vben28/.eslintignore index 348631b2..70e7235e 100644 --- a/vben28/.eslintignore +++ b/vben28/.eslintignore @@ -13,3 +13,4 @@ dist .local /bin Dockerfile +/src/services/ServiceProxies.ts diff --git a/vben28/src/services/ServiceProxyBase.ts b/vben28/src/services/ServiceProxyBase.ts index 527997e8..1a763f69 100644 --- a/vben28/src/services/ServiceProxyBase.ts +++ b/vben28/src/services/ServiceProxyBase.ts @@ -15,15 +15,15 @@ export class ServiceProxyBase { if (!guard) { if (userStore.checkUserLoginExpire) { router.replace(PageEnum.BASE_LOGIN); - return; + } else { + // 添加header + options.headers = { + 'accept-language': language, + 'Content-Type': 'application/json', + Authorization: 'Bearer ' + token, + __tenant: userStore.tenantId, + }; } - // 添加header - options.headers = { - 'accept-language': language, - 'Content-Type': 'application/json', - Authorization: 'Bearer ' + token, - __tenant: userStore.tenantId, - }; } else { options.headers = { 'Content-Type': 'application/json', @@ -37,7 +37,7 @@ export class ServiceProxyBase { protected transformResult( _url: string, response: AxiosResponse, - processor: (response: AxiosResponse) => Promise + processor: (response: AxiosResponse) => Promise, ): Promise { const { t } = useI18n(); diff --git a/vben28/tsconfig.json b/vben28/tsconfig.json index 76e91f26..ac067bb5 100644 --- a/vben28/tsconfig.json +++ b/vben28/tsconfig.json @@ -40,5 +40,11 @@ "mock/**/*.ts", "vite.config.ts" ], - "exclude": ["node_modules", "tests/server/**/*.ts", "dist", "**/*.js"] + "exclude": [ + "node_modules", + "tests/server/**/*.ts", + "dist", + "**/*.js", + "src/services/ServiceProxies.ts" + ] }