UNPKG

mobileoa-common-modules

Version:

移动办公平台前端公共功能模块

50 lines (44 loc) 1.33 kB
'use strict'; var angular = require('angular'); require('./modules'); require('mobileoa-core'); var module = angular.module('login'); module.run(function($rootScope, $state, LinkerCache, localforage) { /** * 在自动登录状态过期后,需要重新登录。 * * @return */ $rootScope.$on('certificateExpires', function() { $rootScope.appEntryState = $state.$current; $state.go('login'); }); /** * 登录成功后对登录人缓存处理 */ $rootScope.$on('login', function() { LinkerCache.get(localStorage.getItem('userId')).then(function(loginUser) { localStorage.setItem('lastLoginUser', JSON.stringify(loginUser)); }); }); function clearCache() { localforage.removeItem('loginUser'); localStorage.removeItem('userId'); localStorage.removeItem('userToken'); localStorage.removeItem('validDate'); delete $rootScope.loginUser; } $rootScope.$on('logout', clearCache); $rootScope.$on('serverUrl.changed', clearCache); }); /** * @deprecated 只适用于v1.12.0版本,计划在v1.15.0版本中删除 */ module.run(function(localforage) { localforage.getItem('lastLoginUser') .then(function(lastLoginUser) { if (lastLoginUser) { localStorage.setItem('lastLoginUser', JSON.stringify(lastLoginUser)); } }); });