refactor: 重构 bootstrap-toggle 默认值

#Comment
默认值为开启
This commit is contained in:
Argo-2016 2020-01-19 14:52:40 +08:00
parent ba8320708a
commit be80b0c629
19 changed files with 114 additions and 54 deletions

View File

@ -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
/// 获得 根模板页实例
/// </summary>
[CascadingParameter(Name = "Default")]
public DefaultLayout RootLayout { get; protected set; } = new DefaultLayout();
protected DefaultLayout? RootLayout { get; set; }
/// <summary>
/// 获得/设置 用户图标
@ -37,5 +38,18 @@ namespace Bootstrap.Admin.Components
/// </summary>
[Parameter]
public EventCallback<string> DisplayNameChanged { get; set; }
/// <summary>
/// 获得/设置 是否显示 Blazor MVC 切换图标
/// </summary>
protected bool EnableBlazor { get; set; }
/// <summary>
/// 参数赋值方法
/// </summary>
protected override void OnParametersSet()
{
EnableBlazor = DictHelper.RetrieveEnableBlazor();
}
}
}

View File

@ -23,7 +23,7 @@ namespace Bootstrap.Admin.Components
///
/// </summary>
[Parameter]
public string ShowCardTitle { get; set; } = "";
public bool ShowCardTitle { get; set; } = true;
/// <summary>
///

View File

@ -79,5 +79,21 @@ namespace Bootstrap.Admin.Extensions
/// <param name="id"></param>
/// <param name="method"></param>
public static void Tooltip(this IJSRuntime? jSRuntime, string id, string method) => jSRuntime.InvokeVoidAsync("$.tooltip", $"#{id}", method);
/// <summary>
/// 显示或者隐藏 网站 Blazor 挂件图标
/// </summary>
/// <param name="jSRuntime"></param>
/// <param name="show"></param>
public static void ToggleBlazor(this IJSRuntime? jSRuntime, bool show) => jSRuntime.InvokeVoidAsync("$.toggleBlazor", show);
/// <summary>
/// 显示或者隐藏 网站 Blazor 挂件图标
/// </summary>
/// <param name="jSRuntime"></param>
/// <param name="showSidebar"></param>
/// <param name="showCardTitle"></param>
/// <param name="fixedTableHeader"></param>
public static void SetWebSettings(this IJSRuntime? jSRuntime, bool showSidebar, bool showCardTitle, bool fixedTableHeader) => jSRuntime.InvokeVoidAsync("$.setWebSettings", showSidebar, showCardTitle, fixedTableHeader);
}
}

View File

@ -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();
}
/// <summary>
@ -54,12 +54,12 @@ namespace Bootstrap.Admin.Models
/// <summary>
/// 是否显示卡片标题
/// </summary>
public string ShowCardTitle { get; protected set; }
public bool ShowCardTitle { get; protected set; }
/// <summary>
/// 是否收缩侧边栏
/// </summary>
public string ShowSideBar { get; protected set; }
public bool ShowSideBar { get; protected set; }
/// <summary>
/// 获得 是否允许短信验证码登录
@ -74,12 +74,12 @@ namespace Bootstrap.Admin.Models
/// <summary>
/// 获得 是否允许短信验证码登录
/// </summary>
public string ShowMobile { get; }
public bool ShowMobile { get; }
/// <summary>
/// 获得 是否允许第三方 OAuth 认证登录
/// </summary>
public string ShowOAuth { get; }
public bool ShowOAuth { get; }
/// <summary>
/// 获得 自动锁屏时长 默认 1 分钟 字典表中配置
@ -94,6 +94,6 @@ namespace Bootstrap.Admin.Models
/// <summary>
/// 获得 是否固定表头
/// </summary>
public string FixedTableHeader { get; }
public bool FixedTableHeader { get; }
}
}

View File

@ -37,6 +37,7 @@ namespace Bootstrap.Admin.Models
WebSiteIcon = DictHelper.RetrieveWebIcon(AppId);
WebSiteLogo = DictHelper.RetrieveWebLogo(AppId);
}
EnableBlazor = DictHelper.RetrieveEnableBlazor();
}
/// <summary>
@ -68,5 +69,10 @@ namespace Bootstrap.Admin.Models
/// 获得 当前样式
/// </summary>
public string ActiveCss { get; } = "";
/// <summary>
/// 获得 是否开启 Blazor
/// </summary>
public bool EnableBlazor { get; }
}
}

View File

@ -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();
}
/// <summary>
@ -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();
}
/// <summary>
@ -41,16 +39,11 @@ namespace Bootstrap.Admin.Models
/// <summary>
/// 获得 是否开启自动锁屏
/// </summary>
public string AutoLockScreen { get; }
public bool AutoLockScreen { get; }
/// <summary>
/// 获得 是否开启自动锁屏
/// </summary>
public string DefaultApp { get; }
/// <summary>
/// 获得 是否开启 Blazor
/// </summary>
public string EnableBlazor { get; }
public bool DefaultApp { get; }
}
}

View File

@ -90,7 +90,7 @@
</div>
</div>
<div class="modal-footer text-right">
<button class="btn btn-secondary" type="button" @onclick="SaveSidebar"><i class="fa fa-save"></i><span>保存</span></button>
<button class="btn btn-secondary" type="button" @onclick="SaveWebSettings"><i class="fa fa-save"></i><span>保存</span></button>
</div>
</div>
</div>
@ -118,7 +118,7 @@
</div>
<ConditionComponent Inverse="true">
<div class="modal-footer text-right">
<button class="btn btn-secondary" type="button"><i class="fa fa-save"></i><span>保存</span></button>
<button class="btn btn-secondary" type="button" @onclick="SaveLogin"><i class="fa fa-save"></i><span>保存</span></button>
</div>
</ConditionComponent>
</div>
@ -172,7 +172,7 @@
<div class="card-header">网站设置</div>
<div class="card-body">
<div class="alert alert-info" role="alert">
<span>开启此功能后后台应用使用 Blazor 多标签形式</span>
<span>开启此功能网站增加 Blazor 与 MVC 切换挂件</span>
</div>
<div class="form-inline">
<div class="row">

View File

@ -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);
}
/// <summary>
/// 保存 网站调整 方法
/// </summary>
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);
}
/// <summary>
/// 保存 登陆设置
/// </summary>
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);
}
/// <summary>
/// 网站设置编辑模型实体类
/// </summary>

View File

@ -3,12 +3,12 @@
<header class="header">
<div class="bg"></div>
<div class="d-flex align-items-center">
<a id="navbar" href="@RootLayout.HomeUrl" class="sidebar-toggle-box">
<a id="navbar" href="@RootLayout?.HomeUrl" class="sidebar-toggle-box">
<i class="fa fa-bars"></i>
<span id="websiteTitle">@Title</span>
</a>
<div class="nav">
@if (@RootLayout.IsAdmin)
@if (@RootLayout?.IsAdmin ?? false)
{
<!-- tasks start -->
<div class="dropdown">
@ -91,7 +91,7 @@
</a>
</div>
}
<div class="dropdown">
<div class="@(EnableBlazor ? "dropdown" : "dropdown d-none")">
<a class="shadow-success dropdown-mvc" href="/Admin/Index" data-toggle="tooltip" title="NETCore MVC 模式">
<img src="/images/netcore2.png" />
</a>
@ -108,7 +108,7 @@
<img src="@Icon.ToBlazorLink()">
<div class="flex-fill">
<div class="username text-truncate">@DisplayName</div>
<div>登录名:@RootLayout.UserName</div>
<div>登录名:@RootLayout?.UserName</div>
</div>
</div>
</div>

View File

@ -1,6 +1,6 @@
@inherits SectionBase
<section class="main-content @ShowCardTitle @(ShowBackground ? @"welcome-bg" : @"")">
<section class="main-content @(ShowCardTitle ? "" : "no-card-header") @(ShowBackground ? "welcome-bg" : "")">
@if (LockScreenPeriod > 0)
{
<input id="lockScreenPeriod" type="hidden" value="@LockScreenPeriod" />

View File

@ -141,7 +141,7 @@
</div>
</div>
</div>
<div class="slidercaptcha card @Model.ShowOAuth">
<div class="slidercaptcha @(Model.ShowOAuth ? "card oauth" : "card")">
<div class="card-header">
<span>请完成安全验证</span>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

View File

@ -170,7 +170,7 @@
<div class="card-header">网站设置</div>
<div class="card-body">
<div class="alert alert-info" role="alert">
<span>开启此功能后后台应用使用 Blazor 多标签形式</span>
<span>开启此功能网站增加 Blazor 与 MVC 切换挂件</span>
</div>
<div class="form-inline">
<div class="row">

View File

@ -90,7 +90,7 @@
</a>
</div>
}
<div class="dropdown">
<div class="@(Model.EnableBlazor ? "dropdown" : "dropdown d-none")">
<a class="shadow-success dropdown-blazor" href="/Pages" data-toggle="tooltip" title="Blazor 多 Tabs 模式">
<img src="~/images/blazor.svg" />
</a>

View File

@ -1,5 +1,5 @@
@model NavigatorBarModel
<aside class="@Model.ShowSideBar">
<aside class="@(Model.ShowSideBar ? "" : "collapsed")">
<div class="bg"></div>
<div class="nav-brand justify-content-center">
<a href="#">

View File

@ -36,7 +36,7 @@
<script src="~/js/log.js" asp-append-version="true"></script>
}
@await Html.PartialAsync("Navigator")
<section id="main-content" class="main-content @Model.ShowCardTitle">
<section id="main-content" class="main-content @(Model.ShowCardTitle ? "" : "no-card-header")">
<input id="lockScreenPeriod" type="hidden" asp-condition="@Model.EnableAutoLockScreen" value="@Model.LockScreenPeriod" />
<div class="main-header">
<ol class="breadcrumb">

View File

@ -94,7 +94,7 @@
</div>
<div class="card-body">
@await RenderSectionAsync("cardbody", false)
<table data-fixedHeader="@Model.FixedTableHeader"></table>
<table data-Header="@(Model.FixedTableHeader ? "fixed" : "scroll")"></table>
</div>
</div>
<div id="tableButtons" class="d-none">

View File

@ -130,6 +130,20 @@
},
submitForm: function (btn) {
$(btn).parent().prev().find('form :submit').click();
},
toggleBlazor: function (show) {
var $blazor = $('header .nav .dropdown-mvc').parent();
if (show) $blazor.removeClass('d-none');
else $blazor.addClass('d-none');
},
setWebSettings: function (showSidebar, showCardTitle, fixedTableHeader) {
var $tabContent = $('section .tab-content');
if (showCardTitle) $tabContent.removeClass('no-card-header');
else $tabContent.addClass('no-card-header');
var $table = $(".bootstrap-table");
if (fixedTableHeader) $table.attr('data-header', 'fixed');
else $table.attr('data-header', 'scroll');
}
});

View File

@ -84,8 +84,10 @@ $(function () {
url: Settings.url, data: [{ name: 'Blazor', code: blazor, category: '网站设置' }], title: 'Blazor 设置', method: "post",
callback: function (result) {
if (result) {
// 导航到 Blazor 页面
window.location.href = $.formatUrl("Pages/Admin/Settings");
// 通过值设置是否显示 Blazor 挂件
var $blazor = $('header .nav .dropdown-blazor').parent();
if (blazor === "1") $blazor.removeClass('d-none');
else $blazor.addClass('d-none');
}
}
});

View File

@ -436,7 +436,7 @@
}
// 判断是否固定表头 小屏幕禁止固定表头功能
var fixHeader = this.attr('data-fixedHeader') === '' && $(window).width() >= 768;
var fixHeader = this.attr('data-header') === 'fixed' && $(window).width() >= 768;
var $tabContainer = $(settings.tableContainer);
if (fixHeader && settings.height === undefined) {
var calcPrevHeight = function (element) {
@ -754,7 +754,7 @@
var oldFunc = toggle.prototype.render;
toggle.prototype.render = function () {
var defaultVal = this.$element.attr('data-default-val') || '';
if (defaultVal === '') this.$element.prop('checked', true);
if (defaultVal === "True") this.$element.prop('checked', true);
oldFunc.call(this);
this.$toggle.on('touchend', function (e) {
$(this).trigger('click.bs.toggle');