From a0779cff1d10a627591ac4cbdb262234dbbb7d82 Mon Sep 17 00:00:00 2001
From: shuangbaojun <190663855@qq.com>
Date: Sun, 12 Dec 2021 16:56:18 +0800
Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=A4=B4=E9=83=A8=E7=BB=84?=
=?UTF-8?q?=E4=BB=B6=E5=8A=9F=E8=83=BD=E5=AE=9E=E7=8E=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Lion.AbpPro.HttpApi.Host.csproj | 2 +
.../Shared/MainLayout.razor | 2 +-
.../AbpProBlazorLayoutAntDesignThemeModule.cs | 43 +++---
.../GlobalHeader/RightContent.razor | 45 ++++++
.../GlobalHeader/RightContent.razor.cs | 140 ++++++++++++++++++
...AbpPro.Blazor.Layout.AntDesignTheme.csproj | 46 +++---
.../_Imports.razor | 3 +-
7 files changed, 239 insertions(+), 42 deletions(-)
create mode 100644 aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/Components/GlobalHeader/RightContent.razor
create mode 100644 aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/Components/GlobalHeader/RightContent.razor.cs
diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj
index 97588f47..42785380 100644
--- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj
+++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj
@@ -52,4 +52,6 @@
+
+
diff --git a/aspnet-core/services/host/Lion.AbpPro.Web.Blazor.WebAssembly/Shared/MainLayout.razor b/aspnet-core/services/host/Lion.AbpPro.Web.Blazor.WebAssembly/Shared/MainLayout.razor
index 3784c2ea..f4f7b0bd 100644
--- a/aspnet-core/services/host/Lion.AbpPro.Web.Blazor.WebAssembly/Shared/MainLayout.razor
+++ b/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">
-
+
@Body
diff --git a/aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/AbpProBlazorLayoutAntDesignThemeModule.cs b/aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/AbpProBlazorLayoutAntDesignThemeModule.cs
index bcb2d05f..fcfb579e 100644
--- a/aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/AbpProBlazorLayoutAntDesignThemeModule.cs
+++ b/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();
+ }
+ }
+}
diff --git a/aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/Components/GlobalHeader/RightContent.razor b/aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/Components/GlobalHeader/RightContent.razor
new file mode 100644
index 00000000..503de88f
--- /dev/null
+++ b/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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/Components/GlobalHeader/RightContent.razor.cs b/aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/Components/GlobalHeader/RightContent.razor.cs
new file mode 100644
index 00000000..1d65edb5
--- /dev/null
+++ b/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 _languageLabels = new Dictionary();
+ private string[] _locales;
+ private IDictionary _languageIcons = new Dictionary();
+ 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;
+ }
+
+ ///
+ /// 多语言
+ ///
+ ///
+ 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);
+ }
+ }
+}
diff --git a/aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/Lion.AbpPro.Blazor.Layout.AntDesignTheme.csproj b/aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/Lion.AbpPro.Blazor.Layout.AntDesignTheme.csproj
index 51bd19f2..7287664b 100644
--- a/aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/Lion.AbpPro.Blazor.Layout.AntDesignTheme.csproj
+++ b/aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/Lion.AbpPro.Blazor.Layout.AntDesignTheme.csproj
@@ -1,20 +1,26 @@
-
-
-
- net6.0
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+ net6.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/_Imports.razor b/aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/_Imports.razor
index 55a5b561..0ae0977a 100644
--- a/aspnet-core/services/src/Lion.AbpPro.Blazor.Layout.AntDesignTheme/_Imports.razor
+++ b/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
\ No newline at end of file
+@using AntDesign
+@using AntDesign.ProLayout
\ No newline at end of file