From c9179aa494559b7d376d1d473b3720ae61c1defe Mon Sep 17 00:00:00 2001
From: cshenfu <men883234@gmail.com>
Date: 星期一, 31 十月 2022 17:13:39 +0800
Subject: [PATCH] noChange

---
 js/index.js |  156 ++++++++++++++++++++++++++-------------------------
 1 files changed, 79 insertions(+), 77 deletions(-)

diff --git a/js/index.js b/js/index.js
index 59789c3..359dc8f 100644
--- a/js/index.js
+++ b/js/index.js
@@ -1,67 +1,69 @@
 "use script"; //寮�鍙戠幆澧冨缓璁紑鍚弗鏍兼ā寮�
 //绯荤粺涓诲叆鍙�
-
+ 
 var map; //鍦扮悆瀵硅薄
 var request; //浼犲叆鐨刧et鍙傛暟
 var geoJsonLayer;
-
+ 
 //鍦板浘
 $(document).ready(function () {
   //鍒ゆ柇webgl鏀寔
   if (!mars3d.Util.webglreport()) {
     mars3d.Util.webglerror();
   }
-
+ 
   //璁板綍url浼犲叆鍙傛暟
   request = haoutil.system.getRequest();
   if (window.top) {
     //鏈夌埗绾�
     request = $.extend(request, haoutil.system.getRequest(window.top));
   }
-
-  // try {
-  //   var jwtstr = request.JWT;
-  //   var strs_ = jwtstr.split('.');
-  //   var jwt_header_ = new buffer.Buffer(strs_[0].toString('base64'), 'base64').toString();
-  //   var jwt_payload_ = new buffer.Buffer(strs_[1].toString('base64'), 'base64').toString();
-  //   var payload_ = JSON.parse(jwt_payload_);
-  //   mars3d.global_variables.userid = payload_.userid;
-  //   mars3d.global_variables.regionCode = payload_.divcode;
-  //   var hash = CryptoJS.HmacSHA256(strs_[0] + '.' + strs_[1], "sxyd");
-  //   var hashInBase64 = base64UrlEncode(hash);
-
-  //   var reg = RegExp(strs_[2]);
-  //   if (!reg.exec(hashInBase64)) {
-  //     // verification failed, go back
-  //     window.top.location = mars3d.global_variables.un_authorization_url;
-  //   }
-  //   payload_ = JSON.parse(jwt_payload_);
-  //   if (!payload_ || !payload_.expires) {
-  //     // verification error ,go back 
-  //     window.top.location = mars3d.global_variables.un_authorization_url;
-  //   }
-  //   var date1 = new Date(payload_.expires);
-  //   var date2 = new Date();
-  //   if (date1 < date2) {
-  //     // expire, go back
-  //     window.top.location = mars3d.global_variables.un_authorization_url;
-  //   }
-  // }
-  // catch (err) {
-  //   window.top.location = mars3d.global_variables.un_authorization_url;
-  // }
-
-  mars3d.global_variables.userid = request?.userid || 2;
+ 
+  try {
+    var jwtstr = request.JWT;
+    var strs_ = jwtstr.split('.');
+    var jwt_header_ = new buffer.Buffer(strs_[0].toString('base64'), 'base64').toString();
+    var jwt_payload_ = new buffer.Buffer(strs_[1].toString('base64'), 'base64').toString();
+    var payload_ = JSON.parse(jwt_payload_);
+    mars3d.global_variables.userid = payload_.userid;
+    mars3d.global_variables.regionCode = payload_.divcode;
+    var hash = CryptoJS.HmacSHA256(strs_[0] + '.' + strs_[1], "sxyd");
+    var hashInBase64 = base64UrlEncode(hash);
+ 
+    var reg = RegExp(strs_[2]);
+    if (!reg.exec(hashInBase64)) {
+      // verification failed, go back
+      window.top.location = mars3d.global_variables.un_authorization_url;
+    }
+    payload_ = JSON.parse(jwt_payload_);
+    if (!payload_ || !payload_.expires) {
+      // verification error ,go back 
+      window.top.location = mars3d.global_variables.un_authorization_url;
+    }
+    var date1 = new Date(payload_.expires);
+    var date2 = new Date();
+    if (date1 < date2) {
+      // expire, go back
+      window.top.location = mars3d.global_variables.un_authorization_url;
+    }
+  }
+  catch (err) {
+    window.top.location = mars3d.global_variables.un_authorization_url;
+  }
+ 
+  if(!mars3d.global_variables.userid) {
+    mars3d.global_variables.userid = 2;
+  }
   regionCode = mars3d.global_variables.regionCode
-
+ 
   var configfile = "config/config.json"; //榛樿鍦板潃
   if (request.config) {
     //url浼犲叆鍦板潃
     configfile = request.config;
   }
-
+ 
   haoutil.loading.show();
-
+ 
   $.ajax({
     type: "get",
     dataType: "json",
@@ -69,10 +71,10 @@
     timeout: 0,
     success: function (data) {
       haoutil.loading.hide();
-
+ 
       //鏋勫缓鍦板浘
       initMap(data.map3d);
-
+ 
       setTimeout(removeMask, 3000); //娆㈣繋UI鍏抽棴澶勭悊
     },
     error: function (request, textStatus) {
@@ -82,50 +84,50 @@
       console.log(textStatus, request);
     },
   });
-
+ 
   initUI();
 });
-
+ 
 function removeMask() {
   $("#mask").remove();
 }
-
+ 
 //UI鐣岄潰鐩稿叧
 function initUI() {
   haoutil.oneMsg("棣栨璁块棶绯荤粺鏃犵紦瀛樹細鐣ユ參锛岃鑰愬績绛夊緟锛�", "load3d_tip");
 }
-
+ 
 //鍒濆鍖栧湴鍥�
 function initMap(mapOptions) {
   //鍚堝苟灞炴�у弬鏁帮紝鍙鐩朿onfig.json涓殑瀵瑰簲閰嶇疆
   // mapOptions = mars3d.Util.merge(mapOptions, {})
-
+ 
   //鍒涘缓涓夌淮鍦扮悆鍦烘櫙
   map = new mars3d.Map("mars3dContainer", mapOptions);
-
-
+ 
+ 
   //鏋勯�爓idget
   initWidget(map);
-
+ 
   initLayersByUserid();
-
-
+ 
+ 
   //濡傛灉鏈墄yz浼犲弬锛岃繘琛屽畾浣�
   if (haoutil.isutil.isNotNull(request.x) && haoutil.isutil.isNotNull(request.y)) {
     map.setCameraView(request, { duration: 0, isWgs84: true });
   }
-
+ 
   //寮�鍦哄姩鐢�
   //map.openFlyAnimation();
-
+ 
   //閽堝涓嶅悓缁堢鐨勪紭鍖栭厤缃�
   if (haoutil.system.isPCBroswer()) {
     // Cesium 1.61浠ュ悗浼氶粯璁ゅ叧闂弽璧版牱锛屽浜庢闈㈢鑰岃█杩樻槸寮�鍚緱濂斤紝
     map.scene.postProcessStages.fxaa.enabled = true;
-
+ 
     //榧犳爣婊氳疆鏀惧ぇ鐨勬闀垮弬鏁�
     map.scene.screenSpaceCameraController._zoomFactor = 2.0;
-
+ 
     //IE娴忚鍣ㄤ紭鍖�
     if (window.navigator.userAgent.toLowerCase().indexOf("msie") >= 0) {
       map.viewer.targetFrameRate = 20; //闄愬埗甯х巼
@@ -134,34 +136,34 @@
   } else {
     //榧犳爣婊氳疆鏀惧ぇ鐨勬闀垮弬鏁�
     map.scene.screenSpaceCameraController._zoomFactor = 5.0;
-
+ 
     //绉诲姩璁惧涓婄鎺変互涓嬪嚑涓�夐」锛屽彲浠ョ浉瀵规洿鍔犳祦鐣�
     map.viewer.requestRenderMode = true; //鍙栨秷瀹炴椂娓叉煋
     map.scene.fog.enabled = false;
     map.scene.skyAtmosphere.show = false;
     map.scene.globe.showGroundAtmosphere = false;
   }
-
+ 
   //浜屼笁缁村垏鎹笉鐢ㄥ姩鐢�
   if (map.sceneModePicker) {
     map.sceneModePicker.viewModel.duration = 0.0;
   }
-
+ 
   //webgl娓叉煋澶辫触鍚庯紝鍒锋柊椤甸潰
   // map.on(mars3d.EventType.renderError, function (scene, error) {
   //   window.location.reload();
   // });
-
+ 
   //缁戝畾鍗曞嚮鏄剧ずBIM鐨勬瀯浠舵爲
   bindShowTilesParts();
-
+ 
   //涓嬮潰鍙互缁х画鍔犻」鐩浉鍏崇殑鍏朵粬浠g爜
 }
-
+ 
 //鍒濆鍖杦idget鐩稿叧
 function initWidget(map) {
   haoutil.loading.show();
-
+ 
   $.ajax({
     type: "get",
     dataType: "json",
@@ -169,7 +171,7 @@
     timeout: 0,
     success: function (widgetCfg) {
       haoutil.loading.hide();
-
+ 
       //url濡傛灉鏈変紶鍙傛椂鐨勫鐞�
       if (haoutil.isutil.isNotNull(request.widget)) {
         if (request.onlyStart) {
@@ -185,10 +187,10 @@
         });
         map.flyHome({ duration: 0 });
       }
-
+ 
       //鍒濆鍖杦idget绠$悊鍣�
       mars3d.widget.init(map, widgetCfg, "./"); //tip: 绗�3涓弬鏁版敮鎸佸畾涔墂idget鐩綍鐨勭浉瀵硅矾寰勩��
-
+ 
       if (window.lastWidgetItem) {
         activateWidget(lastWidgetItem);
         lastWidgetItem = null;
@@ -199,7 +201,7 @@
       haoutil.alert("config/widget.json鏂囦欢鍔犺浇澶辫触锛�");
     },
   });
-
+ 
   //widget鐩稿叧浜嬩欢鐩戝惉
   // mars3d.widget.on(mars3d.widget.EventType.load, function (event) {
   //     console.log("寮曞叆鍔犺浇浜唚idget鐨刯s", event);
@@ -207,7 +209,7 @@
   // mars3d.widget.on(mars3d.widget.EventType.beforeCreate, function (event) {
   //     console.log("涓嶅垱寤簑idet", event);
   // }) 
-
+ 
   mars3d.widget.on(mars3d.widget.EventType.activated, function (event) {
     console.log("婵�娲讳簡widget", event);
   });
@@ -215,7 +217,7 @@
     console.log("閲婃斁浜唚idget", event);
   });
 }
-
+ 
 //bim鏋勪欢鐨勫鐞�
 function bindShowTilesParts() {
   //鍗曞嚮鍦板浘浜嬩欢
@@ -224,15 +226,15 @@
       //涓嶆槸BIM鏁版嵁鏃惰烦鍑�
       return;
     }
-
+ 
     let layer = event.layer;
     if (!layer.options.scenetree) {
       //鏈厤缃畇cenetree鏃惰烦鍑�
       return;
     }
-
+ 
     var tilesParts = "widgets/tilesParts/widget.js";
-
+ 
     if (mars3d.widget.isActivate(tilesParts)) {
       var parts = mars3d.widget.getClass(tilesParts);
       if (parts.config.layerCfg == layer.options) {
@@ -240,7 +242,7 @@
         return;
       }
     }
-
+ 
     mars3d.widget.activate({
       name: layer.name + " 鏋勪欢",
       uri: tilesParts,
@@ -249,7 +251,7 @@
     });
   });
 }
-
+ 
 //澶栭儴椤甸潰璋冪敤
 var lastWidgetItem;
 function activateWidget(item) {
@@ -265,15 +267,15 @@
 function activateFunByMenu(fun) {
   eval(fun);
 }
-
+ 
 function goHome() {
   mars3d.widget.disableAll();
   map.flyHome();
 }
-
+ 
 function base64UrlEncode(str) {
   var encodedSource = CryptoJS.enc.Base64.stringify(str);
   var reg = new RegExp('/', 'g');
   encodedSource = encodedSource.replace(/=+$/,'').replace(/\+/g,'-').replace(reg,'_');
   return encodedSource;
-}
\ No newline at end of file
+}

--
Gitblit v1.9.1