feat: 自动锁屏功能

This commit is contained in:
Argo Zhang 2019-09-21 23:35:21 +08:00
parent 37d7524e0e
commit 413d0a4a32
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
8 changed files with 105 additions and 2 deletions

View File

@ -22,6 +22,8 @@ namespace Bootstrap.Admin.Models
AllowOAuth = DictHelper.RetrieveOAuthLogin(); AllowOAuth = DictHelper.RetrieveOAuthLogin();
ShowMobile = AllowMobile ? "" : "mobile"; ShowMobile = AllowMobile ? "" : "mobile";
ShowOAuth = AllowOAuth ? "" : "oauth"; ShowOAuth = AllowOAuth ? "" : "oauth";
LockScreenPeriod = DictHelper.RetrieveAutoLockScreenPeriod();
EnableAutoLockScreen = DictHelper.RetrieveAutoLockScreen();
} }
/// <summary> /// <summary>
@ -73,5 +75,15 @@ namespace Bootstrap.Admin.Models
/// 获得 是否允许第三方 OAuth 认证登录 /// 获得 是否允许第三方 OAuth 认证登录
/// </summary> /// </summary>
public string ShowOAuth { get; } public string ShowOAuth { get; }
/// <summary>
/// 获得 自动锁屏时长 默认 1 分钟 字典表中配置
/// </summary>
public int LockScreenPeriod { get; }
/// <summary>
/// 获得 自动锁屏功能是否自动开启 默认关闭
/// </summary>
public bool EnableAutoLockScreen { get; }
} }
} }

View File

@ -17,11 +17,17 @@ namespace Bootstrap.Admin.Models
public SettingsModel(ControllerBase controller) : base(controller) public SettingsModel(ControllerBase controller) : base(controller)
{ {
Themes = DictHelper.RetrieveThemes(); Themes = DictHelper.RetrieveThemes();
AutoLockScreen = EnableAutoLockScreen ? "" : "lockScreen";
} }
/// <summary> /// <summary>
/// 获得 系统配置的所有样式表 /// 获得 系统配置的所有样式表
/// </summary> /// </summary>
public IEnumerable<BootstrapDict> Themes { get; } public IEnumerable<BootstrapDict> Themes { get; }
/// <summary>
/// 获得 是否开启自动锁屏
/// </summary>
public string AutoLockScreen { get; }
} }
} }

View File

@ -95,7 +95,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer text-right">
<button data-method="UISettings" class="btn btn-secondary" type="button"><i class="fa fa-save"></i><span>保存</span></button> <button data-method="UISettings" class="btn btn-secondary" type="button"><i class="fa fa-save"></i><span>保存</span></button>
</div> </div>
</div> </div>
@ -115,11 +115,31 @@
</div> </div>
</div> </div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer text-right">
<button data-method="LoginSettings" class="btn btn-secondary" type="button"><i class="fa fa-save"></i><span>保存</span></button> <button data-method="LoginSettings" class="btn btn-secondary" type="button"><i class="fa fa-save"></i><span>保存</span></button>
</div> </div>
</div> </div>
</div> </div>
<div class="card">
<div class="card-header">自动锁屏设置</div>
<div class="card-body">
<div class="form-inline">
<div class="row">
<div class="form-group col-6">
<label class="control-label" for="lockScreen">自动锁屏</label>
<input id="lockScreen" hidden type="checkbox" data-default-val="@Model.AutoLockScreen" data-toggle="toggle" data-width="120" data-onstyle="success" data-on="开启" data-off="关闭" />
</div>
<div class="form-group col-6">
<label class="control-label" for="lockPeriod">时长间隔(秒)</label>
<input id="lockPeriod" type="number" class="form-control" min="30" value="@Model.LockScreenPeriod" />
</div>
</div>
</div>
<div class="modal-footer text-right">
<button data-method="saveAutoLock" class="btn btn-secondary" type="button"><i class="fa fa-save"></i><span>保存</span></button>
</div>
</div>
</div>
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
<div class="d-flex align-items-center"> <div class="d-flex align-items-center">

View File

@ -37,6 +37,7 @@
} }
@await Html.PartialAsync("Navigator") @await Html.PartialAsync("Navigator")
<section id="main-content" class="main-content @Model.ShowCardTitle"> <section id="main-content" class="main-content @Model.ShowCardTitle">
<input id="lockScreenPeriod" type="hidden" asp-condition="@Model.EnableAutoLockScreen" value="@Model.LockScreenPeriod" />
<div class="main-header"> <div class="main-header">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li class="breadcrumb-item"><a href="~/Admin/Index"><i class="fa fa-home"></i>首页</a></li> <li class="breadcrumb-item"><a href="~/Admin/Index"><i class="fa fa-home"></i>首页</a></li>

View File

@ -167,6 +167,32 @@
})(jQuery); })(jQuery);
$(function () { $(function () {
// 自动锁屏功能
var mousePosition = { screenX: 0, screenY: 0 };
var count = 1;
var lockScreenPeriod = Number.parseInt($('#lockScreenPeriod').val());
if (typeof lockScreenPeriod === 'number' && !isNaN(lockScreenPeriod)) {
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;
return;
}
});
}, 2000);
var lockHandler = window.setInterval(function () {
if (count++ * 5 > lockScreenPeriod) {
window.clearInterval(lockHandler);
window.clearInterval(traceMouseOrKey);
this.location.href = $.formatUrl("Account/Lock");
}
}, 5000);
}
var $sideMenu = $(".sidebar ul"); var $sideMenu = $(".sidebar ul");
// breadcrumb // breadcrumb

View File

@ -52,6 +52,20 @@ $(function () {
} }
}); });
break; break;
case 'saveAutoLock':
var autoLock = $('#lockScreen').prop('checked') ? "1" : "0";
$.bc({
url: Settings.url, data: { name: '自动锁屏', code: autoLock, category: '网站设置' }, method: "post"
});
$.bc({
url: Settings.url, data: { name: '自动锁屏时长', code: $('#lockPeriod').val(), category: '网站设置' }, title: '保存自动锁屏设置', method: "post",
callback: function (result) {
if (result) {
window.setTimeout(function () { window.location.reload(true); }, 1000);
}
}
});
break;
} }
}); });

View File

@ -222,5 +222,17 @@ namespace Bootstrap.DataAccess
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public bool RetrieveOAuthLogin() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "OAuth 认证登录" && d.Define == 0)?.Code ?? "1") == "1"; public bool RetrieveOAuthLogin() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "OAuth 认证登录" && d.Define == 0)?.Code ?? "1") == "1";
/// <summary>
/// 获得自动锁屏时长 默认 30 秒
/// </summary>
/// <returns></returns>
public int RetrieveAutoLockScreenPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "自动锁屏时长" && d.Define == 0)?.Code, 30);
/// <summary>
/// 获得自动锁屏是否开启 默认关闭
/// </summary>
/// <returns></returns>
public bool RetrieveAutoLockScreen() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "自动锁屏" && d.Define == 0)?.Code ?? "0") == "1";
} }
} }

View File

@ -222,5 +222,17 @@ namespace Bootstrap.DataAccess
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static bool RetrieveOAuthLogin() => DbContextManager.Create<Dict>()?.RetrieveOAuthLogin() ?? false; public static bool RetrieveOAuthLogin() => DbContextManager.Create<Dict>()?.RetrieveOAuthLogin() ?? false;
/// <summary>
/// 获得自动锁屏时长 默认 30 秒
/// </summary>
/// <returns></returns>
public static int RetrieveAutoLockScreenPeriod() => DbContextManager.Create<Dict>()?.RetrieveAutoLockScreenPeriod() ?? 30;
/// <summary>
/// 获得自动锁屏 默认关闭
/// </summary>
/// <returns></returns>
public static bool RetrieveAutoLockScreen() => DbContextManager.Create<Dict>()?.RetrieveAutoLockScreen() ?? false;
} }
} }