Browse Source

web端单点登录

pengjing 2 tháng trước cách đây
mục cha
commit
fc374ba91b

+ 35 - 27
src/main/resources/static/app/main/controllers.js

@@ -1,25 +1,27 @@
 (function () {
     'use strict';
-    angular.module('gtPartyApp').controller("homeCtrl", function ($scope, $state, $http, AuthUser, $modal, $interval, $q, $filter, $loading, $bsfiles, $alert, $bsRouterState,$timeout,$rootScope,$desData) {
+    angular.module('gtPartyApp').controller("homeCtrl", function ($scope, $state, $http, AuthUser, $modal, $interval, $q, $filter, $loading, $bsfiles, $alert, $bsRouterState, $timeout, $rootScope, $desData) {
 
         var gsModal = {};//客服弹出框
-        $scope.userOnlineIsOut=false;
-        $scope.sysName=window.sysCompanyName;
-        $scope.userOnlineActivityFun=function(){
+        $scope.userOnlineIsOut = false;
+        $scope.sysName = window.sysCompanyName;
+        $scope.userOnlineActivityFun = function () {
             //判断是否已经退出登陆
-            if($scope.userOnlineIsOut){
+            if ($scope.userOnlineIsOut) {
                 return;
             }
-            $http.post("../../api/home/setOnlineUser", {
-                uid: AuthUser.getUser().Id
-            }).then(function (res) {
-                if(res.data.success){
-                    $timeout($scope.userOnlineActivityFun,60*1000);
-                } else {
-                    $scope.loginOutCookie();
-                }
+            if (AuthUser.getUser().Id) {
+                $http.post("../../api/home/setOnlineUser", {
+                    uid: AuthUser.getUser().Id
+                }).then(function (res) {
+                    if (res.data.success) {
+                        $timeout($scope.userOnlineActivityFun, 60 * 1000);
+                    } else {
+                        $scope.loginOutCookie();
+                    }
 
-            });
+                });
+            }
         };
         $scope.User = {name: ''};
         $scope.panels = [];
@@ -53,7 +55,7 @@
                 //修改选择角色
                 $scope.User.curRoleId = newVal;
                 AuthUser.setUser($scope.User);
-                $bsRouterState.tabs.length=0;
+                $bsRouterState.tabs.length = 0;
                 $scope.getMenuList(newVal);
                 $scope.getUserDataScope();
             }
@@ -72,7 +74,7 @@
                     appkey: $scope.menudatas.appkey,
                     defrolekey: $scope.menudatas.defrolekey,
                     roleId: roleId,
-                    dwId:$scope.User.dwId
+                    dwId: $scope.User.dwId
                 }
             }).then(function (result) {
                 if (result.data.success) {
@@ -111,7 +113,7 @@
                 $scope.User.dataDzzdm = res.data.dataDzzdm;
                 AuthUser.setUser($scope.User);
 
-                $bsRouterState.$showTab($bsRouterState.defaults.initTabName,{});
+                $bsRouterState.$showTab($bsRouterState.defaults.initTabName, {});
                 //tabs.
 
             });
@@ -231,9 +233,9 @@
                         //$scope.roleList = $filter('orderBy')(req.data.item, '-orderby');
                         $scope.roleList = req.data.item;
                         $scope.roleName = $scope.roleList[0].rolename;
-                        var roleId=AuthUser.getUser().curRoleId;
+                        var roleId = AuthUser.getUser().curRoleId || '';
                         //$scope.roleList.selectedId =roleId==null||roleId=='null'?$scope.roleList[0].roleid:roleId;
-                        $scope.roleList.selectedId =roleId?$scope.roleList[0].roleid:roleId;
+                        $scope.roleList.selectedId = roleId ? $scope.roleList[0].roleid : roleId;
                         //$scope.getMenuList($scope.roleList.selectedId);
                     }
                 }
@@ -263,6 +265,7 @@
                         //AuthUser.setlogin();
                         $scope.User = res.data.item;
                         $scope.User.isServerMan = res.data.extdata != null ? res.data.extdata.isServerMan : false;
+                        AuthUser.setUser($scope.User);
                         //开始心跳查询是否超时
                         $scope.userOnlineActivityFun();
                         //$scope.getMenuList();
@@ -279,13 +282,13 @@
 
         };
 
-        $scope.loginOutCookie=function(){
+        $scope.loginOutCookie = function () {
 
-            $scope.userOnlineIsOut=true;
-            $http.get("../../api/home/logout",{
-                params:{
-                        uid:AuthUser.getUser().Id
-                    }
+            $scope.userOnlineIsOut = true;
+            $http.get("../../api/home/logout", {
+                params: {
+                    uid: AuthUser.getUser().Id
+                }
             }).then(function (req) {
                 if (req.data.success) {
                     $bsRouterState.tabs.length = 0;
@@ -302,7 +305,7 @@
                         duration: 3
                     });
                 }*/
-                $rootScope.menuToggle=true;
+                $rootScope.menuToggle = true;
                 AuthUser.clearUser();
                 $state.go("login");
 
@@ -530,6 +533,11 @@
 
         };
         return directiveObject;
-    }]).filter('ceil', function() { return function(input) { return Math.ceil(input); }; }); ;
+    }]).filter('ceil', function () {
+        return function (input) {
+            return Math.ceil(input);
+        };
+    });
+    ;
 
 })();

+ 12 - 0
src/main/resources/static/app/main/portalLogin.js

@@ -3,6 +3,18 @@
     $ang.module('gtPartyApp').controller("portalLoginCtrl", ['$scope', '$state', '$http', '$loading', '$alert', '$desData', '$modal', 'AuthUser', function ($scope, $state, $http, $loading, $alert, $desData, $modal, AuthUser) {
         $scope.sysName = window.sysCompanyName;
 
+        $scope.showMsg = function (title, content) {
+            $alert({
+                title: title + ':',
+                content: content,
+                placement: 'top',
+                type: 'info',
+                show: true,
+                duration: 5
+            });
+
+        };
+
         $scope.loadCurUser = function () {
             $http.get("../../api/user/curloginuser", {params: {appkey: "appId"}}).then(function (res) {
                 if (res.data.success && res.data.item) {