From 556464a10ec5f3946b738080428a848154d5b780 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期一, 12 八月 2024 09:06:39 +0800
Subject: [PATCH] 添加识别二维码切换地址的功能

---
 pages/home/home.js |  166 +++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 107 insertions(+), 59 deletions(-)

diff --git a/pages/home/home.js b/pages/home/home.js
index dabd0d4..d0a7f0b 100644
--- a/pages/home/home.js
+++ b/pages/home/home.js
@@ -27,7 +27,8 @@
       content: '纭'
     },
     errorDialogTitle: "鍏抽榾閿欒",
-    showForceConfirm: false //鏄惁寮哄埗寮�闃�
+    showForceConfirm: false, //鏄惁寮哄埗寮�闃�
+    lastIntakeName: ""
   },
 
   openValve: function (e) {
@@ -74,6 +75,9 @@
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad(options) {
+    //鍒ゆ柇鏈湴鏄惁淇濆瓨sessionId
+
+
     // 浣跨敤 wx.nextTick 绛夊緟椤甸潰娓叉煋瀹屾垚
     wx.nextTick(() => {
       this.calculateScrollViewHeight();
@@ -88,27 +92,14 @@
       })
       this.getOpenList();
     }
-    this.getUserDataBySession();
+    this.initData();
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚
    */
   onReady() {
-    //鍒ゆ柇鏈湴鏄惁淇濆瓨sessionId
-    if (storage.isHasKeySync("sessionId")) {
-      storage.getItem('sessionId').then((data) => {
-        this.setData({
-          sessionId: data
-        });
-        if (sessionId !== "") {}
-      }).catch((err) => {
-        console.error('Failed to load parameter:', err);
-      });
-    } else {
-      console.log('Failed to load parameter:false');
-    }
-    this.getOpenList();
+
   },
 
   /**
@@ -201,7 +192,7 @@
       showForceConfirm: false
     });
   },
-  cancelDialog(){
+  cancelDialog() {
     this.setData({
       showForceConfirm: false,
       showConfirm: false
@@ -340,57 +331,114 @@
     wx.scanCode({
       success(res) {
         console.log(res.result); // 褰撲笖浠呭綋鎵爜涓洪潪寰俊浜岀淮鐮佹椂锛屼細杩斿洖result  
-        wx.showLoading({
-          title: '姝e湪寮�闃�璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧
-          mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false
-        });
-        const app = getApp();
-        const data = {
-          intakeName: res.result, //鍙栨按鍙D
-          // vcId: vcId, //铏氭嫙鍗D
-          operator: app.globalData.sessionId //鎿嶄綔鍛�
-        };
-        post({
-          url: "wx/valve/open_wx",
-          data: data,
-          timeout: 180000
-        }).then(response => {
+        if (res.result.startsWith("content://")) {
+          let jsonStr = res.result.replace("content://", "")
+          try {
 
-          // 澶勭悊鎴愬姛鍝嶅簲
-          console.log('璇锋眰鎴愬姛:', response);
-          // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
-          wx.hideLoading();
-          //瀹屾垚鍚庡洖鍒伴椤�
-          wx.reLaunch({
-            url: '/pages/home/home?param=true' // 棣栭〉鐨勮矾寰勶紝鏍规嵁瀹為檯鎯呭喌濉啓
-          });
-        }).catch(error => {
-          // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
-          wx.hideLoading();
-          // 澶勭悊閿欒鍝嶅簲
-          console.error('璇锋眰澶辫触:', error);
-          if (error.code==="1003") {
-            that.setData({
-              showForceConfirm:true
-            })
-          } else {
-            that.setData({
-              showErrorDialog: true,
-              errorData: error.msg,
-              errorDialogTitle: "寮�闃�閿欒"
-            })
+            that.saveData(jsonStr)
+          } catch (error) {
+            console.error('Error parsing JSON:', error);
           }
-    
 
-        });
+        } else {
+          that.postOppenValva(res.result)
+        }
+
       },
       fail(err) {
         console.error(err);
       }
-
     })
   },
-  confirmForceDialog(){
+  confirmForceDialog() {
     console.log("confirmForceDialog");
+    this.setData({
+      showForceConfirm: false
+    })
+    this.postOppenValva(this.data.lastIntakeName, true)
+  },
+  /**
+   * 
+   * @param {*} intakeName 
+   */
+  postOppenValva(intakeName, isforce) {
+    const that = this;
+    wx.showLoading({
+      title: '姝e湪寮�闃�璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧
+      mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false
+    });
+    const app = getApp();
+    that.setData({
+      lastIntakeName: intakeName
+    })
+    const data = {
+      intakeName: intakeName, //鍙栨按鍙D
+      // vcId: vcId, //铏氭嫙鍗D
+      operator: app.globalData.sessionId, //鎿嶄綔鍛�
+      forceOpen: !!isforce // 浣跨敤閫昏緫闈炴搷浣滅 !! 鏉ョ‘淇� isForce 鏄竷灏斿��  
+    };
+    post({
+      url: "wx/valve/open_wx",
+      data: data,
+      timeout: 180000
+    }).then(response => {
+
+      // 澶勭悊鎴愬姛鍝嶅簲
+      console.log('璇锋眰鎴愬姛:', response);
+      // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
+      wx.hideLoading();
+      //瀹屾垚鍚庡洖鍒伴椤�
+      wx.reLaunch({
+        url: '/pages/home/home?param=true' // 棣栭〉鐨勮矾寰勶紝鏍规嵁瀹為檯鎯呭喌濉啓
+      });
+    }).catch(error => {
+      // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
+      wx.hideLoading();
+      // 澶勭悊閿欒鍝嶅簲
+      console.error('璇锋眰澶辫触:', error);
+      if (error.code === "10005") {
+        that.setData({
+          showForceConfirm: true
+        })
+      } else {
+        that.setData({
+          showErrorDialog: true,
+          errorData: error.msg,
+          errorDialogTitle: "寮�闃�閿欒"
+        })
+      }
+    });
+  },
+  /**
+   * 鎵弿鍚庝繚瀛樼敤鎴穒d鍜宼ag
+   */
+  saveData(userData) {
+    storage.setItem("userData", userData).then(() => {
+      this.initData();
+    }).catch((error) => {});
+
+  },
+  //杩涘叆鐣岄潰鑾峰彇鐣岄潰鏁版嵁
+  initData() {
+    const app = getApp();
+    console.log("tag>>>>:" +app.globalData.tag)
+ 
+    if (storage.isHasKeySync("userData")) {
+      storage.getItem('userData').then((data) => {
+        let jsonObj = JSON.parse(data);
+        app.globalData.sessionId = jsonObj.sessionId;
+        app.globalData.tag = jsonObj.tag;
+        this.getUserDataBySession();
+        this.getOpenList();
+        console.log("userData>>>>>>>" + data)
+      }).catch((err) => {
+        console.error('Failed to load parameter:', err);
+      });
+    } else {
+      this.getUserDataBySession();
+      this.getOpenList();
+      console.log('Failed to load parameter:false');
+    }
+  
   }
 })
\ No newline at end of file

--
Gitblit v1.8.0