feat: Blazor 增加网站标题更新功能
This commit is contained in:
parent
bcd344c433
commit
488ac6be60
|
@ -57,6 +57,11 @@ namespace Bootstrap.Admin.Pages.Components
|
|||
/// </summary>
|
||||
public string DisplayName { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string WebTitle { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
@ -122,6 +127,7 @@ namespace Bootstrap.Admin.Pages.Components
|
|||
RequestUrl = new UriBuilder(NavigationManager.Uri).Path;
|
||||
Model = new NavigatorBarModel(UserName, RequestUrl.ToMvcMenuUrl());
|
||||
DisplayName = Model.DisplayName;
|
||||
WebTitle = Model.Title;
|
||||
if (HomeUrl.StartsWith("/")) HomeUrl = NavigationManager.ToBlazorLink(HomeUrl);
|
||||
}
|
||||
}
|
||||
|
@ -136,6 +142,16 @@ namespace Bootstrap.Admin.Pages.Components
|
|||
SideBar?.DisplayNameChanged.InvokeAsync(DisplayName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 网站标题变化时触发此方法
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
public void OnWebTitleChanged(string title)
|
||||
{
|
||||
Header?.WebTitleChanged.InvokeAsync(title);
|
||||
SideBar?.WebTitleChanged.InvokeAsync(title);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnAfterRender 方法
|
||||
/// </summary>
|
||||
|
|
|
@ -14,7 +14,13 @@ namespace Bootstrap.Admin.Pages.Components
|
|||
/// 获得 网站标题
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string Title { get; set; } = "";
|
||||
public string WebTitle { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 网站标题改变事件回调方法
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public EventCallback<string> WebTitleChanged { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得 根模板页实例
|
||||
|
|
|
@ -38,5 +38,17 @@ namespace Bootstrap.Admin.Pages.Components
|
|||
/// </summary>
|
||||
[Parameter]
|
||||
public EventCallback<string> DisplayNameChanged { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 网站标题
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string WebTitle { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 网站标题改变事件回调方法
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public EventCallback<string> WebTitleChanged { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
@inherits DefaultLayoutComponentBase
|
||||
|
||||
<CascadingValue Value=this Name="Default">
|
||||
<Header @ref="Header" Icon="@Model.Icon" Title="@Model.Title" @bind-DisplayName="DisplayName" />
|
||||
<SideBar @ref="SideBar" Model=@Model @bind-DisplayName="DisplayName" />
|
||||
<Header @ref="Header" Icon="@Model.Icon" @bind-DisplayName="DisplayName" @bind-WebTitle="WebTitle"/>
|
||||
<SideBar @ref="SideBar" Model=@Model @bind-DisplayName="DisplayName" @bind-WebTitle="WebTitle" />
|
||||
@Body
|
||||
<Footer Text="@Model.Footer" IsDemo=@Model.IsDemo></Footer>
|
||||
</CascadingValue>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<div class="d-flex align-items-center">
|
||||
<a id="navbar" href="@RootLayout?.HomeUrl" class="sidebar-toggle-box">
|
||||
<i class="fa fa-bars"></i>
|
||||
<span id="websiteTitle">@Title</span>
|
||||
<span id="websiteTitle">@WebTitle</span>
|
||||
</a>
|
||||
<div class="nav">
|
||||
@if (@RootLayout?.IsAdmin ?? false)
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<div class="nav-brand justify-content-center">
|
||||
<a href="@RootLayout?.HomeUrl">
|
||||
<img src="@Model.WebSiteLogo.ToBlazorLink()" />
|
||||
<span>@Model.Title</span>
|
||||
<span>@WebTitle</span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="nav-header flex-fill align-items-center">
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
</ConditionComponent>
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" id="sysName" placeholder="请输入网站标题,50字以内" value="@Model.Title" />
|
||||
<input type="text" class="form-control" placeholder="请输入网站标题,50字以内" @bind-value="@Model.Title" />
|
||||
<ConditionComponent Inverse="true">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-secondary" type="button">保存</button>
|
||||
<button class="btn btn-secondary" type="button" @onclick="SaveWebTitle">保存</button>
|
||||
</div>
|
||||
</ConditionComponent>
|
||||
</div>
|
||||
|
|
|
@ -160,6 +160,16 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components
|
|||
ShowMessage("保存 IP 地理位置", ret);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存网站标题
|
||||
/// </summary>
|
||||
protected void SaveWebTitle()
|
||||
{
|
||||
var ret = DictHelper.SaveWebTitle(Model.Title);
|
||||
RootLayout?.OnWebTitleChanged(Model.Title);
|
||||
ShowMessage("保存网站标题", ret);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 网站设置编辑模型实体类
|
||||
/// </summary>
|
||||
|
|
|
@ -115,6 +115,20 @@ namespace Bootstrap.DataAccess
|
|||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存网站标题
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
public static bool SaveWebTitle(string code)
|
||||
{
|
||||
var ret = DictHelper.SaveSettings(new BootstrapDict[]
|
||||
{
|
||||
new BootstrapDict() { Category = "网站设置", Name = "网站标题", Code = code }
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取字典分类名称
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in New Issue