From b39483c96ae572121d3c619c0b9d37634e682cc4 Mon Sep 17 00:00:00 2001
From: xiebin <123456>
Date: Thu, 02 Mar 2023 10:21:41 +0800
Subject: [PATCH] 增加token验证功能,实现统一登陆

---
 index.html |   52 +++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/index.html b/index.html
index dabcc6f..67327d7 100644
--- a/index.html
+++ b/index.html
@@ -143,25 +143,51 @@
     </script>
 
     <script>
+        function getUrlParam(name) {
+            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
+            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
+            if (r != null) return unescape(r[2]); return null; //返回参数值
+        }
         $(function () {
+            var token  = getUrlParam("token")
+            var login  = sessionStorage.getItem("shuiwen-token")
             //JavaScript JSON.parse()方法用于将一个 JSON 字符串转换为对象。
-            var login = sessionStorage.getItem("shuiwen-token");
+            // var login = sessionStorage.getItem("shuiwen-token");
+            if (!login) {
+                if (token) {
+                    $.ajax({
+                        url: "http://192.168.0.207:82/blade-ycreal/auth/jwtLogin?token=" + token,
+                        type: 'get',
+                        headers: {
+                            'Authorization': 'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
+                            "Tenant-Id": "000000"
+                        },
+                        data: {},
+                        dataType: 'JSON',
+                        success: function (res) {
+                            if (res.success == "true") {
+                                $('#map2d').hide();
 
-            if (login) {
-                if (login.length == 0) {
+                                $('.swDiv').mouseover(function(){
+                                    $('.hover-box').css('display','block');
+                                })
+                                $('.swDiv').mouseout(function(){
+                                    $('.hover-box').css('display','none');
+                                })
+                                return
+                            } else {
+                                window.location.href = "login.html";
+                            }
+                        },
+                        error: function (res) {
+                            window.location.href = "login.html";
+                        },
+
+                    })
+                } else {
                     window.location.href = "login.html";
                 }
-            } else {
-                window.location.href = "login.html";
             }
-            $('#map2d').hide();
-
-            $('.swDiv').mouseover(function(){
-                $('.hover-box').css('display','block');
-            })
-            $('.swDiv').mouseout(function(){
-                $('.hover-box').css('display','none');
-            })
         });
 
         function map3dClick() {

--
Gitblit v1.9.3