1

如何使用ng-idleAngularjs 的模块在闲置 30 分钟后实现自动注销?

4

1 回答 1

1

我真的不太了解 angularjs,我正在上一门课程,但我才刚刚开始。虽然我确实知道 github 上有人可以帮助你。我刚刚在这里包含了片段,但如果你想了解更多信息,你应该查看这个网站: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();
});

希望有帮助:)

于 2015-09-04T00:12:39.197 回答