| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- using EasyTemplate.Tool;
- using EasyTemplate.Tool.Util;
- using Mapster;
- using Microsoft.JSInterop;
- namespace EasyTemplate.Blazor.Web.Components;
- public partial class RightContent
- {
- protected override async Task OnInitializedAsync()
- {
- NavigationManager.RedirectLogin();
- await base.OnInitializedAsync();
- SetClassMap();
- CurrentUser = Global.CurrentUser;
- // 配置 Mapster 映射规则
- TypeAdapterConfig<SystemNotification, NoticeIconData>.NewConfig()
- .Map(dest => dest.Key, src => src.Id)
- .Map(dest => dest.Title, src => src.Title)
- .Map(dest => dest.Description, src => src.Info)
- .Map(dest => dest.Read, src => src.Seen)
- .Map(dest => dest.Datetime, src => src.CreateTime);
- await Notifications();
- }
- private async Task Notifications()
- {
- var notices = await Notices.AsQueryable().ToArrayAsync();
- IconNotifications = notices.Where(x => x.NotifyType == PublicEnum.NotifyType.Notify).Adapt<NoticeIconData[]>();
- Messages = notices.Where(x => x.NotifyType == PublicEnum.NotifyType.Info).Adapt<NoticeIconData[]>();
- Count = notices.Count(x => x.Seen == false);
- }
- protected void SetClassMap()
- {
- ClassMapper
- .Clear()
- .Add("right");
- }
- public async Task HandleSelectUser(MenuItem item)
- {
- switch (item.Key)
- {
- case "center":
- NavigationManager.NavigateTo("/account/center");
- break;
- case "setting":
- NavigationManager.NavigateTo("/account/setting");
- break;
- case "logout":
- var localStorageHelper = new LocalStorage(JSRuntime);
- await localStorageHelper.RemoveLocalStorage(LocalStorage.AutoLogin);
- await localStorageHelper.RemoveLocalStorage(LocalStorage.UserInfo);
- var host = _accessor.GetHost();
- LogLogin.Insert(new SystemLogLogin() { Info = $"用户【{Global.CurrentUser.Account}】登出账号", UserId = Global.CurrentUser.Id, CreateTime = DateTime.Now });
- NavigationManager.NavigateTo("/account/login");
- Global.CurrentUser = null;
- break;
- }
- }
- public async Task Seen(string key)
- {
- Notices.AsUpdateable()
- .SetColumns(x => x.Seen == true)
- .Where(x => x.Id == Convert.ToInt32(key))
- .ExecuteCommand();
- await Notifications();
- }
- public void HandleSelectLang(MenuItem item)
- {
- LocalizationService.SetLanguage(CultureInfo.GetCultureInfo(item.Key));
- }
- public async Task HandleClear(string key)
- {
- switch (key)
- {
- case "notification":
- Notices.AsDeleteable().Where(x => x.NotifyType == PublicEnum.NotifyType.Notify).ExecuteCommand();
- IconNotifications = [];
- break;
- case "message":
- Notices.AsDeleteable().Where(x => x.NotifyType == PublicEnum.NotifyType.Info).ExecuteCommand();
- Messages = [];
- break;
- }
- MessageService.Success($"清空了{key}");
- await Notifications();
- }
- public async Task HandleViewMore(string key)
- {
- MessageService.Info("点击查看更多");
- }
- private NoticeIconData[] IconNotifications = { };
- private NoticeIconData[] Messages = { };
- private int Count = 0;
- private AvatarMenuItem[] AvatarMenuItems =>
- [
- //new() { Key = "center", IconType = "user", Option = L["menu.account.center"]},
- new() { Key = "setting", IconType = "setting", Option = L["menu.account.settings"] },
- new() { IsDivider = true },
- new() { Key = "logout", IconType = "logout", Option = L["menu.account.logout"]}
- ];
- private SystemUser CurrentUser = new SystemUser();
- /// <summary>
- ///
- /// </summary>
- [Inject] protected NavigationManager NavigationManager { get; set; }
- /// <summary>
- ///
- /// </summary>
- [Inject] protected MessageService MessageService { get; set; }
- /// <summary>
- ///
- /// </summary>
- [Inject] private IStringLocalizer<I18n> L { get; set; }
- /// <summary>
- ///
- /// </summary>
- [Inject] private ILocalizationService LocalizationService { get; set; }
- /// <summary>
- ///
- /// </summary>
- [Inject] private IWebHostEnvironment WebHostEnvironment { get; set; }
- /// <summary>
- ///
- /// </summary>
- [Inject] private IHttpContextAccessor _accessor { get; set; }
- /// <summary>
- ///
- /// </summary>
- [Inject] private IJSRuntime JSRuntime { get; set; }
- /// <summary>
- ///
- /// </summary>
- [Inject] private SqlSugarRepository<SystemLogLogin> LogLogin { get; set; }
- /// <summary>
- ///
- /// </summary>
- [Inject] private SqlSugarRepository<SystemNotification> Notices { get; set; }
- }
|