소스 검색

添加退出

wenhongquan 9 년 전
부모
커밋
e2931b7e0b

+ 29 - 16
VisualInspection/js/main.js

@@ -1,25 +1,25 @@
 var MENU;
 //计算左面的
-$(document).ready(function() {
+$(document).ready(function () {
 
     console.log($.zui.store.enable)
 
     setletftime();
 
-    $('#treeMenu').on('click', 'a', function() {
+    $('#treeMenu').on('click', 'a', function () {
         if ($(this).hasClass("p_m")) { return; }
         $('#treeMenu li.active').removeClass('active');
         $(this).closest('li').addClass('active');
         getPageInfo(this.id)
-            // $("#main_content").html(getPageInfo(this.id));
+        // $("#main_content").html(getPageInfo(this.id));
     });
 
     //获取用户信息
     var user = $.zui.store.get("user")
-    if (user == null || typeof(user) == "undefined") {
+    if (user == null || typeof (user) == "undefined") {
         layer.msg('登陆已经过期,将重新登陆!', {
             time: 2000, //20s后自动关闭
-        }, function() {
+        }, function () {
             self.location = base_ui_url + UI_USER_LOGIN
         })
 
@@ -29,9 +29,22 @@ $(document).ready(function() {
         $("#user").html(html);
     }
 
+    $("#user").on("click", function () {
+        layer.confirm('您确定要退出登录?', {
+            btn: ['确定'] //按钮
+        }, function () {
+            UserLoginOUT(function () {
+               
+                self.location = base_ui_url + UI_USER_LOGIN
+            }, function (error) {
+                layer.msg(error, { icon: 3 });
+            })
+        });
+    });
+
 
 
-    MenuGetAll(function(data) {
+    MenuGetAll(function (data) {
         //初始化菜单
         var treedata = [];
         for (var i = 0; i < data.length; i++) {
@@ -62,11 +75,11 @@ $(document).ready(function() {
         //获取当前页
         var currentpage = 0;
         currentpage = $.zui.store.get("currentpage");
-        if (typeof(currentpage) != undefined && currentpage != null) {
+        if (typeof (currentpage) != undefined && currentpage != null) {
             //改变页面
             getPageInfo(currentpage);
         }
-    }, function(error) {});
+    }, function (error) { });
 
 });
 
@@ -93,11 +106,11 @@ function setletftime() {
 function getPageInfo(id) {
     //设置当前页面
     $.zui.store.set("currentpage", id);
-    if (typeof(MENU) != "undefined" && MENU != null) {
+    if (typeof (MENU) != "undefined" && MENU != null) {
         for (var i = 0; i < MENU.length; i++) {
             var menu = MENU[i];
             if (menu.id == id) {
-                if (typeof(menu.url) != "undefined") {
+                if (typeof (menu.url) != "undefined") {
                     changePage(menu.url);
                     chageToPageUI(menu)
                     return;
@@ -108,7 +121,7 @@ function getPageInfo(id) {
                 for (var j = 0; j < menu.childs.length; j++) {
                     var mtemp = menu.childs[j];
                     if (mtemp.id == id) {
-                        if (typeof(mtemp.url) != "undefined") {
+                        if (typeof (mtemp.url) != "undefined") {
                             changePage(mtemp.url);
                             chageToPageUI(mtemp)
                             return;
@@ -127,13 +140,13 @@ function getPageInfo(id) {
 
 
 function changePage(url) {
-    if (typeof(url) != "undefined") {
-        CURRENT_PAGE_URL=url;
+    if (typeof (url) != "undefined") {
+        CURRENT_PAGE_URL = url;
         $("#main_content").load(base_ui_url + url);
 
         event = document.createEvent('MessageEvent');
-		var origin = window.location.protocol + '//' + window.location.host;
-		event.initMessageEvent ('changepage', true, true, CURRENT_PAGE_URL, origin, 1234, window, null);
-		document.dispatchEvent (event);
+        var origin = window.location.protocol + '//' + window.location.host;
+        event.initMessageEvent('changepage', true, true, CURRENT_PAGE_URL, origin, 1234, window, null);
+        document.dispatchEvent(event);
     }
 }

+ 17 - 0
VisualInspection/js/util/service.js

@@ -14,6 +14,23 @@ function UserLogin(body, success, fail) {
         fail("网络错误");
     });
 }
+function UserLoginOUT(success, fail) {
+    var url = base_server_url + USER_LOGOUT
+    ajaxGet(url, "", function(response) {
+        var data = response;
+        if (data.result_code == 0) {
+            //存储token
+            $.zui.store.set("user", "");
+            success()
+        } else {
+            fail(data.result_desc);
+        }
+    }, function(error) {
+        fail("网络错误");
+    });
+}
+
+
 
 function UserGetList(data, success, fail) {
     var url = base_server_url + USER_GET_LIST

+ 1 - 1
VisualInspection/view/common/head.html

@@ -13,7 +13,7 @@
 
         <ul class="nav navbar-nav navbar-right">
             <li>
-                <p id="user" class="header_font" style="padding-right:20px"></p>
+                <p id="user" class="header_font" style="padding-right:20px;cursor:pointer;"></p>
             </li>
             <li>
                 <p id="time_p" class="header_font"></p>

+ 1 - 1
VisualInspection_server/src/main/java/com/xintong/visualinspection/controller/UserController.java

@@ -62,7 +62,7 @@ public class UserController extends BaseController {
     		redisCacheUtil.removeForUserName(username);
     	}
     	//返回成功
-    	return returnSuccessResult("退出成功");
+    	return returnResult(0, "退出成功", null);
     }