From 5d3ed12a593020ec7fd9b5af50991f68b191e649 Mon Sep 17 00:00:00 2001
From: zuoxiao <zuoxiao>
Date: 星期一, 07 四月 2025 17:17:20 +0800
Subject: [PATCH] 调整参数

---
 pages/home/home.js | 1135 +++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 932 insertions(+), 203 deletions(-)

diff --git a/pages/home/home.js b/pages/home/home.js
index d38e37d..dd86186 100644
--- a/pages/home/home.js
+++ b/pages/home/home.js
@@ -4,7 +4,9 @@
   get,
   post
 } = require('../../api/request.js');
-const { PROJECT_URLS } = require('../../api/config.js');
+const {
+  PROJECT_URLS
+} = require('../../api/config.js');
 Page({
 
   /**
@@ -17,7 +19,7 @@
     waterIntakeName: "",
     image: "/images/ic_head_bg.jpg",
     userPhone: "",
-    userName: "璇风櫥褰�",
+    userName: "璇风偣鍑荤櫥褰�",
     scrollViewHeight: 0,
     listData: [],
     isRefreshing: false,
@@ -32,13 +34,23 @@
     lastIntakeName: "",
     showProjectDialog: false,
     selectedProject: '',
-    avatarTapCount: 0
+    avatarTapCount: 0,
+    isFromLogin: false,
+    showTipDialog: ''
   },
 
   openValve: function (e) {
-    wx.navigateTo({
-      url: '/pages/waterIntake/waterIntake',
-    })
+    const app = getApp();
+    if (app.globalData.isLoggedIn) {
+      wx.navigateTo({
+        url: '/pages/waterIntake/waterIntake',
+      })
+    } else {
+      wx.showToast({
+        title: '璇峰厛鐧诲綍',
+        icon: 'error'
+      })
+    }
   },
   calculateScrollViewHeight: function () {
     wx.createSelectorQuery().selectAll('.list-item').boundingClientRect((rects) => {
@@ -49,15 +61,22 @@
     }).exec();
   },
   startPullDownRefresh() {
-    if (!this.data.isWXRefreshing) {
-      var self = this;
-      console.log(this.data.isRefreshing);
-      this.setData({
-        isRefreshing: true
-      });
-      this.getOpenList();
-
+    if (getApp().globalData.isLoggedIn) {
+      if (!this.data.isWXRefreshing) {
+        var self = this;
+        console.log(this.data.isRefreshing);
+        this.setData({
+          isRefreshing: true
+        });
+        this.getOpenList();
+      }
+    } else {
+      wx.showToast({
+        title: '璇峰厛鐧诲綍',
+        icon: 'error'
+      })
     }
+
 
   },
   //鑾峰彇鐢ㄦ埛鏁版嵁
@@ -79,95 +98,225 @@
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad(options) {
-    // 妫�鏌ユ槸鍚﹀凡閫夋嫨椤圭洰
-    const { PROJECT_URLS } = require('../../api/config.js');
-    
-    storage.getItem('selectedProject').then((project) => {
-      if (project) {
-        this.setData({
-          selectedProject: project
-        });
-        
-        // 纭繚鍏ㄥ眬鍙橀噺瀛樺湪
-        getApp().globalData = getApp().globalData || {};
-        // 璁剧疆 baseUrl
-        const baseUrl = PROJECT_URLS[project];
-        getApp().globalData.baseUrl = baseUrl;
-        getApp().globalData.selectedProject = project;
-        
-        // 鏍规嵁椤圭洰璁剧疆瀵瑰簲鐨則ag
-        if (project === 'JYG') {
-          getApp().globalData.tag = 'ym'; // 鍢夊唱鍏抽」鐩搴攖ag涓簓m
-        } else if (project === 'MQ') {
-          getApp().globalData.tag = 'mq'; // 姘戝嫟椤圭洰瀵瑰簲tag涓簃q
-        }
-        
-        console.log('鍔犺浇宸蹭繚瀛樼殑椤圭洰:', project, '鍩熷悕:', baseUrl, 'tag:', getApp().globalData.tag);
-        
-        // 妫�鏌ョ櫥褰曠姸鎬�
-        if (!getApp().globalData.isLoggedIn) {
-          this.checkLoginStatus();
-          return; // 濡傛灉鏈櫥褰曪紝绛夊緟璺宠浆鍒扮櫥褰曢〉闈�
-        }
-      } else {
-        // 棣栨杩涘叆锛屾樉绀洪」鐩�夋嫨寮圭獥
-        this.setData({
-          showProjectDialog: true
-        });
-        return; // 绛夊緟鐢ㄦ埛閫夋嫨椤圭洰
-      }
-      
-      //鍒ゆ柇鏈湴鏄惁淇濆瓨sessionId
-      // 浣跨敤 wx.nextTick 绛夊緟椤甸潰娓叉煋瀹屾垚
-      wx.nextTick(() => {
-        this.calculateScrollViewHeight();
-      });
-      //褰撳紑闃�鎴愬姛鍚庤皟鐢ㄥ埛鏂�
-      console.log("onLoad锛�" + options.param);
-      if (options.param) {
-        wx.showToast({
-          title: '寮�闃�鎴愬姛',
-          icon: 'success',
-          duration: 3000
-        })
-        this.getOpenList();
-      }
-      this.initData();
-    }).catch(err => {
-      console.error('Failed to get selectedProject:', err);
-      // 鍑洪敊鏃朵篃鏄剧ず椤圭洰閫夋嫨寮圭獥
+    console.log('home椤甸潰onLoad寮�濮嬶紝鍙傛暟:', options);
+    //褰撳紑闃�鎴愬姛鍚庤皟鐢ㄥ埛鏂�
+    if (options.param === "1" || options.param === "2") {
       this.setData({
-        showProjectDialog: true
+        options: options
+      })
+    }
+    // 妫�鏌ユ槸鍚︿粠鐧诲綍椤甸潰杩斿洖
+    let fromLogin = false;
+
+    // 妫�鏌RL鍙傛暟
+    if (options && options.fromLogin === 'true') {
+      console.log('妫�娴嬪埌URL鍙傛暟fromLogin=true');
+      fromLogin = true;
+    }
+
+    console.log('home椤甸潰鍔犺浇锛宖romLogin:', fromLogin, '鍙傛暟:', options);
+
+    // 璁剧疆fromLogin鏍囧織
+    if (fromLogin) {
+      console.log('璁剧疆isFromLogin=true');
+      this.setData({
+        isFromLogin: true
       });
-    });
+    }
+
+    // 寤惰繜鎵ц鍓╀綑鐨勫垵濮嬪寲杩囩▼锛屼互纭繚涓存椂鏍囪鍜孶RL鍙傛暟鑳借姝g‘澶勭悊
+    setTimeout(() => {
+      this.initializePage(options, fromLogin);
+    }, 100);
+  },
+
+  // 鏂板鐨勫垵濮嬪寲椤甸潰杈呭姪鍑芥暟锛屽垎绂诲嚭onLoad涓殑閫昏緫浠ヤ究寤惰繜鎵ц
+  initializePage(options, fromLogin) {
+    // 妫�鏌ユ槸鍚﹀凡閫夋嫨椤圭洰
+    const {
+      PROJECT_URLS
+    } = require('../../api/config.js');
+
+    // 纭繚鍏ㄥ眬鍙橀噺瀛樺湪
+    getApp().globalData = getApp().globalData || {};
+
+    storage.getItemSafe('selectedProject')
+      .then((project) => {
+        if (project) {
+          this.setData({
+            selectedProject: project
+          });
+
+          // 璁剧疆 baseUrl
+          const baseUrl = PROJECT_URLS[project];
+          getApp().globalData.baseUrl = baseUrl;
+          getApp().globalData.selectedProject = project;
+
+          // 鏍规嵁椤圭洰璁剧疆瀵瑰簲鐨則ag
+          if (project === 'JYG') {
+            getApp().globalData.tag = 'ym'; // 鍢夊唱鍏抽」鐩搴攖ag涓簓m
+            this.setData({
+              userName: "鍢夊唱鍏抽」鐩�"
+            });
+          } else if (project === 'MQ') {
+            getApp().globalData.tag = 'mq'; // 姘戝嫟椤圭洰瀵瑰簲tag涓簃q
+            this.setData({
+              userName: "姘戝嫟椤圭洰"
+            });
+            // 鍔犺浇姘戝嫟椤圭洰鎸佷箙鍖栧弬鏁�
+            return storage.getItemSafe('MQ_params')
+              .then(params => {
+                if (params) {
+                  getApp().globalData.operator = params.operator;
+                  getApp().globalData.clientId = params.clientId;
+                  getApp().globalData.isLoggedIn = params.isLoggedIn;
+                  getApp().globalData.sessionId = params.sessionId;
+                }
+                return Promise.resolve();
+              });
+          } else if (project === 'TEST') {
+            getApp().globalData.tag = 'ym'; // 娴嬭瘯椤圭洰瀵瑰簲tag涓簍est
+            this.setData({
+              userName: "娴嬭瘯椤圭洰"
+            });
+            // 鍔犺浇娴嬭瘯椤圭洰鎸佷箙鍖栧弬鏁�
+            return storage.getItemSafe('TEST_params')
+              .then(params => {
+                if (params) {
+                  getApp().globalData.operator = params.operator;
+                  getApp().globalData.clientId = params.clientId;
+                  getApp().globalData.isLoggedIn = params.isLoggedIn;
+                  getApp().globalData.sessionId = params.sessionId;
+                  getApp().globalData.vcId = params.vcId;
+                }
+                return Promise.resolve();
+              });
+          }
+
+          // 缁х画鍒濆鍖栭〉闈�
+          this.continueInitPage(options);
+        } else {
+          // 棣栨杩涘叆锛屾樉绀洪」鐩�夋嫨寮圭獥
+          this.setData({
+            showProjectDialog: true
+          });
+          return Promise.reject({
+            type: 'project_not_selected',
+            message: '鏈�夋嫨椤圭洰'
+          }); // 缁堟鍚庣画澶勭悊
+        }
+      })
+      .then(() => {
+        // 缁х画鍒濆鍖栭〉闈�
+        this.continueInitPage(options);
+      })
+      .catch(err => {
+        // 灏嗛敊璇璞¤鑼冨寲
+        const error = typeof err === 'object' ? err : {
+          type: 'unknown',
+          message: String(err)
+        };
+        console.log('鑾峰彇瀛樺偍鏁版嵁涓柇:', error.message);
+
+        // 濡傛灉鏄粠鐧诲綍椤佃繑鍥炴垨宸茬櫥褰曪紝涓嶅啀璺宠浆
+        if (fromLogin || getApp().globalData.isLoggedIn) {
+          console.log('浠庣櫥褰曢〉杩斿洖鎴栧凡鐧诲綍锛岀户缁垵濮嬪寲椤甸潰');
+          this.continueInitPage(options);
+          return;
+        }
+
+        // 澶勭悊鏈�夋嫨椤圭洰鐨勬儏鍐�
+        if (error.type === 'project_not_selected') {
+          console.log('鏈�夋嫨椤圭洰锛屾樉绀洪」鐩�夋嫨寮圭獥');
+          this.setData({
+            showProjectDialog: true
+          });
+          return;
+        }
+
+        // 鍏朵粬鏈煡閿欒锛屽皾璇曠户缁垵濮嬪寲椤甸潰
+        console.warn('鏈煡閿欒锛屽皾璇曠户缁垵濮嬪寲椤甸潰:', error);
+        this.continueInitPage(options);
+      });
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚
    */
   onReady() {
-
+    // 妫�鏌ユ槸鍚︽湁options鍜宲aram
+    if (this.data.options && this.data.options.param) {
+      if (this.data.options.param === "1" || this.data.options.param === "2") {
+        this.getOpenList();
+      }
+    }
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず
    */
   onShow() {
+    console.log('home椤甸潰onShow寮�濮�');
 
+    // 鑾峰彇褰撳墠椤甸潰鐨勫弬鏁�
+    const pages = getCurrentPages();
+    const currentPage = pages[pages.length - 1];
+
+    let fromLogin = false;
+
+    // 妫�鏌ユ槸鍚︽湁fromLogin鍙傛暟
+    if (currentPage && currentPage.options && currentPage.options.fromLogin === 'true') {
+      console.log('onShow: 妫�娴嬪埌fromLogin鍙傛暟锛岃缃甶sFromLogin鏍囪');
+      fromLogin = true;
+      this.setData({
+        isFromLogin: true
+      });
+    }
+
+    // 鍒濆鍖栧鐞�
+    if (fromLogin || this.data.isFromLogin) {
+      console.log('onShow: 浠庣櫥褰曢〉杩斿洖锛屼笉杩涜鐧诲綍妫�鏌�');
+    } else {
+      console.log('onShow: 姝e父鏄剧ず椤甸潰');
+      // 寤惰繜妫�鏌ョ櫥褰曠姸鎬侊紝纭繚鑳芥纭瘑鍒复鏃舵爣璁�
+      setTimeout(() => {
+        this.checkLoginStatusIfNeeded();
+      }, 300);
+    }
+  },
+
+  // 妫�鏌ョ櫥褰曠姸鎬侊紙浠呭湪闇�瑕佹椂锛�
+  checkLoginStatusIfNeeded() {
+    // 鍐嶆纭鏄惁浠庣櫥褰曢〉杩斿洖
+    if (this.getFromLogin()) {
+      console.log('妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝涓嶈繘琛岀櫥褰曟鏌�');
+      return;
+    }
+
+    // 鍐嶆妫�鏌ュ叏灞�鐧诲綍鐘舵��
+    if (getApp().globalData.isLoggedIn) {
+      console.log('妫�娴嬪埌鍏ㄥ眬鐧诲綍鐘舵�侊紝涓嶈繘琛岀櫥褰曟鏌�');
+      return;
+    }
+
+    console.log('鎵ц鐧诲綍鐘舵�佹鏌�');
+    this.checkLoginStatus();
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰闅愯棌
    */
   onHide() {
-
+    // 椤甸潰闅愯棌鏃惰�冭檻娓呯悊涓存椂鏍囪
+    this.cleanupTempMarkers();
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇
    */
   onUnload() {
-
+    // 椤甸潰鍗歌浇鏃舵竻鐞嗕复鏃舵爣璁�
+    this.cleanupTempMarkers();
   },
 
   /**
@@ -222,6 +371,39 @@
       icon: 'none'
     })
   },
+  //瑙g粦鐢ㄦ埛
+  unbind() {
+    if (getApp().globalData.isLoggedIn) {
+      wx.showModal({
+        title: '瑙g粦纭',
+        content: '纭畾瑕佽В缁戝綋鍓嶈处鍙峰悧锛�',
+        success: (res) => {
+          if (res.confirm) {
+            this.unBindPost()
+          }
+        }
+      });
+    } else {
+      wx.showToast({
+        title: '杩樻湭缁戝畾',
+        icon: 'error'
+      })
+    }
+
+  },
+  //杞亴
+  irrigation() {
+    if (getApp().globalData.isLoggedIn) {
+      wx.navigateTo({
+        url: '/pages/irrigation/irrigation',
+      })
+    } else {
+      wx.showToast({
+        title: '璇峰厛鐧诲綍',
+        icon: 'error'
+      })
+    }
+  },
   handleChange(e) {
     const item = e.currentTarget.dataset.item;
     console.log(item);
@@ -261,7 +443,7 @@
       rtuAddr: rtuAddr,
       vcNum: vcNum, //铏氭嫙鍗D
       orderNo: orderNo,
-      operator: app.globalData.operator //鎿嶄綔鍛�
+      operator: app.globalData.clientId //鎿嶄綔鍛�
     };
     console.log("postCloseValaue" + data);
     post({
@@ -298,29 +480,93 @@
    */
   getOpenList() {
     const app = getApp();
+    if (!getApp().globalData.isLoggedIn) {
+      wx.showToast({
+        title: '璇峰厛鐧诲綍',
+        icon: 'error'
+      })
+      this.setData({
+        isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
+        isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
+      });
+      return;
+    }
+    // 妫�鏌ユ槸鍚︿粠鐧诲綍椤佃繑鍥�
+    const fromLogin = this.getFromLogin();
+
+    // 妫�鏌lientId鏄惁瀛樺湪
+    if (!app.globalData.clientId) {
+      console.log('getOpenList: clientId涓嶅瓨鍦紝涓嶆墽琛孉PI璇锋眰');
+
+      // 濡傛灉鏄粠鐧诲綍椤佃繑鍥烇紝灏辨樉绀虹┖鍒楄〃鑰屼笉鏄敊璇彁绀�
+      this.setData({
+        listData: [],
+        isRefreshing: false,
+        isWXRefreshing: false
+      });
+
+      // 濡傛灉涓嶆槸浠庣櫥褰曢〉杩斿洖涓斾笉澶勪簬鍒锋柊鐘舵�侊紝鑰冭檻妫�鏌ョ櫥褰曠姸鎬�
+      if (!fromLogin && !this.data.isRefreshing && !this.data.isWXRefreshing) {
+        console.log('getOpenList: 闈炲埛鏂扮姸鎬佷笅妫�娴嬪埌鏃燾lientId锛屽皾璇曡嚜鍔ㄧ櫥褰�');
+        // 寤惰繜璋冪敤寰俊鐧诲綍锛屽皾璇曡嚜鍔ㄦ仮澶嶄細璇�
+        setTimeout(() => {
+          if (!getApp().globalData.clientId && !this.getFromLogin()) {
+            this.wxLogin();
+          }
+        }, 1000);
+      }
+      return;
+    }
+
+    console.log('getOpenList: 寮�濮嬭幏鍙栧垪琛ㄦ暟鎹�, clientId:', app.globalData.clientId);
+
     const params = {
       url: 'wx/valve/get',
       data: {
-        operator: app.globalData.operator
+        operator: app.globalData.clientId
       }
     };
+
     get(params).then(data => {
+      console.log('鑾峰彇鍒楄〃鏁版嵁鎴愬姛:', data);
       this.setData({
         listData: data.content,
         isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
         isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
-      })
+      });
+
+      // 鎴愬姛鑾峰彇鏁版嵁鍚庡埛鏂癠I楂樺害
+      setTimeout(() => {
+        this.calculateScrollViewHeight();
+      }, 200);
     }).catch(err => {
+      console.error('鑾峰彇鍒楄〃鏁版嵁澶辫触:', err);
       // 閿欒鍥炶皟
       this.setData({
         isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
         isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
-      })
-      wx.showToast({
-        title: err.msg,
-        icon: 'error',
-        duration: 3000
-      })
+      });
+
+      // 妫�鏌ラ敊璇被鍨�
+      if (err && err.code === '0003') {
+        console.log('浼氳瘽鏃犳晥鎴栬繃鏈燂紝浣嗕笉杩涜璺宠浆');
+
+        // 濡傛灉涓嶆槸浠庣櫥褰曢〉杩斿洖锛屾樉绀洪敊璇彁绀�
+        if (!fromLogin) {
+          wx.showToast({
+            title: '鐧诲綍宸茶繃鏈燂紝璇峰埛鏂伴噸璇�',
+            icon: 'none',
+            duration: 3000
+          });
+        }
+      } else {
+        // 涓�鑸敊璇紝鏄剧ず閿欒淇℃伅
+        wx.showToast({
+          title: err.msg || '鑾峰彇鍒楄〃鏁版嵁澶辫触',
+          icon: 'none',
+          duration: 3000
+        });
+      }
     });
   },
   /**
@@ -335,26 +581,65 @@
   },
   //鏍规嵁session鑾峰彇鍐滄埛淇℃伅
   getUserDataBySession() {
+    // 鍏堟鏌ユ槸鍚︿粠鐧诲綍椤佃繑鍥�
+    if (this.getFromLogin()) {
+      console.log('getUserDataBySession: 妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝涓嶆墽琛孉PI璇锋眰');
+      return;
+    }
+
     const app = getApp();
+
+    // 妫�鏌ユ槸鍚︽湁sessionId
+    if (!app.globalData.sessionId) {
+      console.log('getUserDataBySession: sessionId涓嶅瓨鍦紝涓嶆墽琛孉PI璇锋眰');
+      return;
+    }
+
+    console.log('getUserDataBySession: 寮�濮嬭幏鍙栫敤鎴锋暟鎹�, sessionId:', app.globalData.sessionId);
+
     const params = {
       url: 'wx/client/simple_info',
       data: {
         sessionId: app.globalData.sessionId
       }
     };
+
     get(params).then(data => {
+      console.log('鑾峰彇鐢ㄦ埛鏁版嵁鎴愬姛:', data);
       this.setData({
         userName: data.content.clientName,
         userPhone: this.maskPhoneNumber(data.content.phone)
-      })
+      });
     }).catch(err => {
-      // 閿欒鍥炶皟
-      wx.showToast({
-        title: err.msg,
-        icon: 'error',
-        duration: 3000
-      })
-    })
+      console.error('鑾峰彇鐢ㄦ埛鏁版嵁澶辫触:', err);
+      // 閿欒鍥炶皟锛屼絾涓嶈繘琛岄〉闈㈣烦杞�
+
+      // 妫�鏌ラ敊璇被鍨�
+      if (err && err.code === '0003') {
+        console.log('浼氳瘽鏃犳晥鎴栬繃鏈燂紝浣嗕笉杩涜璺宠浆');
+        // 涓嶅啀鐩存帴璺宠浆鍒扮櫥褰曢〉
+
+        // 娓呴櫎浼氳瘽淇℃伅
+        app.globalData.sessionId = '';
+        app.globalData.isLoggedIn = false;
+
+        // 濡傛灉涓嶆槸浠庣櫥褰曢〉杩斿洖锛屾樉绀洪敊璇彁绀�
+        if (!this.getFromLogin()) {
+          wx.showToast({
+            title: '鐧诲綍宸茶繃鏈燂紝璇烽噸鏂扮櫥褰�',
+            icon: 'none',
+            duration: 3000
+          });
+        }
+      } else {
+        // 鍏朵粬閿欒锛屾樉绀洪敊璇俊鎭�
+        // wx.showToast({
+        //   title: err.msg || '鑾峰彇鐢ㄦ埛淇℃伅澶辫触',
+        //   icon: 'none',
+        //   duration: 3000
+        // });
+      }
+    });
   },
   maskPhoneNumber(phoneNumber) {
     if (phoneNumber.length !== 11) {
@@ -421,7 +706,7 @@
     const data = {
       intakeName: intakeName, //鍙栨按鍙D
       // vcId: vcId, //铏氭嫙鍗D
-      operator: app.globalData.operator, //鎿嶄綔鍛�
+      operator: app.globalData.clientId, //鎿嶄綔鍛�
       forceOpen: !!isforce // 浣跨敤閫昏緫闈炴搷浣滅 !! 鏉ョ‘淇� isForce 鏄竷灏斿��  
     };
     post({
@@ -468,32 +753,118 @@
   //杩涘叆鐣岄潰鑾峰彇鐣岄潰鏁版嵁
   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;
+    console.log("initData寮�濮嬶紝tag:", app.globalData.tag);
+
+    // 棣栧厛妫�鏌ユ槸鍚︿粠鐧诲綍椤佃繑鍥�
+    if (this.getFromLogin()) {
+      console.log('initData: 妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝浠呰幏鍙栧熀鏈暟鎹�');
+
+      // 鍗充娇浠庣櫥褰曢〉杩斿洖锛屼篃灏濊瘯鑾峰彇寮�闃�鍒楄〃浠ユ樉绀哄熀鏈琔I
+      // 浣嗗厛妫�鏌ユ槸鍚︽湁瀹㈡埛绔疘D鍙敤
+      if (!app.globalData.clientId) {
+        console.log('initData: 浠庣櫥褰曢〉杩斿洖涓旀棤clientId锛屽皾璇曚粠瀛樺偍鎭㈠');
+        // 灏濊瘯浠庡瓨鍌ㄦ仮澶峜lientId
+        storage.getItemSafe('clientId')
+          .then(clientId => {
+            if (clientId) {
+              console.log('initData: 浠庡瓨鍌ㄦ仮澶峜lientId鎴愬姛:', clientId);
+              app.globalData.clientId = clientId;
+              this.getOpenList();
+            } else {
+              console.log('initData: 鏃犳硶鎭㈠clientId锛屾樉绀虹┖鍒楄〃');
+              this.setData({
+                listData: []
+              });
+            }
+          })
+          .catch(err => {
+            console.error('initData: 鎭㈠clientId澶辫触:', err);
+            this.setData({
+              listData: []
+            });
+          });
+      } else {
+        this.getOpenList();
+      }
+      return;
+    }
+
+    // 灏濊瘯鑾峰彇鐢ㄦ埛鏁版嵁鍜屽凡寮�闃�璁板綍
+    try {
+      // 浼樺厛妫�鏌ュ叏灞�鍙橀噺涓槸鍚︽湁sessionId
+      if (app.globalData.sessionId) {
+        console.log('initData: 浣跨敤鍏ㄥ眬sessionId鑾峰彇鏁版嵁');
         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');
+        return;
+      }
+
+      // 妫�鏌ユ槸鍚︽湁瀛樺偍鐨剈serData
+      const hasUserData = storage.isHasKeySync("userData");
+      console.log('initData: 鏄惁瀛樺湪userData:', hasUserData);
+
+      if (hasUserData) {
+        storage.getItemSafe('userData')
+          .then((data) => {
+            console.log('initData: 鎴愬姛璇诲彇userData');
+            if (data) {
+              try {
+                let jsonObj = JSON.parse(data);
+                app.globalData.sessionId = jsonObj.sessionId;
+                app.globalData.tag = jsonObj.tag;
+                console.log("userData宸插姞杞�:", data);
+              } catch (e) {
+                console.error('userData瑙f瀽澶辫触:', e);
+              }
+            }
+            // 鏃犺濡備綍閮藉皾璇曡幏鍙栫敤鎴蜂俊鎭拰寮�闃�鍒楄〃
+            this.getUserDataBySession();
+            this.getOpenList();
+          })
+          .catch((err) => {
+            console.error('鍔犺浇userData澶辫触:', err);
+
+            // 鍐嶆妫�鏌ユ槸鍚︿粠鐧诲綍椤佃繑鍥�
+            if (this.getFromLogin()) {
+              console.log('initData:catch: 妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝鍙幏鍙栧紑闃�鍒楄〃');
+              this.getOpenList();
+            } else {
+              this.getUserDataBySession();
+              this.getOpenList();
+            }
+          });
+      } else {
+        console.log('鏈壘鍒皍serData锛岀洿鎺ヨ幏鍙栨暟鎹�');
+
+        // 鍐嶆妫�鏌ユ槸鍚︿粠鐧诲綍椤佃繑鍥�
+        if (this.getFromLogin()) {
+          console.log('initData:else: 妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝鍙幏鍙栧紑闃�鍒楄〃');
+          this.getOpenList();
+        } else {
+          this.getUserDataBySession();
+          this.getOpenList();
+        }
+      }
+    } catch (e) {
+      console.error('initData鎵ц鍑洪敊:', e);
+
+      // 鍐嶆妫�鏌ユ槸鍚︿粠鐧诲綍椤佃繑鍥�
+      if (this.getFromLogin()) {
+        console.log('initData:error: 妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝鍙幏鍙栧紑闃�鍒楄〃');
+        this.getOpenList();
+      } else {
+        // 鍑洪敊鏃朵粛灏濊瘯鑾峰彇鏁版嵁
+        this.getUserDataBySession();
+        this.getOpenList();
+      }
     }
-  
   },
   // 澶勭悊澶村儚鐐瑰嚮
   handleAvatarTap() {
     this.setData({
       avatarTapCount: this.data.avatarTapCount + 1
     });
-    
+
     if (this.data.avatarTapCount >= 5) {
       this.setData({
         showProjectDialog: true,
@@ -508,7 +879,9 @@
     if (!e.detail.visible && !this.data.selectedProject) {
       return;
     }
-    this.setData({ showProjectDialog: e.detail.visible });
+    this.setData({
+      showProjectDialog: e.detail.visible
+    });
   },
 
   // 澶勭悊椤圭洰閫夋嫨鍙樺寲
@@ -528,164 +901,520 @@
       });
       return;
     }
-    const projectName = this.data.selectedProject === 'JYG' ? '鍢夊唱鍏抽」鐩�' : '姘戝嫟椤圭洰';
-    
+
+    // 鑾峰彇褰撳墠宸查�夐」鐩拰鏂伴�夋嫨鐨勯」鐩�
+    const currentProject = getApp().globalData.selectedProject;
+    const newProject = this.data.selectedProject;
+    const projectName = newProject === 'JYG' ? '鍢夊唱鍏抽」鐩�' :
+      newProject === 'MQ' ? '姘戝嫟椤圭洰' :
+      newProject === 'TEST' ? '娴嬭瘯椤圭洰' : '鏈煡椤圭洰';
+
+    // 妫�鏌ユ槸鍚﹀垏鎹簡椤圭洰锛堝鏋滃綋鍓嶉」鐩笉鍚屼簬鏂伴�夋嫨鐨勯」鐩級
+    const isProjectChanged = currentProject && currentProject !== newProject;
+
+    // 濡傛灉鍒囨崲浜嗛」鐩紝鍏堟竻闄ょ櫥褰曠姸鎬�
+    if (isProjectChanged) {
+      console.log(`姝e湪浠庨」鐩� ${currentProject} 鍒囨崲鍒� ${newProject}锛屽皢娓呴櫎鐧诲綍鐘舵�乣);
+
+      // 娓呴櫎鍏ㄥ眬鐧诲綍鐘舵��
+      getApp().globalData.sessionId = '';
+      getApp().globalData.clientId = '';
+      getApp().globalData.isLoggedIn = false;
+      getApp().globalData.userInfo = null;
+
+      // 娓呴櫎瀛樺偍涓殑鐧诲綍鐘舵��
+      try {
+        wx.removeStorageSync('sessionId');
+        wx.removeStorageSync('clientId');
+        wx.removeStorageSync('userData');
+        wx.removeStorageSync('isLoggedIn');
+        console.log('宸叉竻闄ょ櫥褰曠浉鍏崇殑瀛樺偍鏁版嵁');
+      } catch (e) {
+        console.error('娓呴櫎瀛樺偍鏁版嵁澶辫触:', e);
+      }
+
+      // 閲嶇疆UI鏄剧ず鐘舵��
+      this.setData({
+        userName: "璇风櫥褰�",
+        userPhone: "",
+        listData: []
+      });
+    }
+
     // 淇濆瓨椤圭洰閫夋嫨鍒版湰鍦板瓨鍌�
-    storage.setItem('selectedProject', this.data.selectedProject).then(() => {
+    storage.setItem('selectedProject', newProject).then(() => {
       // 鏇存柊 BASEURL
-      const { PROJECT_URLS } = require('../../api/config.js');
-      const baseUrl = PROJECT_URLS[this.data.selectedProject];
-      
-      // 鐩存帴淇敼鍏ㄥ眬鍙橀噺
+      const {
+        PROJECT_URLS
+      } = require('../../api/config.js');
+      const baseUrl = PROJECT_URLS[newProject];
+
+      // 鏇存柊鍏ㄥ眬鍙橀噺
       getApp().globalData = getApp().globalData || {};
       getApp().globalData.baseUrl = baseUrl;
-      getApp().globalData.selectedProject = this.data.selectedProject;
-      
-      // 鏍规嵁椤圭洰璁剧疆瀵瑰簲鐨則ag
-      if (this.data.selectedProject === 'JYG') {
+      getApp().globalData.selectedProject = newProject;
+
+      // 鏍规嵁椤圭洰璁剧疆瀵瑰簲鐨則ag鍜宑lientId
+      if (newProject === 'JYG') {
         getApp().globalData.tag = 'ym'; // 鍢夊唱鍏抽」鐩搴攖ag涓簓m
-      } else if (this.data.selectedProject === 'MQ') {
+        this.setData({
+          userName: "鍢夊唱鍏抽」鐩�"
+        });
+      } else if (newProject === 'MQ') {
         getApp().globalData.tag = 'mq'; // 姘戝嫟椤圭洰瀵瑰簲tag涓簃q
+        getApp().globalData.operator = '2025033115305200006';
+        getApp().globalData.clientId = '2025033115305200006';
+        getApp().globalData.isLoggedIn = true;
+        getApp().globalData.sessionId = '2025033115305200006';
+        this.setData({
+          userName: "姘戝嫟椤圭洰"
+        });
+        // 鎸佷箙鍖栧瓨鍌ㄦ皯鍕ら」鐩弬鏁�
+        storage.setItem('MQ_params', {
+          operator: '2025033115305200006',
+          clientId: '2025033115305200006',
+          isLoggedIn: true,
+          sessionId: '2025033115305200006'
+        });
+      } else if (newProject === 'TEST') {
+        getApp().globalData.tag = 'ym'; // 娴嬭瘯椤圭洰瀵瑰簲tag涓簍est
+        getApp().globalData.operator = '2025032411245000006';
+        getApp().globalData.clientId = '2025032411245000006';
+        getApp().globalData.isLoggedIn = true;
+        getApp().globalData.sessionId = '2025032411245000006';
+        getApp().globalData.vcId = '2024122617295800009';
+        this.setData({
+          userName: "娴嬭瘯椤圭洰"
+        });
+        // 鎸佷箙鍖栧瓨鍌ㄦ祴璇曢」鐩弬鏁�
+        storage.setItem('TEST_params', {
+          operator: '2025032411245000006',
+          clientId: '2025032411245000006',
+          isLoggedIn: true,
+          sessionId: '2025032411245000006',
+          vcId: '2024122617295800009'
+        });
       }
-      
+
       console.log('宸插垏鎹㈠埌椤圭洰:', projectName, '鍩熷悕:', baseUrl, 'tag:', getApp().globalData.tag);
-      
+
       this.setData({
         showProjectDialog: false
       });
 
+      // 鏄剧ず鍒囨崲鎴愬姛鎻愮ず
       wx.showToast({
         title: `宸查�夋嫨${projectName}`,
         icon: 'success',
         duration: 2000
       });
+      setTimeout(() => {
+        console.log('椤圭洰宸插垏鎹紝姝e湪鍒濆鍖栨暟鎹�');
+        this.initData();
+      }, 1000);
 
-      // 妫�鏌ョ櫥褰曠姸鎬�
-      // setTimeout(() => {
-      //   this.checkLoginStatus();
-      // }, 500);
     }).catch(err => {
       console.error('淇濆瓨椤圭洰閫夋嫨澶辫触锛�', err);
       wx.showToast({
         title: '淇濆瓨澶辫触锛岃閲嶈瘯',
-        icon: 'success',
+        icon: 'none',
         duration: 2000
       });
     });
   },
-  
+
   // 妫�鏌ョ櫥褰曠姸鎬�
   checkLoginStatus() {
     const app = getApp();
-    
+
     // 妫�鏌ユ槸鍚﹀凡鐧诲綍
     if (app.globalData.isLoggedIn && app.globalData.sessionId) {
-      // 宸茬櫥褰曪紝閲嶆柊鍔犺浇椤甸潰
-      wx.reLaunch({
-        url: '/pages/home/home'
+      console.log('宸蹭粠鍏ㄥ眬鍙橀噺妫�娴嬪埌鐧诲綍鐘舵��');
+      return;
+    }
+
+    // 妫�鏌ユ湰椤甸潰鏄惁姝e湪澶勭悊杩斿洖閫昏緫
+    const fromLogin = this.getFromLogin();
+    if (fromLogin) {
+      console.log('浠庣櫥褰曢〉杩斿洖锛屼笉鍐嶉噸瀹氬悜');
+      return;
+    }
+
+    // 鑾峰彇褰撳墠椤甸潰璺敱鍜屽弬鏁�
+    const pages = getCurrentPages();
+    const currentPage = pages[pages.length - 1];
+    const currentRoute = currentPage ? currentPage.route : '';
+    const currentOptions = currentPage ? currentPage.options || {} : {};
+
+    console.log('褰撳墠椤甸潰璺敱:', currentRoute, '鍙傛暟:', currentOptions);
+
+    // 妫�鏌RL鍙傛暟涓槸鍚︽湁fromLogin
+    if (currentOptions.fromLogin === 'true') {
+      console.log('URL鍙傛暟涓娴嬪埌fromLogin=true锛屼笉鎵ц璺宠浆');
+      this.setData({
+        isFromLogin: true
       });
-    } else {
-      // 灏濊瘯浠庢湰鍦板瓨鍌ㄨ幏鍙栫敤鎴蜂俊鎭�
-      storage.getItem('userInfo').then(userInfoStr => {
-        if (userInfoStr) {
+      return;
+    }
+
+    // 濡傛灉褰撳墠宸插湪鐧诲綍椤碉紝涓嶅啀璺宠浆
+    if (currentRoute === 'pages/login/login') {
+      console.log('褰撳墠宸插湪鐧诲綍椤碉紝涓嶅啀璺宠浆');
+      return;
+    }
+
+    // Promise閾惧鐞嗗瓨鍌ㄦ鏌�
+    Promise.all([
+        storage.getItemSafe('sessionId'),
+        storage.getItemSafe('clientId'),
+        storage.getItemSafe('isLoggedIn')
+      ])
+      .then(([sessionId, clientId, isLoggedIn]) => {
+        if (sessionId) {
+          // 浠庡瓨鍌ㄤ腑鎭㈠鐧诲綍鐘舵��
+          app.globalData.sessionId = sessionId;
+          app.globalData.isLoggedIn = true;
+
+          if (clientId) {
+            app.globalData.clientId = clientId;
+          }
+
+          console.log('宸蹭粠瀛樺偍鎭㈠鐧诲綍鐘舵��');
+          // 宸茬櫥褰曪紝鍒锋柊椤甸潰
+          wx.reLaunch({
+            url: '/pages/home/home'
+          });
+        } else {
+          // 鏍囪褰撳墠椤甸潰姝e湪澶勭悊杩斿洖閫昏緫
+          this.setData({
+            isFromLogin: true
+          });
+
+          // 鏈櫥褰曪紝鍙兘闇�瑕佽烦杞埌鐧诲綍椤甸潰
+          console.log('鏈娴嬪埌鐧诲綍鐘舵�侊紝鍙兘闇�瑕佽烦杞埌鐧诲綍椤�');
+
+          // 鏈�鍚庡啀妫�鏌ヤ竴娆℃槸鍚﹀凡浠庣櫥褰曢〉杩斿洖
+          const finalCheck = this.getFromLogin();
+          if (finalCheck) {
+            console.log('鏈�缁堟鏌�: 宸蹭粠鐧诲綍椤佃繑鍥烇紝涓嶅啀璺宠浆');
+            return;
+          }
+
+          console.log('纭闇�瑕佽烦杞埌鐧诲綍椤�');
+
+          // 璺宠浆鍓嶅啀娆℃鏌ョ櫥褰曢〉闈复鏃舵爣璁�
           try {
-            const userInfo = JSON.parse(userInfoStr);
-            // 楠岃瘉鐢ㄦ埛淇℃伅鏄惁鏈夋晥
-            if (userInfo && userInfo.sessionId) {
-              // 鎭㈠鐧诲綍鐘舵��
-              app.globalData.sessionId = userInfo.sessionId;
-              app.globalData.token = userInfo.token;
-              app.globalData.userInfo = userInfo;
-              app.globalData.isLoggedIn = true;
-              
-              // 宸茬櫥褰曪紝閲嶆柊鍔犺浇椤甸潰
-              wx.reLaunch({
-                url: '/pages/home/home'
-              });
-              return;
-            }
-          } catch (e) {
-            console.error('瑙f瀽鐢ㄦ埛淇℃伅澶辫触:', e);
-          }
+            wx.setStorageSync('_attempted_login_redirect', 'true');
+          } catch (e) {}
+
+          // wx.navigateTo({
+          //   url: `/pages/login/login?project=${this.data.selectedProject}`,
+          //   success: () => console.log('鎴愬姛璺宠浆鍒扮櫥褰曢〉'),
+          //   fail: (err) => console.error('璺宠浆鍒扮櫥褰曢〉澶辫触:', err)
+          // });
         }
-        
-        // 鏈櫥褰曪紝璺宠浆鍒扮櫥褰曢〉闈�
-        wx.redirectTo({
-          url: `/pages/login/login?project=${this.data.selectedProject}`
+      })
+      .catch(err => {
+        console.error('妫�鏌ョ櫥褰曠姸鎬佹椂鍑洪敊:', err);
+
+        // 鏍囪褰撳墠椤甸潰姝e湪澶勭悊杩斿洖閫昏緫
+        this.setData({
+          isFromLogin: true
         });
-      }).catch(err => {
-        console.error('鑾峰彇鐢ㄦ埛淇℃伅澶辫触:', err);
-        // 鏈櫥褰曪紝璺宠浆鍒扮櫥褰曢〉闈�
-        wx.redirectTo({
-          url: `/pages/login/login?project=${this.data.selectedProject}`
-        });
+
+        // 鍐嶆妫�鏌ユ槸鍚﹀凡浠庣櫥褰曢〉杩斿洖
+        if (this.getFromLogin()) {
+          console.log('閿欒澶勭悊: 宸蹭粠鐧诲綍椤佃繑鍥烇紝涓嶅啀璺宠浆');
+          return;
+        }
+
+        // 鍑洪敊鏃朵篃璺宠浆鍒扮櫥褰曢〉
+        // wx.navigateTo({
+        //   url: `/pages/login/login?project=${this.data.selectedProject}`,
+        //   success: () => console.log('閿欒鍚庢垚鍔熻烦杞埌鐧诲綍椤�'),
+        //   fail: (err) => console.error('閿欒鍚庤烦杞埌鐧诲綍椤靛け璐�:', err)
+        // });
+      });
+  },
+
+  // 杈呭姪鍑芥暟锛氭鏌ユ槸鍚︿粠鐧诲綍椤佃繑鍥�
+  getFromLogin() {
+    // 妫�鏌ュ綋鍓嶉〉闈㈢殑options
+    const pages = getCurrentPages();
+    const currentPage = pages[pages.length - 1];
+    if (currentPage && currentPage.options && currentPage.options.fromLogin === 'true') {
+      console.log('getFromLogin: 妫�娴嬪埌URL鍙傛暟fromLogin=true');
+      // 璁剧疆鏍囧織锛岀‘淇濅笅娆℃鏌ユ椂鑳借瘑鍒�
+      this.setData({
+        isFromLogin: true
+      });
+      return true;
+    }
+    console.log('getFromLogin: 鏈娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁�');
+    return false;
+  },
+
+  // 缁х画鍒濆鍖栭〉闈�
+  continueInitPage(options) {
+    console.log('缁х画鍒濆鍖栭〉闈紝options:', options);
+
+    // 妫�鏌ユ槸鍚︿粠鐧诲綍椤佃繑鍥�
+    let fromLogin = false;
+
+    // 浠嶶RL鍙傛暟涓鏌�
+    if (options && options.fromLogin === 'true') {
+      console.log('continueInitPage: 浠嶶RL鍙傛暟妫�娴嬪埌fromLogin=true');
+      fromLogin = true;
+      this.setData({
+        isFromLogin: true
       });
     }
+
+    // 浠庨〉闈㈡暟鎹腑妫�鏌�
+    if (this.data.isFromLogin) {
+      console.log('continueInitPage: 浠庨〉闈㈡暟鎹腑妫�娴嬪埌isFromLogin=true');
+      fromLogin = true;
+    }
+
+    // 鍒ゆ柇鏈湴鏄惁淇濆瓨sessionId
+    // 浣跨敤 wx.nextTick 绛夊緟椤甸潰娓叉煋瀹屾垚
+    wx.nextTick(() => {
+      this.calculateScrollViewHeight();
+    });
+
+    // 褰撳紑闃�鎴愬姛鍚庤皟鐢ㄥ埛鏂�
+    if (options && options.param) {
+      console.log("寮�闃�鎴愬姛鍙傛暟:", options.param);
+      wx.showToast({
+        title: '寮�闃�鎴愬姛',
+        icon: 'success',
+        duration: 3000
+      });
+      this.getOpenList();
+    }
+
+    // 鍒濆鍖栨暟鎹�
+    this.initData();
+
+    // 濡傛灉涓嶆槸浠庣櫥褰曢〉杩斿洖锛屽垯璁剧疆寤惰繜妫�鏌ョ櫥褰曠姸鎬�
+    if (!fromLogin) {
+      console.log('涓嶆槸浠庣櫥褰曢〉杩斿洖锛屽欢杩熸鏌ョ櫥褰曠姸鎬�');
+      setTimeout(() => {
+        // 浠呭湪鏈櫥褰曚笖涓嶆槸浠庣櫥褰曢〉杩斿洖鏃舵鏌ョ櫥褰曠姸鎬�
+        if (!getApp().globalData.isLoggedIn) {
+          console.log('寤惰繜妫�鏌ワ細鏈櫥褰曚笖涓嶆槸浠庣櫥褰曢〉杩斿洖锛屾墽琛岀櫥褰曠姸鎬佹鏌�');
+          this.checkLoginStatus();
+        }
+      }, 500);
+    } else {
+      console.log('浠庣櫥褰曢〉杩斿洖锛屼笉妫�鏌ョ櫥褰曠姸鎬�');
+    }
   },
-  wxLogin(){
-    if(!getApp().globalData.isLoggedIn){
-      const that = this;
+
+  // 寰俊鐧诲綍
+  wxLogin() {
+    if (!getApp().globalData.isLoggedIn) {
+      wx.showLoading({
+        title: '姝e湪鐧诲綍璇风◢鍊�...',
+        mask: true
+      });
+
       wx.login({
-        success: function (res) {
+        success: (res) => {
           if (res.code) {
-            var code = res.code;
-            console.log(code);
             // 灏哻ode鍙戦�佸埌鏈嶅姟鍣ㄨ幏鍙杘penid
-            that.codeLogin(code);
+            post({
+              url: "wx/client/code_login",
+              data: {
+                code: res.code
+              }
+            }).then(response => {
+              wx.hideLoading();
+              if (response.code === "0001") {
+                if (response.content.client.clientId === "") {
+                  // 鏈粦瀹氳处鍙凤紝璺宠浆鍒扮櫥褰曢〉闈�
+                  // wx.navigateTo({
+                  //   url: `/pages/login/login?project=${this.data.selectedProject}`
+                  // });
+                } else {
+                  this.setData({
+                    userName: response.content.client.clientName,
+                    userPhone: response.content.client.userPhone
+                  })
+                  // 宸叉湁璐﹀彿锛屼繚瀛樻暟鎹苟鍒濆鍖�
+                  const sessionId = response.content.client.sessionId;
+                  const clientId = response.content.client.clientId;
+
+                  // 璁剧疆鍏ㄥ眬鍙橀噺
+                  getApp().globalData.sessionId = sessionId;
+                  getApp().globalData.clientId = clientId;
+                  getApp().globalData.isLoggedIn = true;
+
+                  // 璁剧疆姝g‘鐨勯」鐩畉ag
+                  const tag = this.data.selectedProject === 'JYG' ? 'ym' : 'mq';
+                  getApp().globalData.tag = tag;
+
+                  // 淇濆瓨鍒板瓨鍌�
+                  storage.setItem("sessionId", sessionId);
+                  storage.setItem("clientId", clientId);
+                  storage.setItem("isLoggedIn", "true");
+
+                  // 淇濆瓨userData淇℃伅锛屽寘鍚玸essionId鍜宼ag
+                  const userData = JSON.stringify({
+                    sessionId: sessionId,
+                    tag: tag,
+                    project: this.data.selectedProject,
+                    userName: response.content.client.clientName,
+                    userPhone: response.content.client.userPhone
+                  });
+                  storage.setItem("userData", userData)
+                    .then(() => {
+                      console.log('鐢ㄦ埛鏁版嵁淇濆瓨鎴愬姛锛屽寘鍚」鐩俊鎭�:', this.data.selectedProject, 'tag:', tag);
+                      this.initData();
+                    })
+                    .catch(err => {
+                      console.warn('淇濆瓨userData澶辫触锛屼絾缁х画鍒濆鍖�:', err);
+                      this.initData();
+                    });
+
+                }
+              } else {
+                wx.showToast({
+                  title: '鐧诲綍澶辫触',
+                  icon: 'error',
+                  duration: 2000
+                });
+                // wx.navigateTo({
+                //   url: `/pages/login/login?project=${this.data.selectedProject}`
+                // });
+              }
+            }).catch(error => {
+              wx.hideLoading();
+              console.error('鐧诲綍璇锋眰澶辫触:', error);
+              wx.showToast({
+                title: '鐧诲綍澶辫触锛岃閲嶈瘯',
+                icon: 'none'
+              });
+              // wx.redirectTo({
+              //   url: `/pages/login/login?project=${this.data.selectedProject}`
+              // });
+            });
           } else {
+            wx.hideLoading();
             console.log('鐧诲綍澶辫触锛�' + res.errMsg);
-        
+            wx.showToast({
+              title: '寰俊鐧诲綍澶辫触',
+              icon: 'none'
+            });
           }
+        },
+        fail: (err) => {
+          wx.hideLoading();
+          console.error('寰俊鐧诲綍API璋冪敤澶辫触:', err);
+          wx.showToast({
+            title: '鐧诲綍澶辫触锛岃閲嶈瘯',
+            icon: 'none'
+          });
         }
       });
     }
   },
-  //寰俊code鐧诲綍
-  codeLogin(codeData) {
+
+  // 杈呭姪鍑芥暟锛氭竻鐞嗕复鏃舵爣璁�
+  cleanupTempMarkers() {
+    // 鍙湁鍦╥sFromLogin涓簍rue鏃舵墠杩涜娓呯悊
+    if (this.data.isFromLogin) {
+
+
+      // 閲嶈isFromLogin涓篺alse锛屼絾娣诲姞寤惰繜锛岄伩鍏嶅奖鍝嶅綋鍓嶉〉闈㈢殑杩斿洖閫昏緫
+      setTimeout(() => {
+        this.setData({
+          isFromLogin: false
+        });
+        console.log('閲嶇疆isFromLogin=false');
+      }, 5000);
+    }
+  }, //纭瑙g粦
+  unBindPost() {
+    this.setData({
+      showUnBind: false
+    })
     wx.showLoading({
-      title: '姝e湪鐧诲綍璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧
+      title: '姝e湪瑙g粦璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧
       mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false
     });
     const data = {
-      code: codeData, //涓存椂鐧诲綍鍑瘉
+      sessionId: getApp().globalData.sessionId //鍙栨按鍙D
     };
     post({
-      url: "wx/client/code_login",
+      url: 'wx/client/unbind',
       data: data,
+      useParams: true
     }).then(response => {
       // 澶勭悊鎴愬姛鍝嶅簲
       console.log('璇锋眰鎴愬姛:', response);
       // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
       wx.hideLoading();
-      if (response.code === "0001") {
-        //鍋囧涓虹┖鍒欒烦杞埌缁戝畾鐣岄潰
-        if (response.content.client.clientId === "") {
-          wx.navigateTo({
-            url: '/pages/login/login'
-          })
-        } else {
-          //缂撳瓨鍦ㄦ湰鍦�
+      const app = getApp();
+
+      // 娓呴櫎鍏ㄥ眬鐧诲綍鐘舵��
+      app.globalData.sessionId = '';
+      app.globalData.clientId = '';
+      app.globalData.isLoggedIn = false;
+      app.globalData.userInfo = null;
+
+      // 娓呴櫎瀛樺偍涓殑鐧诲綍鐘舵��
+      const storage = require('../../utils/storage.js');
+      storage.removeItem('sessionId')
+        .then(() => storage.removeItem('clientId'))
+        .then(() => storage.removeItem('userData'))
+        .then(() => storage.removeItem('isLoggedIn'))
+        .then(() => {
+          wx.showToast({
+            title: '瑙g粦鎴愬姛',
+            icon: 'success',
+            duration: 2000
+          });
+
+          // 閲嶇疆UI鏄剧ず鐘舵��
           this.setData({
-            isLogin: true
-          })
-          getApp().globalData.sessionId = response.content.client.sessionId
-          storage.setItem("sessionId", response.content.client.sessionId)
-          getApp().globalData.clientId = response.content.client.clientId
-          storage.setItem("clientId", response.content.client.clientId)
-          this.initData();
-        }
-      } else {
-        wx.showToast({
-          title: 'title',
-          icon: 'error',
-          duration: 2000
+            userName: "璇风偣鍑荤櫥褰�",
+            userPhone: "",
+            listData: []
+          });
         })
-      }
+        .catch(err => {
+          console.error('瑙g粦杩囩▼涓嚭閿�:', err);
+          wx.showToast({
+            title: '瑙g粦澶辫触锛岃閲嶈瘯',
+            icon: 'none',
+            duration: 2000
+          });
+        });
     }).catch(error => {
       // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
       wx.hideLoading();
       // 澶勭悊閿欒鍝嶅簲
       console.error('璇锋眰澶辫触:', error);
+      wx.showToast({
+        title: '瑙g粦澶辫触',
+        icon: 'error',
+        duration: 3000
+      })
     });
   },
+  onShareAppMessage: function (options) {
+    // 璁剧疆鍒嗕韩鍐呭
+    return {
+      title: '澶х鐏屾簤鍔╂墜', // 鍒嗕韩鏍囬
+      path: '/pages/home/home', // 鍒嗕韩璺緞锛岃璺緞闇�瑕佹槸褰撳墠灏忕▼搴忓瓨鍦ㄧ殑椤甸潰璺緞
+      imageUrl: '/images/logo2.jpg', // 鍒嗕韩鍥炬爣锛屽彲浠ユ槸缃戠粶鍥剧墖璺緞鎴栨湰鍦板浘鐗囪矾寰�
+      success: function (res) {
+        // 鍒嗕韩鎴愬姛鐨勫洖璋冨嚱鏁�
+      },
+      fail: function (res) {
+        // 鍒嗕韩澶辫触鐨勫洖璋冨嚱鏁�
+      }
+    };
+  }
 })
\ No newline at end of file

--
Gitblit v1.8.0