@namespace MasaBlazorApp3 @using MasaBlazorApp3.Pojo.Config @using MasaBlazorApp3.Util @using Microsoft.Extensions.Options; @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 IJSRuntime JSRuntime @inject GlobalStateService globalStateService; @inject NavigationManager na; @inject PortUtil PortUtil; @inject IOptions drawerSetting; 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:{CheckComputerFreeState.GetLastInputTime()},autoOutLog:{setting.Value.autoOutLog}"); //查询所有标签抽屉,设置标签灯为灭灯 int[] labels = drawerSetting.Value.label; for (int i = 0; i < labels.Length; i++) { await PortUtil.setOffLight(labels[i]); } 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(""); } async void logout() { //查询所有标签抽屉,设置标签灯为灭灯 int[] labels = drawerSetting.Value.label; for (int i = 0; i < labels.Length; i++) { await PortUtil.setOffLight(labels[i]); } 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 } ); } } private DotNetObjectReference? dotNetObjectReference; protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { dotNetObjectReference = DotNetObjectReference.Create(this); await JSRuntime.InvokeVoidAsync("registerMouseClickHandler", dotNetObjectReference); } } [JSInvokable] public void HandleMouseClick(int clientX, int clientY) { // 这里处理鼠标点击事件,例如记录日志或更新状态 // Console.WriteLine($"Mouse clicked at: ({clientX}, {clientY})"); _portUtil.mouseClickTime = DateTime.Now; } public void Dispose() { dotNetObjectReference?.Dispose(); } }