refactor: 移除 BootstrapComponentBase 类
This commit is contained in:
parent
ecd008d846
commit
37f742cca2
|
@ -1,8 +1,5 @@
|
|||
using Bootstrap.Admin.Extensions;
|
||||
using Bootstrap.Admin.Shared;
|
||||
using Bootstrap.Admin.Shared;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bootstrap.Admin.Components
|
||||
{
|
||||
|
@ -21,29 +18,5 @@ namespace Bootstrap.Admin.Components
|
|||
/// </summary>
|
||||
[CascadingParameter(Name = "Default")]
|
||||
public DefaultLayout RootLayout { get; protected set; } = new DefaultLayout();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string UserName { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string DisplayName { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="firstRender"></param>
|
||||
/// <returns></returns>
|
||||
protected override void OnAfterRender(bool firstRender)
|
||||
{
|
||||
var requestUrl = RootLayout.NavigationManager?.Uri ?? "";
|
||||
var path = new Uri(requestUrl).PathAndQuery;
|
||||
var menus = DataAccess.MenuHelper.RetrieveAllMenus(RootLayout.UserName);
|
||||
var menu = menus.FirstOrDefault(menu => path.Contains(menu.Url.ToBlazorMenuUrl()));
|
||||
if (menu != null) TabSet?.AddTab(menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
using Bootstrap.Admin.Shared;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace Bootstrap.Admin.Components
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class BootstrapComponentBase : ComponentBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public NavigationManager? NavigationManager { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Inject]
|
||||
protected IJSRuntime? JSRuntime { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[CascadingParameter(Name = "Admin")]
|
||||
protected AdminLayout Layout { get; set; } = new AdminLayout();
|
||||
}
|
||||
}
|
|
@ -1,11 +1,12 @@
|
|||
using Microsoft.AspNetCore.Components;
|
||||
using Bootstrap.Admin.Shared;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace Bootstrap.Admin.Components
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class HeaderBase : BootstrapComponentBase
|
||||
public class HeaderBase : ComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
|
@ -43,6 +44,12 @@ namespace Bootstrap.Admin.Components
|
|||
[Parameter]
|
||||
public string Icon { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[CascadingParameter(Name = "Default")]
|
||||
public DefaultLayout RootLayout { get; protected set; } = new DefaultLayout();
|
||||
|
||||
/// <summary>
|
||||
/// 更新登录用户显示名称方法
|
||||
/// </summary>
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace Bootstrap.Admin.Components
|
|||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class NavItemBase : BootstrapComponentBase
|
||||
public class NavItemBase : ComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Bootstrap.Admin.Models;
|
||||
using Bootstrap.Admin.Shared;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace Bootstrap.Admin.Components
|
||||
|
@ -6,7 +7,7 @@ namespace Bootstrap.Admin.Components
|
|||
/// <summary>
|
||||
/// 侧边栏组件
|
||||
/// </summary>
|
||||
public class SideBarBase : BootstrapComponentBase
|
||||
public class SideBarBase : ComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 获得/设置 侧边栏绑定 Model 实例
|
||||
|
@ -19,5 +20,11 @@ namespace Bootstrap.Admin.Components
|
|||
/// </summary>
|
||||
[Parameter]
|
||||
public EventCallback<NavigatorBarModel> ModelChanged { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[CascadingParameter(Name = "Default")]
|
||||
public DefaultLayout RootLayout { get; protected set; } = new DefaultLayout();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Bootstrap.Admin.Extensions;
|
||||
using Bootstrap.Admin.Shared;
|
||||
using Bootstrap.Security;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -8,7 +9,7 @@ namespace Bootstrap.Admin.Components
|
|||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class TabBase : BootstrapComponentBase
|
||||
public class TabBase : ComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
|
@ -40,6 +41,18 @@ namespace Bootstrap.Admin.Components
|
|||
[Parameter]
|
||||
public bool Active { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[CascadingParameter(Name = "Admin")]
|
||||
public AdminLayout Layout { get; protected set; } = new AdminLayout();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public NavigationManager? NavigationManager { get; set; }
|
||||
|
||||
private bool closeTab;
|
||||
/// <summary>
|
||||
///
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
using Bootstrap.Admin.Extensions;
|
||||
using Bootstrap.Admin.Shared;
|
||||
using Bootstrap.Security;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.JSInterop;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -10,8 +13,26 @@ namespace Bootstrap.Admin.Components
|
|||
/// <summary>
|
||||
/// TabSet 组件类
|
||||
/// </summary>
|
||||
public class TabSetBase : BootstrapComponentBase
|
||||
public class TabSetBase : ComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public NavigationManager? NavigationManager { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Inject]
|
||||
protected IJSRuntime? JSRuntime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[CascadingParameter(Name = "Default")]
|
||||
public DefaultLayout RootLayout { get; protected set; } = new DefaultLayout();
|
||||
|
||||
/// <summary>
|
||||
/// 页面集合
|
||||
/// </summary>
|
||||
|
@ -23,6 +44,18 @@ namespace Bootstrap.Admin.Components
|
|||
protected List<Tab> Tabs { get; set; } = new List<Tab>();
|
||||
private string? curId;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
var requestUrl = NavigationManager?.Uri ?? "";
|
||||
var path = new Uri(requestUrl).PathAndQuery;
|
||||
var menus = DataAccess.MenuHelper.RetrieveAllMenus(RootLayout.UserName);
|
||||
var menu = menus.FirstOrDefault(menu => path.Contains(menu.Url.ToBlazorMenuUrl()));
|
||||
if (menu != null) AddTab(menu);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 页面呈现后回调方法
|
||||
/// </summary>
|
||||
|
@ -101,7 +134,7 @@ namespace Bootstrap.Admin.Components
|
|||
/// </summary>
|
||||
protected void CloseAllTab()
|
||||
{
|
||||
NavigationManager?.NavigateTo(Layout.RootLayout.HomeUrl);
|
||||
NavigationManager?.NavigateTo(RootLayout.HomeUrl);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
@inherits BootstrapComponentBase
|
||||
|
||||
<div class="card" asp-auth="saveDisplayName">
|
||||
<div class="card" asp-auth="saveDisplayName">
|
||||
<div class="card-header">基本资料</div>
|
||||
<div class="card-body" data-toggle="LgbValidate" data-valid-button="#btnSaveDisplayName">
|
||||
@if (IsDemo)
|
||||
|
@ -17,7 +15,7 @@
|
|||
</div>
|
||||
<div class="form-group col-sm-6 col-md-auto">
|
||||
<label class="control-label" for="DisplayName">显示名称</label>
|
||||
<input type="text" class="form-control" @bind="Layout.DisplayName" placeholder="不可为空,20字以内" maxlength="20" data-valid="true" />
|
||||
<input type="text" class="form-control" @bind="RootLayout.DisplayName" placeholder="不可为空,20字以内" maxlength="20" data-valid="true" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -113,21 +111,27 @@
|
|||
</div>
|
||||
|
||||
@code {
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[CascadingParameter(Name = "Default")]
|
||||
public DefaultLayout RootLayout { get; protected set; } = new DefaultLayout();
|
||||
|
||||
private ProfilesModel? Model;
|
||||
private bool IsDemo;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
Model = new ProfilesModel(Layout?.UserName);
|
||||
Model = new ProfilesModel(RootLayout.UserName);
|
||||
IsDemo = Model?.IsDemo ?? false;
|
||||
}
|
||||
|
||||
private void SaveDisplayName()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Model?.UserName) && Layout != null && !string.IsNullOrEmpty(Layout.DisplayName))
|
||||
if (!string.IsNullOrEmpty(Model?.UserName) && !string.IsNullOrEmpty(RootLayout.DisplayName))
|
||||
{
|
||||
Bootstrap.DataAccess.UserHelper.SaveDisplayName(Model.UserName, Layout.DisplayName);
|
||||
Bootstrap.DataAccess.UserHelper.SaveDisplayName(Model.UserName, RootLayout.DisplayName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<header class="header">
|
||||
<div class="bg"></div>
|
||||
<div class="d-flex align-items-center">
|
||||
<a id="navbar" href="@Layout.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>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<aside class="@Model.ShowSideBar">
|
||||
<div class="bg"></div>
|
||||
<div class="nav-brand justify-content-center">
|
||||
<a href="@Layout.RootLayout.HomeUrl">
|
||||
<a href="@RootLayout.HomeUrl">
|
||||
<img src="@Model.WebSiteLogo.ToBlazorLink()" />
|
||||
<span>@Model.Title</span>
|
||||
</a>
|
||||
|
|
Loading…
Reference in New Issue