diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 155aa65730b43db8acac19d5a761fd8e21acf75b..2b75fefb98feeffbb847998998e7755e35acf3a7 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 6.2.7-beta03 + 6.2.7-beta05 diff --git a/src/BootstrapBlazor/Components/AutoRedirect/AutoRedirect.cs b/src/BootstrapBlazor/Components/AutoRedirect/AutoRedirect.cs new file mode 100644 index 0000000000000000000000000000000000000000..3d441427d36a70f205c4166b533538b224b41658 --- /dev/null +++ b/src/BootstrapBlazor/Components/AutoRedirect/AutoRedirect.cs @@ -0,0 +1,101 @@ +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using System; +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; + +namespace BootstrapBlazor.Components; + +/// +/// 自动锁定组件 +/// +public class AutoRedirect : BootstrapComponentBase, IDisposable +{ + /// + /// 获得/设置 登出 Controller Url + /// + [Parameter] + public string? LogoutUrl { get; set; } + + /// + /// 获得/设置 自动锁屏间隔单位 秒 默认 60 秒 + /// + [Parameter] + public int Interval { get; set; } = 60; + + /// + /// 获得/设置 NavigationManager 实例 + /// + [Inject] + [NotNull] + private NavigationManager? NavigationManager { get; set; } + + private JSInterop? Interop { get; set; } + + /// + /// OnInitialized 方法 + /// + protected override void OnInitialized() + { + base.OnInitialized(); + + Interop = new JSInterop(JSRuntime); + } + + /// + /// OnAfterRenderAsync 方法 + /// + /// + /// + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + if (Interop != null) + { + await Interop.InvokeVoidAsync(this, null, "bb_auto_redirect", Interval, nameof(Lock)); + } + } + } + + /// + /// 锁屏操作由 JS 调用 + /// + [JSInvokable] + public void Lock() + { + if (!string.IsNullOrEmpty(LogoutUrl)) + { + NavigationManager.NavigateTo(LogoutUrl, true); + } + } + + /// + /// Dispose 方法 + /// + /// + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + if (Interop != null) + { + Interop.Dispose(); + Interop = null; + } + } + } + + /// + /// + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } +} diff --git a/src/BootstrapBlazor/Components/AutoRedirect/AutoRedirect.js b/src/BootstrapBlazor/Components/AutoRedirect/AutoRedirect.js new file mode 100644 index 0000000000000000000000000000000000000000..63bb1873aed2bb696271c49bcb136bd4593aa533 --- /dev/null +++ b/src/BootstrapBlazor/Components/AutoRedirect/AutoRedirect.js @@ -0,0 +1,27 @@ +(function ($) { + $.extend({ + bb_auto_redirect: function (obj, interval, method) { + var mousePosition = {}; + var count = 1; + var traceMouseOrKey = window.setInterval(function () { + $(document).off('mousemove').one('mousemove', function (e) { + if (mousePosition.screenX !== e.screenX || mousePosition.screenY !== e.screenY) { + mousePosition.screenX = e.screenX; + mousePosition.screenY = e.screenY; + count = 1; + } + }); + $(document).off('keydown').one('keydown', function () { + count = 1; + }) + }, 1000); + var lockHandler = window.setInterval(function () { + if (count++ > interval) { + window.clearInterval(lockHandler); + window.clearInterval(traceMouseOrKey); + obj.invokeMethodAsync(method); + } + }, 1000); + } + }); +})(jQuery); diff --git a/src/BootstrapBlazor/wwwroot/js/bootstrap.blazor.bundle.min.js b/src/BootstrapBlazor/wwwroot/js/bootstrap.blazor.bundle.min.js index 3d497d6353cbcbbaa15d6a677c0a92ba387d66fa..7aed185d8d26e72f6e09a8dea0bb71f8bf599c7f 100644 --- a/src/BootstrapBlazor/wwwroot/js/bootstrap.blazor.bundle.min.js +++ b/src/BootstrapBlazor/wwwroot/js/bootstrap.blazor.bundle.min.js @@ -13,4 +13,4 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this /*! Summernote v0.8.18 | (c) 2013- Alan Hong and other contributors | MIT license */ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("jquery"));else if("function"==typeof define&&define.amd)define(["jquery"],e);else{var n="object"==typeof exports?e(require("jquery")):e(t.jQuery);for(var o in n)("object"==typeof exports?exports:t)[o]=n[o]}}(self,(function(t){return(()=>{"use strict";var e={9458:e=>{e.exports=t}},n={};function o(t){var i=n[t];if(void 0!==i)return i.exports;var r=n[t]={exports:{}};return e[t](r,r.exports,o),r.exports}o.amdO={},o.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return o.d(e,{a:e}),e},o.d=(t,e)=>{for(var n in e)o.o(e,n)&&!o.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};return(()=>{o.r(i);var t=o(9458),e=o.n(t);function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(t,e){for(var n=0;n'),u=s('