【发布时间】:2023-04-03 15:39:01
【问题描述】:
如何使用 Angularjs 的 ng-idle 模块在 30 分钟空闲时间后实现自动注销?
【问题讨论】:
如何使用 Angularjs 的 ng-idle 模块在 30 分钟空闲时间后实现自动注销?
【问题讨论】:
我对 angularjs 真的不太了解,我正在做一个关于它的课程,但我才刚刚开始。虽然我确实知道 github 上有人可以帮助你。我刚刚在此处包含了 sn-ps,但如果您想了解更多信息,请查看此站点:https://github.com/HackedByChinese/ng-idle
不管怎样,这里是:
在 angular.js 之后包含 angular-idle.js。您可以通过以下命令使用 Bower 进行安装:bower install --save ng-idle。
简单的例子:
// include the `ngIdle` module
var app = angular.module('demo', ['ngIdle']);
app
.controller('EventsCtrl', function($scope, Idle) {
$scope.events = [];
$scope.$on('IdleStart', function() {
// the user appears to have gone idle
});
$scope.$on('IdleWarn', function(e, countdown) {
// follows after the IdleStart event, but includes a countdown until the user is considered timed out
// the countdown arg is the number of seconds remaining until then.
// you can change the title or display a warning dialog from here.
// you can let them resume their session by calling Idle.watch()
});
$scope.$on('IdleTimeout', function() {
// the user has timed out (meaning idleDuration + timeout has passed without any activity)
// this is where you'd log them
});
$scope.$on('IdleEnd', function() {
// the user has come back from AFK and is doing stuff. if you are warning them, you can use this to hide the dialog
});
$scope.$on('Keepalive', function() {
// do something to keep the user's session alive
});
})
.config(function(IdleProvider, KeepaliveProvider) {
// configure Idle settings
IdleProvider.idle(5); // in seconds
IdleProvider.timeout(5); // in seconds
KeepaliveProvider.interval(2); // in seconds
})
.run(function(Idle){
// start watching when the app runs. also starts the Keepalive service by default.
Idle.watch();
});
希望有所帮助:)
【讨论】: