Browse Source

头部组件功能实现

blazor2
shuangbaojun 4 years ago
parent
commit
a0779cff1d
  1. 2
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj
  2. 2
      aspnet-core/services/host/Lion.AbpPro.Web.Blazor.WebAssembly/Shared/MainLayout.razor
  3. 43
      aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/AbpProBlazorLayoutAntDesignThemeModule.cs
  4. 45
      aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/Components/GlobalHeader/RightContent.razor
  5. 140
      aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/Components/GlobalHeader/RightContent.razor.cs
  6. 46
      aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/Lion.AbpPro.Blazor.Layout.AntDesignTheme.csproj
  7. 3
      aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/_Imports.razor

2
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj

@ -52,4 +52,6 @@
<None Remove="Logs\**" />
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties appsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>
</Project>

2
aspnet-core/services/host/Lion.AbpPro.Web.Blazor.WebAssembly/Shared/MainLayout.razor

@ -6,7 +6,7 @@
Logo="@("https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg")"
MenuData="_menuData">
<RightContentRender>
<demo.Components.RightContent />
<Lion.AbpPro.Blazor.Layout.AntDesignTheme.Components.GlobalHeader.RightContent></Lion.AbpPro.Blazor.Layout.AntDesignTheme.Components.GlobalHeader.RightContent>
</RightContentRender>
<ChildContent>
@Body

43
aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/AbpProBlazorLayoutAntDesignThemeModule.cs

@ -1,20 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.Components.Web.Theming.Routing;
using Volo.Abp.Modularity;
namespace Lion.AbpPro.Blazor.Layout.AntDesignTheme
{
public class AbpProBlazorLayoutAntDesignThemeModule: AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAntDesign();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.Components.Web.Theming.Routing;
using Volo.Abp.Autofac.WebAssembly;
using Volo.Abp.Modularity;
namespace Lion.AbpPro.Blazor.Layout.AntDesignTheme
{
[DependsOn(
typeof(AbpAutofacWebAssemblyModule)
)]
public class AbpProBlazorLayoutAntDesignThemeModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAntDesign();
}
}
}

45
aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/Components/GlobalHeader/RightContent.razor

@ -0,0 +1,45 @@
@namespace Lion.AbpPro.Blazor.Layout.AntDesignTheme.Components.GlobalHeader
@inherits AntDomComponentBase
<Space Class="@ClassMapper.Class" Size="@("24")">
<!--通知-->
<SpaceItem>
<NoticeIcon ClearText="Empty"
ViewMoreText="see more"
Count="0"
OnClear="HandleClear"
OnViewMore="HandleViewMore">
<NoticeList TabKey="message"
Title="消息"
EmptyText="你已阅读所有站内消息"
ShowViewMore=true
Data="null" />
<NoticeList TabKey="notification"
Title="通知"
EmptyText="你已阅读所有通知消息"
ShowViewMore=true
Data="null" />
</NoticeIcon>
</SpaceItem>
<!--语言-->
<SpaceItem>
<SelectLang OnItemSelected="HandleSelectLang" LanguageIcons="_languageIcons" LanguageLabels="_languageLabels" Locales="_locales" />
</SpaceItem>
<!--账户信息-->
<SpaceItem>
<AvatarDropdown Name="admin"
Avatar="https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png"
MenuItems="AvatarMenuItems"
OnItemSelected="HandleSelectUser" />
</SpaceItem>
<!--最大化-->
<SpaceItem>
<AntDesign.Tooltip Placement="@Placement.Bottom" Title="FullScreenTipMsg">
<Button Icon="fullscreen" Type="@ButtonType.Text"></Button>
</AntDesign.Tooltip>
</SpaceItem>
</Space>

140
aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/Components/GlobalHeader/RightContent.razor.cs

@ -0,0 +1,140 @@
using AntDesign;
using AntDesign.ProLayout;
using Blazored.LocalStorage;
using Lion.AbpPro.Users;
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace Lion.AbpPro.Blazor.Layout.AntDesignTheme.Components.GlobalHeader
{
public partial class RightContent : ITransientDependency
{
private readonly HttpClient _httpClient;
private readonly ILocalStorageService _localStorage;
private readonly MessageService _messageService;
private readonly NavigationManager _navigationManager;
private IDictionary<string, string> _languageLabels = new Dictionary<string, string>();
private string[] _locales;
private IDictionary<string, string> _languageIcons = new Dictionary<string, string>();
public RightContent(
HttpClient httpClient,
ILocalStorageService localStorage,
MessageService messageService,
NavigationManager navigationManager
)
{
_httpClient = httpClient;
_localStorage = localStorage;
_messageService = messageService;
_navigationManager = navigationManager;
}
public string FullScreenTipMsg { get; set; } = "全屏";
public AvatarMenuItem[] AvatarMenuItems { get; } = new AvatarMenuItem[]
{
new() { Key = "setting", IconType = "setting", Option = "个人设置"},
new() { Key = "center", IconType = "user", Option = "锁定屏幕"},
new() { IsDivider = true },
new() { Key = "logout", IconType = "logout", Option = "注销"}
};
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
ClearClassMap();
_languageLabels.Add("zh-Hans", "简体中文");
_languageLabels.Add("en", "English");
_languageIcons.Add("zh-Hans", "\ud83c\udde8\ud83c\uddf3");
_languageIcons.Add("en", "\ud83c\uddfa\ud83c\uddf8");
_locales = new string[] { "zh-Hans", "en" };
}
private void ClearClassMap()
{
ClassMapper.Clear().Add("right");
}
public async Task HandleClear(string key)
{
switch (key)
{
case "notification":
// TODO
break;
case "message":
// TODO
break;
}
await _messageService.Success($"清空了{key}");
}
public async Task HandleViewMore(string key)
{
await _messageService.Info("查看更多...");
}
public async Task HandleSelectUser(MenuItem item)
{
switch (item.Key)
{
case "center":
_navigationManager.NavigateTo("/account/center");
break;
case "setting":
_navigationManager.NavigateTo("/account/settings");
break;
case "logout":
// 先调用服务端登出接口 TODO
// 再清楚本地应用token缓存
await _localStorage.RemoveItemAsync("access_token");
_httpClient.DefaultRequestHeaders.Authorization = null;
_navigationManager.NavigateTo("/user/login", true);
break;
default:
break;
}
await Task.CompletedTask;
}
/// <summary>
/// 多语言
/// </summary>
/// <param name="item"></param>
public async Task HandleSelectLang(MenuItem item)
{
var langText = item.Key switch
{
"zh-Hans" => "简体中文",
_ => "English",
};
string lang = item.Key;
await _localStorage.SetItemAsStringAsync("lang", lang);
//await _accountAppService.ChangeLanguageAsync(lang); //TODO
CultureInfo culture = new(lang);
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
await _messageService.Success($"切换【{langText}】成功!");
var currentUrl = _navigationManager.Uri;
_navigationManager.NavigateTo(currentUrl, true);
}
}
}

46
aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/Lion.AbpPro.Blazor.Layout.AntDesignTheme.csproj

@ -1,20 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<Import Project="..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<SupportedPlatform Include="browser" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AntDesign" Version="0.10.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="$(MicrosoftVersion)" />
<PackageReference Include="Volo.Abp.AspNetCore.Components.Web.Theming" Version="$(AbpPackageVersion)" />
<PackageReference Include="Volo.Abp.Core" Version="$(AbpPackageVersion)" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk.Razor">
<Import Project="..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<SupportedPlatform Include="browser" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AntDesign" Version="0.10.2" />
<PackageReference Include="AntDesign.ProLayout" Version="0.1.9" />
<PackageReference Include="Blazored.LocalStorage" Version="4.1.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="$(MicrosoftVersion)" />
<PackageReference Include="Volo.Abp.Autofac.WebAssembly" Version="$(AbpPackageVersion)" />
<PackageReference Include="Volo.Abp.AspNetCore.Components.Web.Theming" Version="$(AbpPackageVersion)" />
<PackageReference Include="Volo.Abp.Core" Version="$(AbpPackageVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Lion.AbpPro.HttpApi.Client\Lion.AbpPro.HttpApi.Client.csproj" />
</ItemGroup>
</Project>

3
aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/_Imports.razor

@ -1,4 +1,5 @@
@using Microsoft.AspNetCore.Components.Web
@using System.Net.Http
@using System.Net.Http.Json
@using AntDesign
@using AntDesign
@using AntDesign.ProLayout
Loading…
Cancel
Save