From 1377d25967698b28401352e1c3d2923a9f850ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E6=98=8E=E9=94=8B?= Date: Tue, 3 Oct 2023 00:40:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?wip:=20(ui)=20=E5=B0=86AjaxResult=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=BC=BA=E7=B1=BB=E5=9E=8B=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/IdentityController.cs | 2 +- .../Hangfire/HangfireJobRunner.cs | 4 +- src/OSharp.AspNetCore/UI/AjaxResult.cs | 68 ++++++++++++++++--- .../UI/AjaxResultExtensions.cs | 39 +++++++++-- 4 files changed, 96 insertions(+), 17 deletions(-) diff --git a/samples/web/Liuliu.Demo.Web/Controllers/IdentityController.cs b/samples/web/Liuliu.Demo.Web/Controllers/IdentityController.cs index 0c00f46e..6a4d3423 100644 --- a/samples/web/Liuliu.Demo.Web/Controllers/IdentityController.cs +++ b/samples/web/Liuliu.Demo.Web/Controllers/IdentityController.cs @@ -229,7 +229,7 @@ public async Task Token(TokenDto dto) User user = result.Data; JsonWebToken token = await CreateJwtToken(user, dto.ClientType); await unitOfWork.CommitAsync(); - return new AjaxResult("登录成功", AjaxResultType.Success, token); + return new AjaxResult("登录成功", AjaxResultType.Success, token); } if (grantType == GrantType.RefreshToken) diff --git a/samples/web/Liuliu.Demo.Web/Hangfire/HangfireJobRunner.cs b/samples/web/Liuliu.Demo.Web/Hangfire/HangfireJobRunner.cs index 033dd2fb..084caacc 100644 --- a/samples/web/Liuliu.Demo.Web/Hangfire/HangfireJobRunner.cs +++ b/samples/web/Liuliu.Demo.Web/Hangfire/HangfireJobRunner.cs @@ -36,8 +36,8 @@ public void Start() BackgroundJob.Enqueue>(m => m.FindByIdAsync("1")); string jobId = BackgroundJob.Schedule>(m => m.FindByIdAsync("2"), TimeSpan.FromMinutes(2)); BackgroundJob.ContinueJobWith(jobId, m => m.GetUserCount()); - RecurringJob.AddOrUpdate(m => m.GetUserCount(), Cron.Minutely, TimeZoneInfo.Local); - RecurringJob.AddOrUpdate(m=>m.LockUser2(), Cron.Minutely, TimeZoneInfo.Local); + RecurringJob.AddOrUpdate("TestHangfireJob.GetUserCount", m => m.GetUserCount(), Cron.Minutely); + RecurringJob.AddOrUpdate("TestHangfireJob.LockUser2", m => m.LockUser2(), Cron.Minutely); } } diff --git a/src/OSharp.AspNetCore/UI/AjaxResult.cs b/src/OSharp.AspNetCore/UI/AjaxResult.cs index 89119851..03bc90d6 100644 --- a/src/OSharp.AspNetCore/UI/AjaxResult.cs +++ b/src/OSharp.AspNetCore/UI/AjaxResult.cs @@ -24,10 +24,17 @@ public AjaxResult() /// /// 初始化一个类型的新实例 /// - public AjaxResult(string content, AjaxResultType type = AjaxResultType.Success, object data = null) + public AjaxResult(string content, AjaxResultType type = AjaxResultType.Success, object data = default) : this(content, data, type) { } + /// + /// 初始化一个类型的新实例 + /// + public AjaxResult(object data, AjaxResultType type = AjaxResultType.Success, string content = null) + : this(content ?? type.ToDescription(), data, type) + { } + /// /// 初始化一个类型的新实例 /// @@ -38,13 +45,6 @@ public AjaxResult(string content, object data, AjaxResultType type = AjaxResultT Data = data; } - /// - /// 初始化一个类型的新实例 - /// - public AjaxResult(object data, AjaxResultType type = AjaxResultType.Success, string content = null) - : this(content ?? type.ToDescription(), data, type) - { } - /// /// 获取或设置 Ajax操作结果类型 /// @@ -84,3 +84,55 @@ public static AjaxResult Success(object data = null) return new AjaxResult("操作执行成功", AjaxResultType.Success, data); } } + + + +/// +/// 表示Ajax操作结果 +/// +public class AjaxResult : AjaxResult +{ + /// + /// 初始化一个类型的新实例 + /// + public AjaxResult() + : this(null) + { } + + /// + /// 初始化一个类型的新实例 + /// + public AjaxResult(string content, AjaxResultType type = AjaxResultType.Success, T data = default) + : this(content, data, type) + { } + + /// + /// 初始化一个类型的新实例 + /// + public AjaxResult(T data, AjaxResultType type = AjaxResultType.Success, string content = null) + : this(content ?? type.ToDescription(), data, type) + { } + + /// + /// 初始化一个类型的新实例 + /// + public AjaxResult(string content, T data, AjaxResultType type = AjaxResultType.Success) + { + Type = type; + Content = content; + Data = data; + } + + /// + /// 获取或设置 返回数据 + /// + public new T Data { get; set; } + + /// + /// 成功的AjaxResult + /// + public static AjaxResult Success(T data = default) + { + return new AjaxResult("操作执行成功", AjaxResultType.Success, data); + } +} diff --git a/src/OSharp.AspNetCore/UI/AjaxResultExtensions.cs b/src/OSharp.AspNetCore/UI/AjaxResultExtensions.cs index 12c8f244..e4d2e205 100644 --- a/src/OSharp.AspNetCore/UI/AjaxResultExtensions.cs +++ b/src/OSharp.AspNetCore/UI/AjaxResultExtensions.cs @@ -17,12 +17,39 @@ public static class AjaxResultExtensions /// /// 将业务操作结果转ajax操作结果,并处理强类型的 OperationResult.Data /// - public static AjaxResult ToAjaxResult(this OperationResult result, Func dataFunc = null) + public static AjaxResult ToAjaxResult(this OperationResult result, Func dataFunc = null) { string content = result.Message ?? result.ResultType.ToDescription(); AjaxResultType type = result.ResultType.ToAjaxResultType(); - object data = dataFunc == null ? result.Data : dataFunc(result.Data); - return new AjaxResult(content, type, data); + T data = dataFunc == null ? result.Data : dataFunc(result.Data); + return new AjaxResult(content, type, data); + } + + /// + /// 将业务操作结果转ajax操作结果,并处理强类型的 OperationResult.Data + /// + public static AjaxResult ToAjaxResult(this OperationResult result, Func dataFunc = null) + { + string content = result.Message ?? result.ResultType.ToDescription(); + AjaxResultType type = result.ResultType.ToAjaxResultType(); + TResult data; + if (dataFunc == null) + { + if (result.Data is TResult data2) + { + data = data2; + } + else + { + data = default; + } + } + else + { + data = dataFunc(result.Data); + } + + return new AjaxResult(content, type, data); } /// @@ -41,11 +68,11 @@ public static AjaxResult ToAjaxResult(this OperationResult result, bool contains /// /// 将业务操作结果转ajax操作结果,会将 object 类型的 OperationResult.Data 转换为强类型 T,再通过 dataFunc 进行进一步处理 /// - public static AjaxResult ToAjaxResult(this OperationResult result, Func dataFunc) + public static AjaxResult ToAjaxResult(this OperationResult result, Func dataFunc) { string content = result.Message ?? result.ResultType.ToDescription(); AjaxResultType type = result.ResultType.ToAjaxResultType(); - object data = null; + T data = default; if (result.Data != null) { if (dataFunc != null && result.Data is T resultData) @@ -53,7 +80,7 @@ public static AjaxResult ToAjaxResult(this OperationResult result, Func(content, type, data); } /// From 0ae7a950c55d2f9dcb22ddcd9251b9e1992796dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E6=98=8E=E9=94=8B?= Date: Tue, 3 Oct 2023 01:03:19 +0800 Subject: [PATCH 2/2] update readme.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c727189c..79be169e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # OSharp Framework [![Member project of .NET Core Community](https://img.shields.io/badge/member%20project%20of-NCC-9e20c9.svg)](https://github.com/dotnetcore) -[![depoly action](https://github.com/dotnetcore/osharp/workflows/Build/Test/MirrorToGitee/badge.svg)](https://github.com/dotnetcore/osharp/actions/workflows/ci.yml) +[![depoly action](https://img.shields.io/github/actions/workflow/status/dotnetcore/osharp/ci.yml +)](https://github.com/dotnetcore/osharp/actions/workflows/ci.yml) [![NuGet Badge](https://buildstats.info/nuget/osharp.core)](https://www.nuget.org/packages/osharpns/) [![GitHub license](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://raw.githubusercontent.com/i66soft/osharp-ns20/master/LICENSE) @@ -67,6 +68,7 @@ OSharp 全称 OSharp Framework with .NetStandard2.x,是一个基于.NetStandar |包名称|稳定版本|预览版本|下载数| |----|----|----|----| +|[OSharp.Utils](https://www.nuget.org/packages/OSharp.Utils/)|[![OSharp.Utils](https://img.shields.io/nuget/v/OSharp.Utils.svg)](https://www.nuget.org/packages/OSharp.Utils/)|[![OSharp.Utils](https://img.shields.io/nuget/vpre/OSharp.Utils.svg)](https://www.nuget.org/packages/OSharp.Utils/)|[![OSharp.Utils](https://img.shields.io/nuget/dt/OSharp.Utils.svg)](https://www.nuget.org/packages/OSharp.Utils/)| |[OSharp.Core](https://www.nuget.org/packages/OSharp.Core/)|[![OSharp.Core](https://img.shields.io/nuget/v/OSharp.Core.svg)](https://www.nuget.org/packages/OSharp.Core/)|[![OSharp.Core](https://img.shields.io/nuget/vpre/OSharp.Core.svg)](https://www.nuget.org/packages/OSharp.Core/)|[![OSharp.Core](https://img.shields.io/nuget/dt/OSharp.Core.svg)](https://www.nuget.org/packages/OSharp.Core/)| |[OSharp.AspNetCore](https://www.nuget.org/packages/OSharp.AspNetCore/)|[![OSharp.AspNetCore](https://img.shields.io/nuget/v/OSharp.AspNetCore.svg)](https://www.nuget.org/packages/OSharp.AspNetCore/)|[![OSharp.AspNetCore](https://img.shields.io/nuget/vpre/OSharp.AspNetCore.svg)](https://www.nuget.org/packages/OSharp.AspNetCore/)|[![OSharp.AspNetCore](https://img.shields.io/nuget/dt/OSharp.AspNetCore.svg)](https://www.nuget.org/packages/OSharp.AspNetCore/)| |[OSharp.Authorization.Datas](https://www.nuget.org/packages/OSharp.Authorization.Datas/)|[![OSharp.Authorization.Datas](https://img.shields.io/nuget/v/OSharp.Authorization.Datas.svg)](https://www.nuget.org/packages/OSharp.Authorization.Datas/)|[![OSharp.Authorization.Datas](https://img.shields.io/nuget/vpre/OSharp.Authorization.Datas.svg)](https://www.nuget.org/packages/OSharp.Authorization.Datas/)|[![OSharp.Authorization.Datas](https://img.shields.io/nuget/dt/OSharp.Authorization.Datas.svg)](https://www.nuget.org/packages/OSharp.Authorization.Datas/)| @@ -79,8 +81,6 @@ OSharp 全称 OSharp Framework with .NetStandard2.x,是一个基于.NetStandar |[OSharp.EntityFrameworkCore.PostgreSql](https://www.nuget.org/packages/OSharp.EntityFrameworkCore.PostgreSql/)|[![OSharp.EntityFrameworkCore.PostgreSql](https://img.shields.io/nuget/v/OSharp.EntityFrameworkCore.PostgreSql.svg)](https://www.nuget.org/packages/OSharp.EntityFrameworkCore.PostgreSql/)|[![OSharp.EntityFrameworkCore.PostgreSql](https://img.shields.io/nuget/vpre/OSharp.EntityFrameworkCore.PostgreSql.svg)](https://www.nuget.org/packages/OSharp.EntityFrameworkCore.PostgreSql/)|[![OSharp.EntityFrameworkCore.PostgreSql](https://img.shields.io/nuget/dt/OSharp.EntityFrameworkCore.PostgreSql.svg)](https://www.nuget.org/packages/OSharp.EntityFrameworkCore.PostgreSql/)| |[OSharp.Hangfire](https://www.nuget.org/packages/OSharp.Hangfire/)|[![OSharp.Hangfire](https://img.shields.io/nuget/v/OSharp.Hangfire.svg)](https://www.nuget.org/packages/OSharp.Hangfire/)|[![OSharp.Hangfire](https://img.shields.io/nuget/vpre/OSharp.Hangfire.svg)](https://www.nuget.org/packages/OSharp.Hangfire/)|[![OSharp.Hangfire](https://img.shields.io/nuget/dt/OSharp.Hangfire.svg)](https://www.nuget.org/packages/OSharp.Hangfire/)||[OSharp.Identity](https://www.nuget.org/packages/OSharp.Identity/)|[![OSharp.Identity](https://img.shields.io/nuget/v/OSharp.Identity.svg)](https://www.nuget.org/packages/OSharp.Identity/)| |[OSharp.Identity](https://www.nuget.org/packages/OSharp.Identity/)|[![OSharp.Identity](https://img.shields.io/nuget/v/OSharp.Identity.svg)](https://www.nuget.org/packages/OSharp.Identity/)|[![OSharp.Identity](https://img.shields.io/nuget/vpre/OSharp.Identity.svg)](https://www.nuget.org/packages/OSharp.Identity/)|[![OSharp.Identity](https://img.shields.io/nuget/dt/OSharp.Identity.svg)](https://www.nuget.org/packages/OSharp.Identity/)| -|[OSharp.IdentityServer](https://www.nuget.org/packages/OSharp.IdentityServer/)|[![OSharp.IdentityServer](https://img.shields.io/nuget/v/OSharp.IdentityServer.svg)](https://www.nuget.org/packages/OSharp.IdentityServer/)|[![OSharp.IdentityServer](https://img.shields.io/nuget/vpre/OSharp.IdentityServer.svg)](https://www.nuget.org/packages/OSharp.IdentityServer/)|[![OSharp.IdentityServer](https://img.shields.io/nuget/dt/OSharp.IdentityServer.svg)](https://www.nuget.org/packages/OSharp.IdentityServer/)| -|[OSharp.IdentityServer.EntityConfiguration](https://www.nuget.org/packages/OSharp.IdentityServer.EntityConfiguration/)|[![OSharp.IdentityServer.EntityConfiguration](https://img.shields.io/nuget/v/OSharp.IdentityServer.EntityConfiguration.svg)](https://www.nuget.org/packages/OSharp.IdentityServer.EntityConfiguration/)|[![OSharp.IdentityServer.EntityConfiguration](https://img.shields.io/nuget/vpre/OSharp.IdentityServer.EntityConfiguration.svg)](https://www.nuget.org/packages/OSharp.IdentityServer.EntityConfiguration/)|[![OSharp.IdentityServer.EntityConfiguration](https://img.shields.io/nuget/dt/OSharp.IdentityServer.EntityConfiguration.svg)](https://www.nuget.org/packages/OSharp.IdentityServer.EntityConfiguration/)| |[OSharp.Log4Net](https://www.nuget.org/packages/OSharp.Log4Net/)|[![OSharp.Log4Net](https://img.shields.io/nuget/v/OSharp.Log4Net.svg)](https://www.nuget.org/packages/OSharp.Log4Net/)|[![OSharp.Log4Net](https://img.shields.io/nuget/vpre/OSharp.Log4Net.svg)](https://www.nuget.org/packages/OSharp.Log4Net/)|[![OSharp.Log4Net](https://img.shields.io/nuget/dt/OSharp.Log4Net.svg)](https://www.nuget.org/packages/OSharp.Log4Net/)| |[OSharp.MiniProfiler](https://www.nuget.org/packages/OSharp.MiniProfiler/)|[![OSharp.MiniProfiler](https://img.shields.io/nuget/v/OSharp.MiniProfiler.svg)](https://www.nuget.org/packages/OSharp.MiniProfiler/)|[![OSharp.MiniProfiler](https://img.shields.io/nuget/vpre/OSharp.MiniProfiler.svg)](https://www.nuget.org/packages/OSharp.MiniProfiler/)|[![OSharp.MiniProfiler](https://img.shields.io/nuget/dt/OSharp.MiniProfiler.svg)](https://www.nuget.org/packages/OSharp.MiniProfiler/)| |[OSharp.Redis](https://www.nuget.org/packages/OSharp.Redis/)|[![OSharp.Redis](https://img.shields.io/nuget/v/OSharp.Redis.svg)](https://www.nuget.org/packages/OSharp.Redis/)|[![OSharp.Redis](https://img.shields.io/nuget/vpre/OSharp.Redis.svg)](https://www.nuget.org/packages/OSharp.Redis/)|[![OSharp.Redis](https://img.shields.io/nuget/dt/OSharp.Redis.svg)](https://www.nuget.org/packages/OSharp.Redis/)| @@ -328,4 +328,4 @@ OSharp 当前版本(6.0.0)使用了 `.net` 当前最新版本 `6.0.0`,所 ## 感谢 [![](https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE1Mu3b?ver=5c31)](https://dotnet.microsoft.com/zh-cn/) -[![JetBrains Resharper](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/resharper/) \ No newline at end of file +[![JetBrains Resharper](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/resharper/)