From be80b0c6296697ccf44c35a6cb893315a0139046 Mon Sep 17 00:00:00 2001 From: Argo-2016 Date: Sun, 19 Jan 2020 14:52:40 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=20bootstrap-togg?= =?UTF-8?q?le=20=E9=BB=98=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #Comment 默认值为开启 --- .../Bootstrap.Admin/Components/HeaderBase.cs | 16 ++++++++- .../Bootstrap.Admin/Components/SectionBase.cs | 2 +- .../Extensions/JSRuntimeExtensions.cs | 16 +++++++++ .../Bootstrap.Admin/Models/AdminModel.cs | 20 +++++------ .../Bootstrap.Admin/Models/HeaderBarModel.cs | 6 ++++ .../Bootstrap.Admin/Models/SettingsModel.cs | 19 ++++------ .../Pages/Admin/Settings.razor | 6 ++-- .../Pages/Components/SettingsBase.cs | 35 +++++++++++++------ src/admin/Bootstrap.Admin/Shared/Header.razor | 10 +++--- .../Bootstrap.Admin/Shared/Section.razor | 2 +- .../Views/Account/Login.cshtml | 2 +- .../Views/Admin/Settings.cshtml | 2 +- .../Views/Shared/Header.cshtml | 2 +- .../Views/Shared/Navigator.cshtml | 2 +- .../Views/Shared/_Admin.cshtml | 2 +- .../Views/Shared/_Default.cshtml | 2 +- .../Bootstrap.Admin/wwwroot/js/ba.blazor.js | 14 ++++++++ .../Bootstrap.Admin/wwwroot/js/settings.js | 6 ++-- .../wwwroot/lib/longbow/longbow.common.js | 4 +-- 19 files changed, 114 insertions(+), 54 deletions(-) diff --git a/src/admin/Bootstrap.Admin/Components/HeaderBase.cs b/src/admin/Bootstrap.Admin/Components/HeaderBase.cs index 4b5e95de..93323879 100644 --- a/src/admin/Bootstrap.Admin/Components/HeaderBase.cs +++ b/src/admin/Bootstrap.Admin/Components/HeaderBase.cs @@ -1,4 +1,5 @@ using Bootstrap.Admin.Shared; +using Bootstrap.DataAccess; using Microsoft.AspNetCore.Components; namespace Bootstrap.Admin.Components @@ -18,7 +19,7 @@ namespace Bootstrap.Admin.Components /// 获得 根模板页实例 /// [CascadingParameter(Name = "Default")] - public DefaultLayout RootLayout { get; protected set; } = new DefaultLayout(); + protected DefaultLayout? RootLayout { get; set; } /// /// 获得/设置 用户图标 @@ -37,5 +38,18 @@ namespace Bootstrap.Admin.Components /// [Parameter] public EventCallback DisplayNameChanged { get; set; } + + /// + /// 获得/设置 是否显示 Blazor MVC 切换图标 + /// + protected bool EnableBlazor { get; set; } + + /// + /// 参数赋值方法 + /// + protected override void OnParametersSet() + { + EnableBlazor = DictHelper.RetrieveEnableBlazor(); + } } } diff --git a/src/admin/Bootstrap.Admin/Components/SectionBase.cs b/src/admin/Bootstrap.Admin/Components/SectionBase.cs index 33fe5847..e97a8644 100644 --- a/src/admin/Bootstrap.Admin/Components/SectionBase.cs +++ b/src/admin/Bootstrap.Admin/Components/SectionBase.cs @@ -23,7 +23,7 @@ namespace Bootstrap.Admin.Components /// /// [Parameter] - public string ShowCardTitle { get; set; } = ""; + public bool ShowCardTitle { get; set; } = true; /// /// diff --git a/src/admin/Bootstrap.Admin/Extensions/JSRuntimeExtensions.cs b/src/admin/Bootstrap.Admin/Extensions/JSRuntimeExtensions.cs index 9f564768..8aab8595 100644 --- a/src/admin/Bootstrap.Admin/Extensions/JSRuntimeExtensions.cs +++ b/src/admin/Bootstrap.Admin/Extensions/JSRuntimeExtensions.cs @@ -79,5 +79,21 @@ namespace Bootstrap.Admin.Extensions /// /// public static void Tooltip(this IJSRuntime? jSRuntime, string id, string method) => jSRuntime.InvokeVoidAsync("$.tooltip", $"#{id}", method); + + /// + /// 显示或者隐藏 网站 Blazor 挂件图标 + /// + /// + /// + public static void ToggleBlazor(this IJSRuntime? jSRuntime, bool show) => jSRuntime.InvokeVoidAsync("$.toggleBlazor", show); + + /// + /// 显示或者隐藏 网站 Blazor 挂件图标 + /// + /// + /// + /// + /// + public static void SetWebSettings(this IJSRuntime? jSRuntime, bool showSidebar, bool showCardTitle, bool fixedTableHeader) => jSRuntime.InvokeVoidAsync("$.setWebSettings", showSidebar, showCardTitle, fixedTableHeader); } } diff --git a/src/admin/Bootstrap.Admin/Models/AdminModel.cs b/src/admin/Bootstrap.Admin/Models/AdminModel.cs index b212290d..3ceaed8f 100644 --- a/src/admin/Bootstrap.Admin/Models/AdminModel.cs +++ b/src/admin/Bootstrap.Admin/Models/AdminModel.cs @@ -20,15 +20,15 @@ namespace Bootstrap.Admin.Models Footer = DictHelper.RetrieveWebFooter(appId); Theme = DictHelper.RetrieveActiveTheme(); IsDemo = DictHelper.RetrieveSystemModel(); - ShowCardTitle = DictHelper.RetrieveCardTitleStatus() ? "" : "no-card-header"; - ShowSideBar = DictHelper.RetrieveSidebarStatus() ? "" : "collapsed"; + ShowCardTitle = DictHelper.RetrieveCardTitleStatus(); + ShowSideBar = DictHelper.RetrieveSidebarStatus(); AllowMobile = DictHelper.RetrieveMobileLogin(); AllowOAuth = DictHelper.RetrieveOAuthLogin(); - ShowMobile = AllowMobile ? "" : "mobile"; - ShowOAuth = AllowOAuth ? "" : "oauth"; + ShowMobile = AllowMobile; + ShowOAuth = AllowOAuth; LockScreenPeriod = DictHelper.RetrieveAutoLockScreenPeriod(); EnableAutoLockScreen = DictHelper.RetrieveAutoLockScreen(); - FixedTableHeader = DictHelper.RetrieveFixedTableHeader() ? "" : "scroll"; + FixedTableHeader = DictHelper.RetrieveFixedTableHeader(); } /// @@ -54,12 +54,12 @@ namespace Bootstrap.Admin.Models /// /// 是否显示卡片标题 /// - public string ShowCardTitle { get; protected set; } + public bool ShowCardTitle { get; protected set; } /// /// 是否收缩侧边栏 /// - public string ShowSideBar { get; protected set; } + public bool ShowSideBar { get; protected set; } /// /// 获得 是否允许短信验证码登录 @@ -74,12 +74,12 @@ namespace Bootstrap.Admin.Models /// /// 获得 是否允许短信验证码登录 /// - public string ShowMobile { get; } + public bool ShowMobile { get; } /// /// 获得 是否允许第三方 OAuth 认证登录 /// - public string ShowOAuth { get; } + public bool ShowOAuth { get; } /// /// 获得 自动锁屏时长 默认 1 分钟 字典表中配置 @@ -94,6 +94,6 @@ namespace Bootstrap.Admin.Models /// /// 获得 是否固定表头 /// - public string FixedTableHeader { get; } + public bool FixedTableHeader { get; } } } diff --git a/src/admin/Bootstrap.Admin/Models/HeaderBarModel.cs b/src/admin/Bootstrap.Admin/Models/HeaderBarModel.cs index be38f069..a04cd228 100644 --- a/src/admin/Bootstrap.Admin/Models/HeaderBarModel.cs +++ b/src/admin/Bootstrap.Admin/Models/HeaderBarModel.cs @@ -37,6 +37,7 @@ namespace Bootstrap.Admin.Models WebSiteIcon = DictHelper.RetrieveWebIcon(AppId); WebSiteLogo = DictHelper.RetrieveWebLogo(AppId); } + EnableBlazor = DictHelper.RetrieveEnableBlazor(); } /// @@ -68,5 +69,10 @@ namespace Bootstrap.Admin.Models /// 获得 当前样式 /// public string ActiveCss { get; } = ""; + + /// + /// 获得 是否开启 Blazor + /// + public bool EnableBlazor { get; } } } diff --git a/src/admin/Bootstrap.Admin/Models/SettingsModel.cs b/src/admin/Bootstrap.Admin/Models/SettingsModel.cs index 8a8fb903..bd55a087 100644 --- a/src/admin/Bootstrap.Admin/Models/SettingsModel.cs +++ b/src/admin/Bootstrap.Admin/Models/SettingsModel.cs @@ -17,9 +17,8 @@ namespace Bootstrap.Admin.Models public SettingsModel(ControllerBase controller) : base(controller) { Themes = DictHelper.RetrieveThemes(); - AutoLockScreen = EnableAutoLockScreen ? "" : "lockScreen"; - DefaultApp = DictHelper.RetrieveDefaultApp() ? "" : "defaultApp"; - EnableBlazor = DictHelper.RetrieveEnableBlazor() ? "" : "blazor"; + AutoLockScreen = EnableAutoLockScreen; + DefaultApp = DictHelper.RetrieveDefaultApp(); } /// @@ -28,9 +27,8 @@ namespace Bootstrap.Admin.Models public SettingsModel(string? userName) : base(userName) { Themes = DictHelper.RetrieveThemes(); - AutoLockScreen = EnableAutoLockScreen ? "" : "lockScreen"; - DefaultApp = DictHelper.RetrieveDefaultApp() ? "" : "defaultApp"; - EnableBlazor = DictHelper.RetrieveEnableBlazor() ? "" : "blazor"; + AutoLockScreen = EnableAutoLockScreen; + DefaultApp = DictHelper.RetrieveDefaultApp(); } /// @@ -41,16 +39,11 @@ namespace Bootstrap.Admin.Models /// /// 获得 是否开启自动锁屏 /// - public string AutoLockScreen { get; } + public bool AutoLockScreen { get; } /// /// 获得 是否开启自动锁屏 /// - public string DefaultApp { get; } - - /// - /// 获得 是否开启 Blazor - /// - public string EnableBlazor { get; } + public bool DefaultApp { get; } } } diff --git a/src/admin/Bootstrap.Admin/Pages/Admin/Settings.razor b/src/admin/Bootstrap.Admin/Pages/Admin/Settings.razor index 51ff0bc3..78a32a5a 100644 --- a/src/admin/Bootstrap.Admin/Pages/Admin/Settings.razor +++ b/src/admin/Bootstrap.Admin/Pages/Admin/Settings.razor @@ -90,7 +90,7 @@ @@ -118,7 +118,7 @@ @@ -172,7 +172,7 @@
网站设置
diff --git a/src/admin/Bootstrap.Admin/Pages/Components/SettingsBase.cs b/src/admin/Bootstrap.Admin/Pages/Components/SettingsBase.cs index a88b16ba..81c8ada0 100644 --- a/src/admin/Bootstrap.Admin/Pages/Components/SettingsBase.cs +++ b/src/admin/Bootstrap.Admin/Pages/Components/SettingsBase.cs @@ -1,4 +1,5 @@ using Bootstrap.Admin.Components; +using Bootstrap.Admin.Extensions; using Bootstrap.Admin.Shared; using Bootstrap.DataAccess; using Bootstrap.Security; @@ -62,25 +63,39 @@ namespace Bootstrap.Pages.Admin.Components { var ret = DictHelper.SaveSettings(new BootstrapDict[] { new BootstrapDict() { Category = "网站设置", Name = "Blazor", Code = Model.EnableBlazor ? "1" : "0" } }); if (Model.EnableBlazor) ShowMessage("Blazor 设置保存", ret); - else - { - var url = RootLayout?.NavigationManager?.Uri.Replace("/Pages", ""); - RootLayout?.NavigationManager?.NavigateTo(url, true); - } + + // 根据保存结果隐藏 Header 挂件 + if (ret) RootLayout?.JSRuntime?.ToggleBlazor(Model.EnableBlazor); } /// /// 保存 网站调整 方法 /// - protected void SaveSidebar() + protected void SaveWebSettings() { var ret = DictHelper.SaveSettings(new BootstrapDict[]{ - new BootstrapDict() { Category = "网站调整", Name = "侧边栏状态", Code = Model.ShowSideBar ? "1" : "0" }, - new BootstrapDict() { Category = "网站调整", Name = "卡片标题状态", Code = Model.ShowCardTitle ? "1" : "0" }, - new BootstrapDict() { Category = "网站调整", Name = "固定表头", Code = Model.FixedTableHeader ? "1" : "0" } + new BootstrapDict() { Category = "网站设置", Name = "侧边栏状态", Code = Model.ShowSideBar ? "1" : "0" }, + new BootstrapDict() { Category = "网站设置", Name = "卡片标题状态", Code = Model.ShowCardTitle ? "1" : "0" }, + new BootstrapDict() { Category = "网站设置", Name = "固定表头", Code = Model.FixedTableHeader ? "1" : "0" } }); - ShowMessage("网站调整 设置保存", ret); + ShowMessage("网站调整保存", ret); + + // 根据保存结果设置网站样式 + if (ret) RootLayout?.JSRuntime?.SetWebSettings(Model.ShowSideBar, Model.ShowCardTitle, Model.FixedTableHeader); } + + /// + /// 保存 登陆设置 + /// + protected void SaveLogin() + { + var ret = DictHelper.SaveSettings(new BootstrapDict[]{ + new BootstrapDict() { Category = "网站设置", Name = "OAuth 认证登录", Code = Model.ShowOAuth ? "1" : "0" }, + new BootstrapDict() { Category = "网站设置", Name = "短信验证码登录", Code = Model.ShowMobile ? "1" : "0" } + }); + ShowMessage("登录设置保存", ret); + } + /// /// 网站设置编辑模型实体类 /// diff --git a/src/admin/Bootstrap.Admin/Shared/Header.razor b/src/admin/Bootstrap.Admin/Shared/Header.razor index 90d98161..262dc297 100644 --- a/src/admin/Bootstrap.Admin/Shared/Header.razor +++ b/src/admin/Bootstrap.Admin/Shared/Header.razor @@ -3,12 +3,12 @@
- + @Title diff --git a/src/admin/Bootstrap.Admin/Shared/Section.razor b/src/admin/Bootstrap.Admin/Shared/Section.razor index a4f52252..d33fed0f 100644 --- a/src/admin/Bootstrap.Admin/Shared/Section.razor +++ b/src/admin/Bootstrap.Admin/Shared/Section.razor @@ -1,6 +1,6 @@ @inherits SectionBase -
+
@if (LockScreenPeriod > 0) { diff --git a/src/admin/Bootstrap.Admin/Views/Account/Login.cshtml b/src/admin/Bootstrap.Admin/Views/Account/Login.cshtml index f7c67644..f1335e31 100644 --- a/src/admin/Bootstrap.Admin/Views/Account/Login.cshtml +++ b/src/admin/Bootstrap.Admin/Views/Account/Login.cshtml @@ -141,7 +141,7 @@
-
+
请完成安全验证 diff --git a/src/admin/Bootstrap.Admin/Views/Admin/Settings.cshtml b/src/admin/Bootstrap.Admin/Views/Admin/Settings.cshtml index 2c149d2f..ee330a8a 100644 --- a/src/admin/Bootstrap.Admin/Views/Admin/Settings.cshtml +++ b/src/admin/Bootstrap.Admin/Views/Admin/Settings.cshtml @@ -170,7 +170,7 @@
网站设置
diff --git a/src/admin/Bootstrap.Admin/Views/Shared/Header.cshtml b/src/admin/Bootstrap.Admin/Views/Shared/Header.cshtml index 8b19c96d..f26a1aba 100644 --- a/src/admin/Bootstrap.Admin/Views/Shared/Header.cshtml +++ b/src/admin/Bootstrap.Admin/Views/Shared/Header.cshtml @@ -90,7 +90,7 @@
} -