@namespace MasaBlazorApp3 @using MasaBlazorApp3.Pojo.Config @using MasaBlazorApp3.Util @using log4net @inherits LayoutComponentBase @if (children.Count > 5) { @foreach (Premission p in children) { if (childrenIds.Any(id => id == p.Id)) { @p.PremissionName } } @if (children.Any(c => c.PremissionPath.Contains("Box"))) { } } else { @foreach (Premission p in children) { if (childrenIds.Any(id => id == p.Id)) { @p.PremissionName } } @if (children.Any(c => c.PremissionPath.Contains("Box"))) { } }
@Body
@code { @inject GlobalStateService globalStateService; @inject NavigationManager na; int selectedIndex = 0; Pojo.User Operator; List childrenIds; List children; @inject Microsoft.Extensions.Options.IOptions setting; @inject PortUtil _portUtil; @inject NotificationService _message private readonly ILog logger = LogManager.GetLogger(typeof(MainLayout)); bool currentPage = true; protected override void OnInitialized() { string Uri = na.Uri; string[] s = Uri.Split("/"); Operator = globalStateService.Operator; Premission parent = new Premission().getAdminPremission().Find(p => p.PremissionPath == s[3]); childrenIds = Operator.role.permissionIds.Where(id => id - (parent.Id * 10) < 10).ToList(); children = parent.Items.ToList(); if (setting.Value.autoOutLog > 0) { // 是否需要自动退出 var promiseUtil = new PromiseUtil(); promiseUtil.taskAsyncLoop(500, null, async (data, next, stop) => { if (globalStateService.Operator == null || !currentPage) { logger.Info($"MainLayout页自动退出循环停止{globalStateService.Operator == null},{!currentPage}"); stop(); } else { try { //没有在操作抽屉 if (!_portUtil.Operate) { // 无人操作鼠标键盘 if ((DateTime.Now - _portUtil.dateTime).TotalSeconds > setting.Value.autoOutLog && (DateTime.Now - _portUtil.mouseClickTime).TotalSeconds > setting.Value.autoOutLog) { logger.Info($"设备{setting.Value.autoOutLog}内无人操作,用户【{Operator?.NickName}】自动退出登录,_portUtil.Operate:{_portUtil.Operate},totalSecond:{(DateTime.Now - _portUtil.dateTime).TotalSeconds},lastInputTime:{(DateTime.Now - _portUtil.mouseClickTime).TotalSeconds},autoOutLog:{setting.Value.autoOutLog}"); globalStateService.Operator = null; globalStateService.Reviewer = null; na.NavigateTo(""); stop(); } else { next(); } } else { next(); } } catch (Exception ex) { logger.Info($"检查是否自动退出循环异常:{ex.Message}"); next(); } } }); } base.OnInitialized(); } void backHome() { PortUtil.speechSynthesizer.SpeakAsyncCancelAll(); currentPage = false; na.NavigateTo(""); } void logout() { PortUtil.speechSynthesizer.SpeakAsyncCancelAll(); globalStateService.Operator = null; globalStateService.Reviewer = null; na.NavigateTo(""); } async Task OpenStorage() { try { var b = await _portUtil.OpenStorage(); } catch (Exception ex) { logger.Info($"开储物箱发生错误,{ex.Message}"); _message.Notify( new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "提示", Detail = $"开储物箱发生错误,{ex.Message}", Duration = 4000 } ); } } } @code { }