From e7b8a9ef51019b3ddd573436fff00fc10a4114e2 Mon Sep 17 00:00:00 2001 From: zhangpeihang <948869991@qq.com> Date: Fri, 14 Jan 2022 22:37:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=89=8D=E5=8F=B0?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=9C=AA=E5=AE=8C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppInfo.cs | 62 +++++++++++++++++ .../Services/DictService.cs | 26 ++++++- .../admin/BootstrapAdmin.Web.Core/IDict.cs | 22 +++++- .../Components/FrontAppDialog.razor | 67 +++++++++++++++++++ .../Pages/Admin/Settings.razor | 24 ++++++- .../Pages/Admin/Settings.razor.cs | 41 +++++++++++- .../Validators/AppIdValidator.cs | 46 +++++++++++++ 7 files changed, 277 insertions(+), 11 deletions(-) create mode 100644 src/blazor/admin/BootstrapAdmin.Web/Components/FrontAppDialog.razor create mode 100644 src/blazor/admin/BootstrapAdmin.Web/Validators/AppIdValidator.cs diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/AppInfo.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/AppInfo.cs index 20c952df..9b0446fd 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/AppInfo.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/AppInfo.cs @@ -152,6 +152,68 @@ public class AppInfo [Required(ErrorMessage = "{0}不可为空")] public int IPCacheExpired { get; set; } + /// + /// + /// + [NotNull] + public Dictionary? FrontApp { get; set; } + + /// + /// + /// + [NotNull] + [Display(Name = "应用ID")] + [Required(ErrorMessage = "{0}不可为空")] + public string? AppID { get; set; } + + /// + /// + /// + [NotNull] + [Display(Name = "应用名称")] + [Required(ErrorMessage = "{0}不可为空")] + public string? AppName { get; set; } + + /// + /// + /// + [NotNull] + [Display(Name = "应用首页")] + [Required(ErrorMessage = "{0}不可为空")] + public string? Home { get; set; } + + /// + /// + /// + [NotNull] + [Display(Name = "网站标题")] + [Required(ErrorMessage = "{0}不可为空")] + public string? WebTitle { get; set; } + + /// + /// + /// + [NotNull] + [Display(Name = "网站页脚")] + [Required(ErrorMessage = "{0}不可为空")] + public string? WebFooter { get; set; } + + /// + /// + /// + [NotNull] + [Display(Name = "网站图标")] + [Required(ErrorMessage = "{0}不可为空")] + public string? WebIcon { get; set; } + + /// + /// + /// + [NotNull] + [Display(Name = "Favicon")] + [Required(ErrorMessage = "{0}不可为空")] + public string? Favicon { get; set; } + /// /// /// diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DictService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DictService.cs index b0980a4d..e73393f6 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DictService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DictService.cs @@ -314,13 +314,15 @@ class DictService : IDict public bool SaveAutoLockScreen(bool value) => SaveDict(new Dict { Category = "网站设置", Name = "自动锁屏", Code = value ? "1" : "0" }); - public string? GetAutoLockScreenInterval() + public int GetAutoLockScreenInterval() { var dicts = GetAll(); - return dicts.FirstOrDefault(s => s.Category == "网站设置" && s.Name == "自动锁屏时长" && s.Define == EnumDictDefine.System)?.Code; + var value = dicts.FirstOrDefault(s => s.Category == "网站设置" && s.Name == "自动锁屏时长" && s.Define == EnumDictDefine.System)?.Code ?? "0"; + _ = int.TryParse(value, out var ret); + return ret; } - public bool SaveAutoLockScreenInterval(string value) => SaveDict(new Dict { Category = "网站设置", Name = "自动锁屏时长", Code = value }); + public bool SaveAutoLockScreenInterval(int value) => SaveDict(new Dict { Category = "网站设置", Name = "自动锁屏时长", Code = value.ToString() }); public Dictionary GetIps() { @@ -396,4 +398,22 @@ class DictService : IDict } public bool SaveIPCacheExpired(int value) => SaveDict(new Dict { Category = "网站设置", Name = "IP请求缓存时长", Code = value.ToString() }); + + public Dictionary GetFrontApp() + { + var dicts = GetAll(); + return dicts.Where(s => s.Category == "应用程序" && s.Code != "BA").ToDictionary(s => s.Name, s => s.Code); + } + + public string GetFrontUrl(string name) + { + var dicts = GetAll(); + return dicts.Where(s => s.Category == "应用首页" && s.Name == name).FirstOrDefault()?.Code ?? ""; + } + + public string? GetAppNameByAppName(string name) + { + var dicts = GetAll(); + return dicts.Where(s => s.Category == "应用程序" && s.Code == name).FirstOrDefault()?.Name; + } } diff --git a/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs b/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs index 1bab27a8..a4608fbf 100644 --- a/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs +++ b/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs @@ -257,13 +257,13 @@ public interface IDict /// 获得自动锁屏间隔时间 /// /// - string? GetAutoLockScreenInterval(); + int GetAutoLockScreenInterval(); /// /// 保存自动锁屏间隔时间 /// /// - bool SaveAutoLockScreenInterval(string value); + bool SaveAutoLockScreenInterval(int value); /// /// 获得地理位置服务 @@ -354,4 +354,22 @@ public interface IDict /// /// bool SaveIPCacheExpired(int value); + + /// + /// 获得前台应用 + /// + /// + Dictionary? GetFrontApp(); + + /// + /// 获得前台应用 + /// + /// + string GetFrontUrl(string name); + + /// + /// 获得前台应用 + /// + /// + string? GetAppNameByAppName(string name); } diff --git a/src/blazor/admin/BootstrapAdmin.Web/Components/FrontAppDialog.razor b/src/blazor/admin/BootstrapAdmin.Web/Components/FrontAppDialog.razor new file mode 100644 index 00000000..606c8257 --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.Web/Components/FrontAppDialog.razor @@ -0,0 +1,67 @@ +@using BootstrapAdmin.Web.Core; +@using BootstrapAdmin.Web.Validators; + + +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ +@code{ + + /// + /// + /// + [NotNull] + [Parameter] + public AppInfo? Value { get; set; } + + /// + /// + /// + [Parameter] + public EventCallback? ValueChanged { get; set; } + + [NotNull] + [Inject] + private IDict? DictService { get; set; } + + private List Validators = new List(); + + protected override void OnInitialized() + { + base.OnInitialized(); + if (Value?.AppID == null) + { + Validators.Add(new AppIdValidator(DictService)); + } + } + + private Task CreateFrontApp(EditContext context) + { + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Settings.razor b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Settings.razor index a8fcba0c..238a8f9d 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Settings.razor +++ b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Settings.razor @@ -47,11 +47,29 @@ + +
+ @foreach (var item in AppInfo.FrontApp) + { + var value = DictService.GetFrontUrl(item.Value); +
+ + +
+ } +
+
+
+
+ 注意:本设置将覆盖 个人中心 中设置的网站样式覆盖本设置 -
@@ -133,7 +151,7 @@ - +
@@ -146,7 +164,7 @@ - +
diff --git a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Settings.razor.cs b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Settings.razor.cs index d6567291..e2fcaeed 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Settings.razor.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Settings.razor.cs @@ -1,4 +1,5 @@ using BootstrapAdmin.DataAccess.Models; +using BootstrapAdmin.Web.Components; using BootstrapAdmin.Web.Core; using BootstrapAdmin.Web.Extensions; using Microsoft.AspNetCore.Components.Forms; @@ -36,6 +37,10 @@ public partial class Settings [NotNull] private ToastService? ToastService { get; set; } + [Inject] + [NotNull] + private DialogService? DialogService { get; set; } + /// /// /// @@ -61,13 +66,14 @@ public partial class Settings MobileLogin = DictService.GetAppMobileLogin(), OAuthLogin = DictService.GetAppOAuthLogin(), AutoLock = DictService.GetAutoLockScreen(), - Interval = Convert.ToInt32(DictService.GetAutoLockScreenInterval()), + Interval = DictService.GetAutoLockScreenInterval(), ExceptionExpired = DictService.GetExceptionExpired(), OperateExpired = DictService.GetOperateExpired(), LoginExpired = DictService.GetLoginExpired(), AccessExpired = DictService.GetAccessExpired(), CookieExpired = DictService.GetCookieExpiresPeriod(), IPCacheExpired = DictService.GetIPCacheExpired(), + FrontApp = DictService.GetFrontApp() }; } @@ -137,14 +143,14 @@ public partial class Settings private async Task OnSaveSaveAppLogin(EditContext context) { var ret = DictService.SaveAppMobileLogin(AppInfo.MobileLogin); - DictService.SaveAppOAuthLogin(AppInfo.TitleSetting); + DictService.SaveAppOAuthLogin(AppInfo.OAuthLogin); await ShowToast(ret, "网站登录"); } private async Task OnSaveAppLockScreen(EditContext context) { var ret = DictService.SaveAutoLockScreen(AppInfo.AutoLock); - DictService.SaveAutoLockScreenInterval(AppInfo.Interval.ToString()); + DictService.SaveAutoLockScreenInterval(AppInfo.Interval); await ShowToast(ret, "自动锁屏"); } @@ -165,4 +171,33 @@ public partial class Settings await ShowToast(ret, "日志缓存"); } + + private async Task OnSaveFrontApp() + { + + DialogOption option = new DialogOption + { + Title = "添加前台应用", + BodyTemplate = BootstrapDynamicComponent.CreateComponent(new Dictionary + { + [nameof(FrontAppDialog.Value)] = AppInfo + }).Render(), + ShowFooter = false, + }; + await DialogService.Show(option); + } + + private async Task OnDeleteFrontApp() + { + DialogOption option = new DialogOption + { + Title = "添加前台应用", + BodyTemplate = BootstrapDynamicComponent.CreateComponent(new Dictionary + { + [nameof(FrontAppDialog.Value)] = AppInfo + }).Render(), + ShowFooter = false, + }; + await DialogService.Show(option); + } } diff --git a/src/blazor/admin/BootstrapAdmin.Web/Validators/AppIdValidator.cs b/src/blazor/admin/BootstrapAdmin.Web/Validators/AppIdValidator.cs new file mode 100644 index 00000000..05910c9d --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.Web/Validators/AppIdValidator.cs @@ -0,0 +1,46 @@ +using BootstrapAdmin.Web.Core; +using System.ComponentModel.DataAnnotations; + +namespace BootstrapAdmin.Web.Validators; + +/// +/// +/// +public class AppIdValidator : IValidator +{ + private IDict DictService { get; set; } + + /// + /// + /// + /// + public AppIdValidator(IDict dictService) => DictService = dictService; + + /// + /// + /// + public string? ErrorMessage { get; set; } + + /// + /// + /// + /// + /// + /// + public void Validate(object? propertyValue, ValidationContext context, List results) + { + var AppName = DictService.GetAppNameByAppName(propertyValue?.ToString()!); + if (!string.IsNullOrEmpty(AppName)) + { + ErrorMessage = $"{context.DisplayName}已存在"; + } + else + { + ErrorMessage = null; + } + if (!string.IsNullOrEmpty(ErrorMessage)) + { + results.Add(new ValidationResult(ErrorMessage, new string[] { context.MemberName! })); + } + } +}