From 6ae0924bdb44e8b1f569b6f1cdb6ff403e1d2ce3 Mon Sep 17 00:00:00 2001 From: zuoxiao <zuoxiao> Date: 星期一, 28 四月 2025 10:15:33 +0800 Subject: [PATCH] 优化首页和灌溉页面的样式,添加当前项目显示;重构项目配置,确保项目登录需求一致性;更新登录页面逻辑,简化项目选择和信息展示,提升用户体验。 --- pages/irrigation/irrigation.js | 6 pages/home/home.js | 3227 ++++++++++++++++++++++++++++--------------------------- pages/login/login.js | 77 - pages/login/login.wxml | 2 pages/waterIntake/waterIntake.js | 4 pages/home/home.wxml | 8 utils/projectConfig.js | 55 pages/home/home.wxss | 41 8 files changed, 1,711 insertions(+), 1,709 deletions(-) diff --git a/pages/home/home.js b/pages/home/home.js index 9f9c353..a997e2b 100644 --- a/pages/home/home.js +++ b/pages/home/home.js @@ -1,1620 +1,1675 @@ // pages/home/home.js const storage = require('../../utils/storage.js'); const { - get, - post + get, + post } = require('../../api/request.js'); const config = require('../../api/config.js'); const { - PROJECT_CONFIG + PROJECT_CONFIG } = require('../../utils/projectConfig.js'); const { - ENV + ENV } = require('../../api/env.js'); Page({ - /** - * 椤甸潰鐨勫垵濮嬫暟鎹� - */ - data: { - sessionId: "", - showConfirm: false, - myItem: {}, - waterIntakeName: "", - image: "/images/ic_head_bg.jpg", - userPhone: "", - userName: "璇风偣鍑荤櫥褰�", - scrollViewHeight: 0, - listData: [], - isRefreshing: false, - isWXRefreshing: false, - errorData: '', //閿欒鍐呭 - showErrorDialog: false, - confirmBtn: { - content: '纭' - }, - errorDialogTitle: "鍏抽榾閿欒", - showForceConfirm: false, //鏄惁寮哄埗寮�闃� - lastIntakeName: "", - showProjectDialog: false, - selectedProject: '', - avatarTapCount: 0, - isFromLogin: false, - showTipDialog: '', - projectConfig: PROJECT_CONFIG, // 娣诲姞椤圭洰閰嶇疆鍒癲ata涓� - showInfoDialog: false, - projectList: [] + /** + * 椤甸潰鐨勫垵濮嬫暟鎹� + */ + data: { + sessionId: "", + showConfirm: false, + myItem: {}, + waterIntakeName: "", + image: "/images/ic_head_bg.jpg", + userPhone: "", + userName: "璇风偣鍑荤櫥褰�", + scrollViewHeight: 0, + listData: [], + isRefreshing: false, + isWXRefreshing: false, + errorData: '', //閿欒鍐呭 + showErrorDialog: false, + confirmBtn: { + content: '纭' }, + errorDialogTitle: "鍏抽榾閿欒", + showForceConfirm: false, //鏄惁寮哄埗寮�闃� + lastIntakeName: "", + showProjectDialog: false, + selectedProject: '', + avatarTapCount: 0, + isFromLogin: false, + showTipDialog: '', + projectConfig: PROJECT_CONFIG, // 娣诲姞椤圭洰閰嶇疆鍒癲ata涓� + showInfoDialog: false, + projectList: [] + }, - openValve: function (e) { - 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) => { - // let totalHeight = rects.reduce((sum, rect) => sum + rect.height, 0); - // this.setData({ - // scrollViewHeight: totalHeight, - // }); - // }).exec(); - // }, - startPullDownRefresh() { - 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' - }) - } + openValve: function (e) { + 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) => { + // let totalHeight = rects.reduce((sum, rect) => sum + rect.height, 0); + // this.setData({ + // scrollViewHeight: totalHeight, + // }); + // }).exec(); + // }, + startPullDownRefresh() { + 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' + }) + } - }, + }, - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 - */ - onLoad(options) { - console.log('home椤甸潰onLoad寮�濮嬶紝鍙傛暟:', options); - - // 鍒濆鍖栭」鐩垪琛ㄦ暟鎹� - this.initProjectList(); - - //褰撳紑闃�鎴愬姛鍚庤皟鐢ㄥ埛鏂� - if (options.param === "1" || options.param === "2") { - this.setData({ - 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(options) { + console.log('home椤甸潰onLoad寮�濮嬶紝鍙傛暟:', options); // 鍒濆鍖栭」鐩垪琛ㄦ暟鎹� - initProjectList() { - // 灏哖ROJECT_CONFIG瀵硅薄杞崲涓烘暟缁勶紝鏂逛究鍦ㄨ鍥句腑閬嶅巻 - const projectList = Object.entries(PROJECT_CONFIG).map(([key, config]) => ({ - key: key, // 浣跨敤key浣滀负椤圭洰鏍囪瘑(JYG銆丮Q绛�) - tag: config.tag, // 淇濈暀tag瀛楁锛堝師閰嶇疆涓凡鏈夌殑鏍囪瘑锛屽ym銆乵q绛夛級 - displayName: config.displayName, // 鏄剧ず鍚嶇О - ...config // 鍏朵粬閰嶇疆灞炴�� - })); - - // 鑾峰彇褰撳墠宸查�夋嫨鐨勯」鐩紝榛樿涓篔YG - let currentSelectedProject = 'JYG'; - - // 灏濊瘯浠庡叏灞�鍙橀噺鑾峰彇 - const app = getApp(); - if (app && app.globalData && app.globalData.selectedProject) { - currentSelectedProject = app.globalData.selectedProject; - } else { - // 灏濊瘯浠庢湰鍦板瓨鍌ㄨ幏鍙� - try { - const savedProject = wx.getStorageSync('selectedProject'); - if (savedProject) { - currentSelectedProject = savedProject; - } - } catch (e) { - console.error('浠庢湰鍦板瓨鍌ㄨ幏鍙栭」鐩け璐�:', e); - } + this.initProjectList(); + + //褰撳紑闃�鎴愬姛鍚庤皟鐢ㄥ埛鏂� + if (options.param === "1" || options.param === "2") { + this.setData({ + 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); + }, + + // 鍒濆鍖栭」鐩垪琛ㄦ暟鎹� + initProjectList() { + // 灏哖ROJECT_CONFIG瀵硅薄杞崲涓烘暟缁勶紝鏂逛究鍦ㄨ鍥句腑閬嶅巻 + const projectList = Object.entries(PROJECT_CONFIG).map(([key, config]) => ({ + key: key, // 浣跨敤key浣滀负椤圭洰鏍囪瘑(JYG銆丮Q绛�) + tag: config.tag, // 淇濈暀tag瀛楁锛堝師閰嶇疆涓凡鏈夌殑鏍囪瘑锛屽ym銆乵q绛夛級 + displayName: config.displayName, // 鏄剧ず鍚嶇О + ...config // 鍏朵粬閰嶇疆灞炴�� + })); + + // 鑾峰彇褰撳墠宸查�夋嫨鐨勯」鐩紝榛樿涓篔YG + let currentSelectedProject = 'JYG'; + + // 灏濊瘯浠庡叏灞�鍙橀噺鑾峰彇 + const app = getApp(); + if (app && app.globalData && app.globalData.selectedProject) { + currentSelectedProject = app.globalData.selectedProject; + } else { + // 灏濊瘯浠庢湰鍦板瓨鍌ㄨ幏鍙� + try { + const savedProject = wx.getStorageSync('selectedProject'); + if (savedProject) { + currentSelectedProject = savedProject; } - - // 璁剧疆鍒伴〉闈㈡暟鎹腑 - this.setData({ - projectList, - selectedProject: currentSelectedProject - }); - - console.log('椤圭洰鍒楄〃宸插垵濮嬪寲:', projectList, '褰撳墠閫変腑椤圭洰:', currentSelectedProject); - }, - - // 鏂板鐨勫垵濮嬪寲椤甸潰杈呭姪鍑芥暟锛屽垎绂诲嚭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 serverUrl = PROJECT_CONFIG[project]?.serverUrl; - if (serverUrl) { - getApp().globalData.baseUrl = serverUrl; - getApp().globalData.selectedProject = project; - console.log('璁剧疆baseUrl:', serverUrl); - } - - // 鏍规嵁椤圭洰璁剧疆瀵瑰簲鐨則ag - const projectConfig = PROJECT_CONFIG[project]; - if (projectConfig) { - getApp().globalData.tag = projectConfig.tag; - this.setData({ - userName: projectConfig.displayName - }); - } - - // 鏍规嵁椤圭洰璁剧疆瀵瑰簲鐨刼perator鍜宑lientId - if (projectConfig && projectConfig.operatorId) { - getApp().globalData.operator = projectConfig.operatorId; - getApp().globalData.clientId = projectConfig.operatorId; - getApp().globalData.isLoggedIn = true; - getApp().globalData.sessionId = projectConfig.operatorId; - - // 濡傛灉鏈塿cId锛屼篃璁剧疆 - if (projectConfig.vcId) { - getApp().globalData.vcId = projectConfig.vcId; - } - - // 鎸佷箙鍖栧瓨鍌ㄩ」鐩弬鏁� - const params = { - operator: projectConfig.operatorId, - clientId: projectConfig.operatorId, - isLoggedIn: true, - sessionId: projectConfig.operatorId - }; - - if (projectConfig.vcId) { - params.vcId = projectConfig.vcId; - } - - storage.setItem(`${project}_params`, params); - } - - // 缁х画鍒濆鍖栭〉闈� - 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) { - 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; - } - - console.log('鎵ц鐧诲綍鐘舵�佹鏌�'); - this.checkLoginStatus(); - }, - - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰闅愯棌 - */ - onHide() { - // 椤甸潰闅愯棌鏃惰�冭檻娓呯悊涓存椂鏍囪 - this.cleanupTempMarkers(); - }, - - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇 - */ - onUnload() { - // 椤甸潰鍗歌浇鏃舵竻鐞嗕复鏃舵爣璁� - this.cleanupTempMarkers(); - }, - - /** - * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 - */ - onPullDownRefresh() { - // 涓嬫媺鍒锋柊瑙﹀彂鐨勯�昏緫锛屽彲浠ユ槸璇锋眰鏁版嵁绛夋搷浣� - // 渚嬪锛岃姹傛暟鎹悗鏇存柊椤甸潰鍐呭 - console.log(this.data.isRefreshing); - this.setData({ - isWXRefreshing: true - }); - console.log(this.data.isRefreshing); - // 鏁版嵁璇锋眰瀹屾垚鍚庯紝鍋滄涓嬫媺鍒锋柊鐨勫姩鐢� - this.getOpenList(); - }, - - /** - * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁� - */ - onReachBottom() { - - }, - - /** - * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜� - */ - onShareAppMessage() { - - }, - recharge() { - // wx.navigateTo({ - // url: '/pages/rechargeCard/rechargeCard', - // }) - wx.showToast({ - title: '鏆傛湭寮�鏀�', - icon: 'none' - }) - }, - openValveList() { - const app = getApp(); - if (app.globalData.isLoggedIn) { - wx.navigateTo({ - url: '/pages/valveList/valveList', - }) - } else { - wx.showToast({ - title: '璇峰厛鐧诲綍', - icon: 'error' - }) + } catch (e) { + console.error('浠庢湰鍦板瓨鍌ㄨ幏鍙栭」鐩け璐�:', e); } - }, - feedBack() { + } + + // 璁剧疆鍒伴〉闈㈡暟鎹腑 + this.setData({ + projectList, + selectedProject: currentSelectedProject + }); + + console.log('椤圭洰鍒楄〃宸插垵濮嬪寲:', projectList, '褰撳墠閫変腑椤圭洰:', currentSelectedProject); + }, + + // 鏂板鐨勫垵濮嬪寲椤甸潰杈呭姪鍑芥暟锛屽垎绂诲嚭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 serverUrl = PROJECT_CONFIG[project]?.serverUrl; + if (serverUrl) { + getApp().globalData.baseUrl = serverUrl; + getApp().globalData.selectedProject = project; + console.log('璁剧疆baseUrl:', serverUrl); + } + + // 鏍规嵁椤圭洰璁剧疆瀵瑰簲鐨則ag + const projectConfig = PROJECT_CONFIG[project]; + if (projectConfig) { + getApp().globalData.tag = projectConfig.tag; + + // 鏍规嵁椤圭洰鏄惁闇�瑕佺櫥褰曪紝璁剧疆涓嶅悓鐨剈serName + if (projectConfig.needLogin === false) { + // 涓嶉渶瑕佺櫥褰曠殑椤圭洰锛屾樉绀洪」鐩悕绉� + this.setData({ + userName: projectConfig.displayName + }); + } else { + // 闇�瑕佺櫥褰曠殑椤圭洰锛屾樉绀�"璇风偣鍑荤櫥褰�" + this.setData({ + userName: "璇风偣鍑荤櫥褰�" + }); + } + } + + // 鏍规嵁椤圭洰璁剧疆瀵瑰簲鐨刼perator鍜宑lientId + if (projectConfig && projectConfig.operatorId) { + getApp().globalData.operator = projectConfig.operatorId; + getApp().globalData.clientId = projectConfig.operatorId; + getApp().globalData.isLoggedIn = true; + getApp().globalData.sessionId = projectConfig.operatorId; + + // 濡傛灉鏈塿cId锛屼篃璁剧疆 + if (projectConfig.vcId) { + getApp().globalData.vcId = projectConfig.vcId; + } + + // 鎸佷箙鍖栧瓨鍌ㄩ」鐩弬鏁� + const params = { + operator: projectConfig.operatorId, + clientId: projectConfig.operatorId, + isLoggedIn: true, + sessionId: projectConfig.operatorId + }; + + if (projectConfig.vcId) { + params.vcId = projectConfig.vcId; + } + + storage.setItem(`${project}_params`, params); + } + + // 缁х画鍒濆鍖栭〉闈� + 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) { + 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; + } + + console.log('鎵ц鐧诲綍鐘舵�佹鏌�'); + this.checkLoginStatus(); + }, + + /** + * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰闅愯棌 + */ + onHide() { + // 椤甸潰闅愯棌鏃惰�冭檻娓呯悊涓存椂鏍囪 + this.cleanupTempMarkers(); + }, + + /** + * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇 + */ + onUnload() { + // 椤甸潰鍗歌浇鏃舵竻鐞嗕复鏃舵爣璁� + this.cleanupTempMarkers(); + }, + + /** + * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 + */ + onPullDownRefresh() { + // 涓嬫媺鍒锋柊瑙﹀彂鐨勯�昏緫锛屽彲浠ユ槸璇锋眰鏁版嵁绛夋搷浣� + // 渚嬪锛岃姹傛暟鎹悗鏇存柊椤甸潰鍐呭 + console.log(this.data.isRefreshing); + this.setData({ + isWXRefreshing: true + }); + console.log(this.data.isRefreshing); + // 鏁版嵁璇锋眰瀹屾垚鍚庯紝鍋滄涓嬫媺鍒锋柊鐨勫姩鐢� + this.getOpenList(); + }, + + /** + * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁� + */ + onReachBottom() { + + }, + + /** + * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜� + */ + onShareAppMessage() { + + }, + recharge() { + // wx.navigateTo({ + // url: '/pages/rechargeCard/rechargeCard', + // }) + wx.showToast({ + title: '鏆傛湭寮�鏀�', + icon: 'none' + }) + }, + openValveList() { + const app = getApp(); + if (app.globalData.isLoggedIn) { + wx.navigateTo({ + url: '/pages/valveList/valveList', + }) + } else { + wx.showToast({ + title: '璇峰厛鐧诲綍', + icon: 'error' + }) + } + }, + feedBack() { + wx.showToast({ + title: '鏆傛湭寮�鏀�', + icon: 'none' + }) + }, + //瑙g粦鐢ㄦ埛 + unbind() { + // 妫�鏌ュ綋鍓嶉」鐩槸鍚﹂渶瑕佺櫥褰� + const currentProject = getApp().globalData.selectedProject; + const projectConfig = PROJECT_CONFIG[currentProject]; + + // 濡傛灉褰撳墠椤圭洰閰嶇疆涓轰笉闇�瑕佺櫥褰曪紝鍒欐彁绀虹敤鎴峰苟鎵撳紑椤圭洰閫夋嫨寮圭獥 + if (projectConfig && !projectConfig.needLogin) { + wx.showModal({ + title: '鍒囨崲椤圭洰', + content: '鏄惁纭畾瑙g粦锛�', + confirmText: '纭', + cancelText: '鍙栨秷', + success: (res) => { + if (res.confirm) { + // 鏄剧ず椤圭洰閫夋嫨寮圭獥 + this.setData({ + showProjectDialog: true + }); + } + } + }); + return; + } + + // 濡傛灉宸茬櫥褰曪紝鏄剧ず瑙g粦纭瀵硅瘽妗� + if (getApp().globalData.isLoggedIn) { + wx.showModal({ + title: '瑙g粦纭', + content: '纭畾瑕佽В缁戝綋鍓嶈处鍙峰悧锛熻В缁戝悗灏嗘棤娉曚娇鐢ㄧ浉鍏冲姛鑳斤紝闇�閲嶆柊缁戝畾銆�', + confirmText: '纭瑙g粦', + confirmColor: '#e34d59', + cancelText: '鍙栨秷', + 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); + this.setData({ + showConfirm: true, + waterIntakeName: item.intakeNum, + myItem: item + }); + }, + closeDialog() { + console.log("closeDialog"); + this.setData({ + showConfirm: false, + showErrorDialog: false, + showForceConfirm: false + }); + }, + cancelDialog() { + this.setData({ + showForceConfirm: false, + showConfirm: false + }); + }, + /** + * 鍏抽棴闃�闂� + * @param {*} orderNo 璁㈠崟鍙� + * @param {*} rtuAddr 闃�鎺у櫒鍦板潃 + * @param {*} vcNum 铏氭嫙鍗$紪鍙� + */ + postCloseValaue(orderNo, rtuAddr, vcNum) { + wx.showLoading({ + title: '姝e湪鍏抽榾璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧 + mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false + }); + const app = getApp(); + const data = { + rtuAddr: rtuAddr, + vcNum: vcNum, //铏氭嫙鍗D + orderNo: orderNo, + operator: app.globalData.clientId //鎿嶄綔鍛� + }; + console.log("postCloseValaue" + data); + post({ + url: "wx/valve/close_wx", + data: data, + isShowLoding: false, + timeout: 185000 + }).then(response => { + + // 澶勭悊鎴愬姛鍝嶅簲 + console.log('璇锋眰鎴愬姛:', response); + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + this.getOpenList(); + wx.showToast({ + title: '鍏抽榾鎴愬姛', + icon: 'success', + duration: 3000 + }) + }).catch(error => { + wx.hideLoading(); + // 澶勭悊閿欒鍝嶅簲 + console.error('璇锋眰澶辫触:', error); + if (error.code === "ECONNABORTED" || error.message?.includes('timeout')) { + // 澶勭悊瓒呮椂閿欒 + this.setData({ + showErrorDialog: true, + errorData: "閫氫俊瓒呮椂锛岃绋嶅悗鍐嶈瘯", + errorDialogTitle: "鍏抽榾閿欒" + }) + } else { + this.setData({ + showErrorDialog: true, + errorData: error.msg, + errorDialogTitle: "鍏抽榾閿欒" + }) + } + }); + }, + /** + * 鑾峰彇涓哄叧闃�璁板綍 + */ + 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.clientId + } + }; + + get(params).then(data => { + console.log('鑾峰彇鍒楄〃鏁版嵁鎴愬姛:', data); + this.setData({ + listData: data.content, + isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 + isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 + }); + this.updateDisplayText(); + + }).catch(err => { + console.error('鑾峰彇鍒楄〃鏁版嵁澶辫触:', err); + // 閿欒鍥炶皟 + this.setData({ + isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 + isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 + }); + + // 妫�鏌ラ敊璇被鍨� + if (err && err.code === '0003') { + console.log('浼氳瘽鏃犳晥鎴栬繃鏈燂紝浣嗕笉杩涜璺宠浆'); + + // 濡傛灉涓嶆槸浠庣櫥褰曢〉杩斿洖锛屾樉绀洪敊璇彁绀� + if (!fromLogin) { + wx.showToast({ + title: '鐧诲綍宸茶繃鏈燂紝璇峰埛鏂伴噸璇�', + icon: 'none', + duration: 3000 + }); + } + } else { + // 涓�鑸敊璇紝鏄剧ず閿欒淇℃伅 wx.showToast({ - title: '鏆傛湭寮�鏀�', - icon: 'none' - }) - }, - //瑙g粦鐢ㄦ埛 - unbind() { - // 妫�鏌ュ綋鍓嶉」鐩槸鍚﹂渶瑕佺櫥褰� - const currentProject = getApp().globalData.selectedProject; - const projectConfig = PROJECT_CONFIG[currentProject]; + title: err.msg || '鑾峰彇鍒楄〃鏁版嵁澶辫触', + icon: 'none', + duration: 3000 + }); + } + }); + }, + /** + * 纭鍏抽棴鍥炶皟 + * @param {} item + */ + confirmDialog() { + this.setData({ + showConfirm: false + }); + this.postCloseValaue(this.data.myItem.orderNo, this.data.myItem.rtuAddr, this.data.myItem.vcNum); + }, + //鏍规嵁session鑾峰彇鍐滄埛淇℃伅 + getUserDataBySession() { + // 鍏堟鏌ユ槸鍚︿粠鐧诲綍椤佃繑鍥� + if (this.getFromLogin()) { + console.log('getUserDataBySession: 妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝涓嶆墽琛孉PI璇锋眰'); + return; + } - // 濡傛灉褰撳墠椤圭洰閰嶇疆涓轰笉闇�瑕佺櫥褰曪紝鍒欐彁绀虹敤鎴峰苟鎵撳紑椤圭洰閫夋嫨寮圭獥 - if (projectConfig && !projectConfig.needLogin) { - wx.showModal({ - title: '鍒囨崲椤圭洰', - content: '鏄惁纭畾瑙g粦锛�', - confirmText: '纭', - cancelText: '鍙栨秷', - success: (res) => { - if (res.confirm) { - // 鏄剧ず椤圭洰閫夋嫨寮圭獥 - this.setData({ - showProjectDialog: true - }); - } - } - }); - 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 => { + 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 + }); } + } + }); + }, + maskPhoneNumber(phoneNumber) { + if (phoneNumber.length !== 11) { + throw new Error("Phone number must be 11 digits"); + } + // 浣跨敤姝e垯琛ㄨ揪寮忔浛鎹腑闂村洓浣嶆暟瀛椾负鏄熷彿 + const maskedPhoneNumber = phoneNumber.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2"); + return maskedPhoneNumber; + }, - // 濡傛灉宸茬櫥褰曪紝鏄剧ず瑙g粦纭瀵硅瘽妗� - if (getApp().globalData.isLoggedIn) { - wx.showModal({ - title: '瑙g粦纭', - content: '纭畾瑕佽В缁戝綋鍓嶈处鍙峰悧锛熻В缁戝悗灏嗘棤娉曚娇鐢ㄧ浉鍏冲姛鑳斤紝闇�閲嶆柊缁戝畾銆�', - confirmText: '纭瑙g粦', - confirmColor: '#e34d59', - cancelText: '鍙栨秷', - success: (res) => { - if (res.confirm) { - this.unBindPost(); - } - } - }); + closeDialog() { + this.setData({ + showErrorDialog: false + }) + }, + /** + * 鎵爜寮�闃� + */ + scenCode() { + const that = this; + wx.scanCode({ + success(res) { + console.log(res.result); // 褰撲笖浠呭綋鎵爜涓洪潪寰俊浜岀淮鐮佹椂锛屼細杩斿洖result + if (res.result.startsWith("content://")) { + let jsonStr = res.result.replace("content://", "") + try { + + that.saveData(jsonStr) + } catch (error) { + console.error('Error parsing JSON:', error); + } + } 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); - this.setData({ - showConfirm: true, - waterIntakeName: item.intakeNum, - myItem: item - }); - }, - closeDialog() { - console.log("closeDialog"); - this.setData({ - showConfirm: false, - showErrorDialog: false, - showForceConfirm: false - }); - }, - cancelDialog() { - this.setData({ - showForceConfirm: false, - showConfirm: false - }); - }, - /** - * 鍏抽棴闃�闂� - * @param {*} orderNo 璁㈠崟鍙� - * @param {*} rtuAddr 闃�鎺у櫒鍦板潃 - * @param {*} vcNum 铏氭嫙鍗$紪鍙� - */ - postCloseValaue(orderNo, rtuAddr, vcNum) { - wx.showLoading({ - title: '姝e湪鍏抽榾璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧 - mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false - }); - const app = getApp(); - const data = { - rtuAddr: rtuAddr, - vcNum: vcNum, //铏氭嫙鍗D - orderNo: orderNo, - operator: app.globalData.clientId //鎿嶄綔鍛� - }; - console.log("postCloseValaue" + data); - post({ - url: "wx/valve/close_wx", - data: data, - isShowLoding: false, - timeout: 185000 - }).then(response => { - - // 澶勭悊鎴愬姛鍝嶅簲 - console.log('璇锋眰鎴愬姛:', response); - // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� - wx.hideLoading(); - this.getOpenList(); - wx.showToast({ - title: '鍏抽榾鎴愬姛', - icon: 'success', - duration: 3000 - }) - }).catch(error => { - wx.hideLoading(); - // 澶勭悊閿欒鍝嶅簲 - console.error('璇锋眰澶辫触:', error); - if (error.code === "ECONNABORTED" || error.message?.includes('timeout')) { - // 澶勭悊瓒呮椂閿欒 - this.setData({ - showErrorDialog: true, - errorData: "閫氫俊瓒呮椂锛岃绋嶅悗鍐嶈瘯", - errorDialogTitle: "鍏抽榾閿欒" - }) - } else { - this.setData({ - showErrorDialog: true, - errorData: error.msg, - errorDialogTitle: "鍏抽榾閿欒" - }) - } - }); - }, - /** - * 鑾峰彇涓哄叧闃�璁板綍 - */ - 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; + that.postOppenValva(res.result) } - console.log('getOpenList: 寮�濮嬭幏鍙栧垪琛ㄦ暟鎹�, clientId:', app.globalData.clientId); + }, + fail(err) { + console.error(err); + } + }) + }, + 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.clientId, //鎿嶄綔鍛� + forceOpen: !!isforce // 浣跨敤閫昏緫闈炴搷浣滅 !! 鏉ョ‘淇� isForce 鏄竷灏斿�� + }; + post({ + url: "wx/valve/open_wx", + data: data, + timeout: 180000 + }).then(response => { - const params = { - url: 'wx/valve/get', - data: { - operator: app.globalData.clientId - } - }; - - get(params).then(data => { - console.log('鑾峰彇鍒楄〃鏁版嵁鎴愬姛:', data); - this.setData({ - listData: data.content, - isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 - isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 - }); - this.updateDisplayText(); - - }).catch(err => { - console.error('鑾峰彇鍒楄〃鏁版嵁澶辫触:', err); - // 閿欒鍥炶皟 - this.setData({ - isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 - isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 - }); - - // 妫�鏌ラ敊璇被鍨� - 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 - }); - } - }); - }, - /** - * 纭鍏抽棴鍥炶皟 - * @param {} item - */ - confirmDialog() { - this.setData({ - showConfirm: false - }); - this.postCloseValaue(this.data.myItem.orderNo, this.data.myItem.rtuAddr, this.data.myItem.vcNum); - }, - //鏍规嵁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 => { - 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) { - throw new Error("Phone number must be 11 digits"); - } - // 浣跨敤姝e垯琛ㄨ揪寮忔浛鎹腑闂村洓浣嶆暟瀛椾负鏄熷彿 - const maskedPhoneNumber = phoneNumber.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2"); - return maskedPhoneNumber; - }, - - closeDialog() { - this.setData({ - showErrorDialog: false - }) - }, - /** - * 鎵爜寮�闃� - */ - scenCode() { - const that = this; - wx.scanCode({ - success(res) { - console.log(res.result); // 褰撲笖浠呭綋鎵爜涓洪潪寰俊浜岀淮鐮佹椂锛屼細杩斿洖result - if (res.result.startsWith("content://")) { - let jsonStr = res.result.replace("content://", "") - try { - - that.saveData(jsonStr) - } catch (error) { - console.error('Error parsing JSON:', error); - } - - } else { - that.postOppenValva(res.result) - } - - }, - fail(err) { - console.error(err); - } - }) - }, - 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(); + // 澶勭悊鎴愬姛鍝嶅簲 + 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({ - lastIntakeName: intakeName + showForceConfirm: true }) - const data = { - intakeName: intakeName, //鍙栨按鍙D - // vcId: vcId, //铏氭嫙鍗D - operator: app.globalData.clientId, //鎿嶄綔鍛� - forceOpen: !!isforce // 浣跨敤閫昏緫闈炴搷浣滅 !! 鏉ョ‘淇� isForce 鏄竷灏斿�� - }; - post({ - url: "wx/valve/open_wx", - data: data, - timeout: 180000 - }).then(response => { + } else { + that.setData({ + showErrorDialog: true, + errorData: error.msg, + errorDialogTitle: "寮�闃�閿欒" + }) + } + }); + }, + /** + * 鎵弿鍚庝繚瀛樼敤鎴穒d鍜宼ag + */ + saveData(userData) { + storage.setItem("userData", userData).then(() => { + this.initData(); + }).catch((error) => {}); - // 澶勭悊鎴愬姛鍝嶅簲 - console.log('璇锋眰鎴愬姛:', response); - // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� - wx.hideLoading(); - //瀹屾垚鍚庡洖鍒伴椤� - wx.reLaunch({ - url: '/pages/home/home?param=true' // 棣栭〉鐨勮矾寰勶紝鏍规嵁瀹為檯鎯呭喌濉啓 + }, + //杩涘叆鐣岄潰鑾峰彇鐣岄潰鏁版嵁 + initData() { + const app = getApp(); + 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: [] }); - }).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) => { }); + }); + } else { + this.getOpenList(); + } + return; + } - }, - //杩涘叆鐣岄潰鑾峰彇鐣岄潰鏁版嵁 - initData() { - const app = getApp(); - console.log("initData寮�濮嬶紝tag:", app.globalData.tag); + // 妫�鏌ュ綋鍓嶉」鐩槸鍚﹂渶瑕佺櫥褰� + const currentProject = app.globalData.selectedProject; + const projectConfig = PROJECT_CONFIG[currentProject]; + const needLogin = projectConfig && projectConfig.needLogin; - // 棣栧厛妫�鏌ユ槸鍚︿粠鐧诲綍椤佃繑鍥� - if (this.getFromLogin()) { - console.log('initData: 妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝浠呰幏鍙栧熀鏈暟鎹�'); + // 鏍规嵁椤圭洰鏄惁闇�瑕佺櫥褰曪紝璁剧疆涓嶅悓鐨剈serName + if (projectConfig && projectConfig.needLogin === false) { + // 涓嶉渶瑕佺櫥褰曠殑椤圭洰锛屾樉绀洪」鐩悕绉� + this.setData({ + userName: projectConfig.displayName + }); + } - // 鍗充娇浠庣櫥褰曢〉杩斿洖锛屼篃灏濊瘯鑾峰彇寮�闃�鍒楄〃浠ユ樉绀哄熀鏈琔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鑾峰彇鏁版嵁'); + + // 鍙湁闇�瑕佺櫥褰曠殑椤圭洰鎵嶈皟鐢╣etUserDataBySession + if (needLogin) { + console.log('initData: 褰撳墠椤圭洰闇�瑕佺櫥褰曪紝鑾峰彇鐢ㄦ埛鏁版嵁'); + this.getUserDataBySession(); + } else { + console.log('initData: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰曪紝璺宠繃鑾峰彇鐢ㄦ埛鏁版嵁'); } - // 妫�鏌ュ綋鍓嶉」鐩槸鍚﹂渶瑕佺櫥褰� - const currentProject = app.globalData.selectedProject; - const projectConfig = PROJECT_CONFIG[currentProject]; - const needLogin = projectConfig && projectConfig.needLogin; + this.getOpenList(); + return; + } - // 灏濊瘯鑾峰彇鐢ㄦ埛鏁版嵁鍜屽凡寮�闃�璁板綍 - try { - // 浼樺厛妫�鏌ュ叏灞�鍙橀噺涓槸鍚︽湁sessionId - if (app.globalData.sessionId) { - console.log('initData: 浣跨敤鍏ㄥ眬sessionId鑾峰彇鏁版嵁'); + // 妫�鏌ユ槸鍚︽湁瀛樺偍鐨剈serData + const hasUserData = storage.isHasKeySync("userData"); + console.log('initData: 鏄惁瀛樺湪userData:', hasUserData); - // 鍙湁闇�瑕佺櫥褰曠殑椤圭洰鎵嶈皟鐢╣etUserDataBySession - if (needLogin) { - console.log('initData: 褰撳墠椤圭洰闇�瑕佺櫥褰曪紝鑾峰彇鐢ㄦ埛鏁版嵁'); - this.getUserDataBySession(); - } else { - console.log('initData: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰曪紝璺宠繃鑾峰彇鐢ㄦ埛鏁版嵁'); - } - - this.getOpenList(); - return; + 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); + } } - // 妫�鏌ユ槸鍚︽湁瀛樺偍鐨剈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); - } - } - - // 鍙湁闇�瑕佺櫥褰曠殑椤圭洰鎵嶈皟鐢╣etUserDataBySession - if (needLogin) { - console.log('initData: 褰撳墠椤圭洰闇�瑕佺櫥褰曪紝鑾峰彇鐢ㄦ埛鏁版嵁'); - this.getUserDataBySession(); - } else { - console.log('initData: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰曪紝璺宠繃鑾峰彇鐢ㄦ埛鏁版嵁'); - } - - this.getOpenList(); - }) - .catch((err) => { - console.error('鍔犺浇userData澶辫触:', err); - - // 鍐嶆妫�鏌ユ槸鍚︿粠鐧诲綍椤佃繑鍥� - if (this.getFromLogin()) { - console.log('initData:catch: 妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝鍙幏鍙栧紑闃�鍒楄〃'); - this.getOpenList(); - } else { - // 鍙湁闇�瑕佺櫥褰曠殑椤圭洰鎵嶈皟鐢╣etUserDataBySession - if (needLogin) { - console.log('initData:catch: 褰撳墠椤圭洰闇�瑕佺櫥褰曪紝鑾峰彇鐢ㄦ埛鏁版嵁'); - this.getUserDataBySession(); - } else { - console.log('initData:catch: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰曪紝璺宠繃鑾峰彇鐢ㄦ埛鏁版嵁'); - } - - this.getOpenList(); - } - }); + // 鍙湁闇�瑕佺櫥褰曠殑椤圭洰鎵嶈皟鐢╣etUserDataBySession + if (needLogin) { + console.log('initData: 褰撳墠椤圭洰闇�瑕佺櫥褰曪紝鑾峰彇鐢ㄦ埛鏁版嵁'); + this.getUserDataBySession(); } else { - console.log('鏈壘鍒皍serData锛岀洿鎺ヨ幏鍙栨暟鎹�'); - - // 鍐嶆妫�鏌ユ槸鍚︿粠鐧诲綍椤佃繑鍥� - if (this.getFromLogin()) { - console.log('initData:else: 妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝鍙幏鍙栧紑闃�鍒楄〃'); - this.getOpenList(); - } else { - // 鍙湁闇�瑕佺櫥褰曠殑椤圭洰鎵嶈皟鐢╣etUserDataBySession - if (needLogin) { - console.log('initData:else: 褰撳墠椤圭洰闇�瑕佺櫥褰曪紝鑾峰彇鐢ㄦ埛鏁版嵁'); - this.getUserDataBySession(); - } else { - console.log('initData:else: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰曪紝璺宠繃鑾峰彇鐢ㄦ埛鏁版嵁'); - } - - this.getOpenList(); - } + console.log('initData: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰曪紝璺宠繃鑾峰彇鐢ㄦ埛鏁版嵁'); } - } catch (e) { - console.error('initData鎵ц鍑洪敊:', e); + + this.getOpenList(); + }) + .catch((err) => { + console.error('鍔犺浇userData澶辫触:', err); // 鍐嶆妫�鏌ユ槸鍚︿粠鐧诲綍椤佃繑鍥� if (this.getFromLogin()) { - console.log('initData:error: 妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝鍙幏鍙栧紑闃�鍒楄〃'); - this.getOpenList(); + console.log('initData:catch: 妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝鍙幏鍙栧紑闃�鍒楄〃'); + this.getOpenList(); } else { - // 鍙湁闇�瑕佺櫥褰曠殑椤圭洰鎵嶈皟鐢╣etUserDataBySession - if (needLogin) { - console.log('initData:error: 褰撳墠椤圭洰闇�瑕佺櫥褰曪紝鑾峰彇鐢ㄦ埛鏁版嵁'); - this.getUserDataBySession(); - } else { - console.log('initData:error: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰曪紝璺宠繃鑾峰彇鐢ㄦ埛鏁版嵁'); - } + // 鍙湁闇�瑕佺櫥褰曠殑椤圭洰鎵嶈皟鐢╣etUserDataBySession + if (needLogin) { + console.log('initData:catch: 褰撳墠椤圭洰闇�瑕佺櫥褰曪紝鑾峰彇鐢ㄦ埛鏁版嵁'); + this.getUserDataBySession(); + } else { + console.log('initData:catch: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰曪紝璺宠繃鑾峰彇鐢ㄦ埛鏁版嵁'); + } - this.getOpenList(); + this.getOpenList(); } - } - }, - // 澶勭悊澶村儚鐐瑰嚮 - handleAvatarTap() { - this.setData({ - avatarTapCount: this.data.avatarTapCount + 1 - }); + }); + } else { + console.log('鏈壘鍒皍serData锛岀洿鎺ヨ幏鍙栨暟鎹�'); - if (this.data.avatarTapCount >= 5) { - this.setData({ - showProjectDialog: true, - avatarTapCount: 0 - }); - } - }, - - // 澶勭悊寮圭獥鍙鎬у彉鍖� - onVisibleChange(e) { - // 濡傛灉灏濊瘯鍏抽棴寮圭獥涓旀病鏈夐�夋嫨椤圭洰锛屽垯闃绘鍏抽棴 - if (!e.detail.visible && !this.data.selectedProject) { - return; - } - this.setData({ - showProjectDialog: e.detail.visible - }); - }, - - // 澶勭悊椤圭洰閫夋嫨鍙樺寲 - onProjectChange(event) { - console.log('閫夋嫨鐨勯」鐩細', event.detail.value); - this.setData({ - selectedProject: event.detail.value - }); - }, - - // 澶勭悊椤圭洰閫夋嫨纭 - handleProjectConfirm() { - console.log('寮�濮嬪鐞嗛」鐩�夋嫨纭', this.data.selectedProject, this.data.projectList); - - if (!this.data.selectedProject) { - wx.showToast({ - title: '璇烽�夋嫨椤圭洰', - icon: 'none' - }); - return; - } - - // 鑾峰彇褰撳墠宸查�夐」鐩拰鏂伴�夋嫨鐨勯」鐩� - const currentProject = getApp().globalData.selectedProject; - const newProject = this.data.selectedProject; - console.log('褰撳墠椤圭洰:', currentProject, '鏂伴�夋嫨椤圭洰:', newProject); - console.log('PROJECT_CONFIG 鍐呭:', PROJECT_CONFIG); - - const projectConfig = PROJECT_CONFIG[newProject]; - console.log('閫夋嫨鐨勯」鐩厤缃�:', projectConfig); - - if (!projectConfig) { - wx.showToast({ - title: '椤圭洰閰嶇疆閿欒', - icon: 'none' - }); - return; - } - - // 妫�鏌ユ槸鍚﹀垏鎹簡椤圭洰锛堝鏋滃綋鍓嶉」鐩笉鍚屼簬鏂伴�夋嫨鐨勯」鐩級 - const isProjectChanged = currentProject && currentProject !== newProject; - - // 娣诲姞浜屾纭 - const confirmText = isProjectChanged - ? `纭畾瑕佸皢椤圭洰浠�"${PROJECT_CONFIG[currentProject]?.displayName || '褰撳墠椤圭洰'}"鍒囨崲鍒�"${projectConfig.displayName}"鍚楋紵` - : `纭畾閫夋嫨"${projectConfig.displayName}"椤圭洰鍚楋紵`; - - wx.showModal({ - title: isProjectChanged ? '纭鍒囨崲椤圭洰' : '纭閫夋嫨椤圭洰', - content: confirmText, - confirmText: isProjectChanged ? '纭鍒囨崲' : '纭', - cancelText: '鍙栨秷', - success: (res) => { - if (res.confirm) { - // 鐢ㄦ埛纭閫夋嫨锛岀户缁鐞� - this.processProjectSelection(currentProject, newProject, projectConfig, isProjectChanged); - } else { - // 鐢ㄦ埛鍙栨秷锛屼笉杩涜浠讳綍鎿嶄綔 - console.log('鐢ㄦ埛鍙栨秷浜嗛」鐩�夋嫨'); - } - } - }); - }, - - // 澶勭悊椤圭洰閫夋嫨鐨勫悗缁搷浣� - processProjectSelection(currentProject, newProject, projectConfig, isProjectChanged) { - // 濡傛灉鍒囨崲浜嗛」鐩紝鍏堟竻闄ょ櫥褰曠姸鎬� - 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', newProject).then(() => { - // 璋冪敤setBaseUrl鏉ユ洿鏂板熀纭�URL - try { - console.log('灏濊瘯璁剧疆鍩虹URL锛岄」鐩�:', newProject); - const result = config.setBaseUrl(newProject); - console.log('璁剧疆鍩虹URL缁撴灉:', result); - } catch (error) { - console.error('璁剧疆鍩虹URL鍑洪敊:', error); - // 缁х画鎵ц锛屼笉涓柇娴佺▼ - } - - // 鏇存柊鍏ㄥ眬鍙橀噺 - getApp().globalData = getApp().globalData || {}; - getApp().globalData.selectedProject = newProject; - getApp().globalData.baseUrl = projectConfig.serverUrl; - getApp().globalData.serverId = projectConfig.serverId; - - // 閫氳繃閰嶇疆瀵硅薄缁熶竴璁剧疆椤圭洰鍙傛暟 - getApp().globalData.tag = projectConfig.tag; - - // 璁剧疆鐢ㄦ埛鐣岄潰鏄剧ず鐨勯」鐩悕绉� - this.setData({ - userName: projectConfig.displayName - }); - - // 瀵逛簬涓嶉渶瑕佺櫥褰曠殑椤圭洰锛岀洿鎺ヨ缃畂perator鍜宑lientId - if (!projectConfig.needLogin && projectConfig.operatorId) { - const operatorId = projectConfig.operatorId; - getApp().globalData.operator = operatorId; - getApp().globalData.clientId = operatorId; - getApp().globalData.isLoggedIn = true; - getApp().globalData.sessionId = operatorId; - - // 濡傛灉鏈塿cId锛屼篃璁剧疆 - if (projectConfig.vcId) { - getApp().globalData.vcId = projectConfig.vcId; - } - - // 鎸佷箙鍖栧瓨鍌ㄩ」鐩弬鏁� - const params = { - operator: operatorId, - clientId: operatorId, - isLoggedIn: true, - sessionId: operatorId - }; - - if (projectConfig.vcId) { - params.vcId = projectConfig.vcId; - } - - storage.setItem(`${newProject}_params`, params); - } - - console.log('宸插垏鎹㈠埌椤圭洰:', projectConfig.displayName, '鏈嶅姟鍣�:', projectConfig.serverId, 'tag:', getApp().globalData.tag); - - this.setData({ - showProjectDialog: false - }); - - // 鏄剧ず鍒囨崲鎴愬姛鎻愮ず - wx.showToast({ - title: `宸查�夋嫨${projectConfig.displayName}`, - icon: 'success', - duration: 2000 - }); - setTimeout(() => { - console.log('椤圭洰宸插垏鎹紝姝e湪鍒濆鍖栨暟鎹�'); - this.initData(); - }, 1000); - - }).catch(err => { - console.error('淇濆瓨椤圭洰閫夋嫨澶辫触锛�', err); - wx.showToast({ - title: '淇濆瓨澶辫触锛岃閲嶈瘯', - icon: 'none', - duration: 2000 - }); - }); - }, - - // 妫�鏌ョ櫥褰曠姸鎬� - checkLoginStatus() { - const app = getApp(); - - // 妫�鏌ユ槸鍚﹀凡鐧诲綍 - if (app.globalData.isLoggedIn && app.globalData.sessionId) { - console.log('宸蹭粠鍏ㄥ眬鍙橀噺妫�娴嬪埌鐧诲綍鐘舵��'); - return; - } - - // 妫�鏌ユ湰椤甸潰鏄惁姝e湪澶勭悊杩斿洖閫昏緫 - const fromLogin = this.getFromLogin(); - if (fromLogin) { - console.log('浠庣櫥褰曢〉杩斿洖锛屼笉鍐嶉噸瀹氬悜'); - return; - } - - // 妫�鏌ュ綋鍓嶉」鐩槸鍚﹂渶瑕佺櫥褰� - const currentProject = app.globalData.selectedProject; - if (currentProject && PROJECT_CONFIG[currentProject] && !PROJECT_CONFIG[currentProject].needLogin) { - console.log('褰撳墠椤圭洰涓嶉渶瑕佺櫥褰�:', currentProject); - 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 - }); - 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; - } - - // 妫�鏌ラ」鐩槸鍚﹂渶瑕佺櫥褰� - if (currentProject && PROJECT_CONFIG[currentProject] && !PROJECT_CONFIG[currentProject].needLogin) { - console.log('鏈�缁堟鏌�: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰�:', currentProject); - return; - } - - console.log('纭闇�瑕佽烦杞埌鐧诲綍椤�'); - - // 璺宠浆鍓嶅啀娆℃鏌ョ櫥褰曢〉闈复鏃舵爣璁� - try { - 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) - // }); - } - }) - .catch(err => { - console.error('妫�鏌ョ櫥褰曠姸鎬佹椂鍑洪敊:', err); - - // 鏍囪褰撳墠椤甸潰姝e湪澶勭悊杩斿洖閫昏緫 - this.setData({ - isFromLogin: true - }); - - // 鍐嶆妫�鏌ユ槸鍚﹀凡浠庣櫥褰曢〉杩斿洖 - if (this.getFromLogin()) { - console.log('閿欒澶勭悊: 宸蹭粠鐧诲綍椤佃繑鍥烇紝涓嶅啀璺宠浆'); - return; - } - - // 妫�鏌ラ」鐩槸鍚﹂渶瑕佺櫥褰� - if (currentProject && PROJECT_CONFIG[currentProject] && !PROJECT_CONFIG[currentProject].needLogin) { - console.log('閿欒澶勭悊: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰�:', currentProject); - 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; - } - // 褰撳紑闃�鎴愬姛鍚庤皟鐢ㄥ埛鏂� - 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); + // 鍐嶆妫�鏌ユ槸鍚︿粠鐧诲綍椤佃繑鍥� + if (this.getFromLogin()) { + console.log('initData:else: 妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝鍙幏鍙栧紑闃�鍒楄〃'); + this.getOpenList(); } else { - console.log('浠庣櫥褰曢〉杩斿洖锛屼笉妫�鏌ョ櫥褰曠姸鎬�'); - } - }, + // 鍙湁闇�瑕佺櫥褰曠殑椤圭洰鎵嶈皟鐢╣etUserDataBySession + if (needLogin) { + console.log('initData:else: 褰撳墠椤圭洰闇�瑕佺櫥褰曪紝鑾峰彇鐢ㄦ埛鏁版嵁'); + this.getUserDataBySession(); + } else { + console.log('initData:else: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰曪紝璺宠繃鑾峰彇鐢ㄦ埛鏁版嵁'); + } - // 寰俊鐧诲綍 - wxLogin() { - // 妫�鏌ュ綋鍓嶉」鐩槸鍚﹂渶瑕佺櫥褰� - const currentProject = getApp().globalData.selectedProject; - if (currentProject && PROJECT_CONFIG[currentProject] && !PROJECT_CONFIG[currentProject].needLogin) { - console.log('wxLogin: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰�:', currentProject); + this.getOpenList(); + } + } + } catch (e) { + console.error('initData鎵ц鍑洪敊:', e); + + // 鍐嶆妫�鏌ユ槸鍚︿粠鐧诲綍椤佃繑鍥� + if (this.getFromLogin()) { + console.log('initData:error: 妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝鍙幏鍙栧紑闃�鍒楄〃'); + this.getOpenList(); + } else { + // 鍙湁闇�瑕佺櫥褰曠殑椤圭洰鎵嶈皟鐢╣etUserDataBySession + if (needLogin) { + console.log('initData:error: 褰撳墠椤圭洰闇�瑕佺櫥褰曪紝鑾峰彇鐢ㄦ埛鏁版嵁'); + this.getUserDataBySession(); + } else { + console.log('initData:error: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰曪紝璺宠繃鑾峰彇鐢ㄦ埛鏁版嵁'); + } + + this.getOpenList(); + } + } + }, + // 澶勭悊澶村儚鐐瑰嚮 + handleAvatarTap() { + this.setData({ + avatarTapCount: this.data.avatarTapCount + 1 + }); + + if (this.data.avatarTapCount >= 5) { + this.setData({ + showProjectDialog: true, + avatarTapCount: 0 + }); + } + }, + + // 澶勭悊寮圭獥鍙鎬у彉鍖� + onVisibleChange(e) { + // 濡傛灉灏濊瘯鍏抽棴寮圭獥涓旀病鏈夐�夋嫨椤圭洰锛屽垯闃绘鍏抽棴 + if (!e.detail.visible && !this.data.selectedProject) { + return; + } + this.setData({ + showProjectDialog: e.detail.visible + }); + }, + + // 澶勭悊椤圭洰閫夋嫨鍙樺寲 + onProjectChange(event) { + console.log('閫夋嫨鐨勯」鐩細', event.detail.value); + this.setData({ + selectedProject: event.detail.value + }); + }, + + // 澶勭悊椤圭洰閫夋嫨纭 + handleProjectConfirm() { + console.log('寮�濮嬪鐞嗛」鐩�夋嫨纭', this.data.selectedProject, this.data.projectList); + + if (!this.data.selectedProject) { + wx.showToast({ + title: '璇烽�夋嫨椤圭洰', + icon: 'none' + }); + return; + } + + // 鑾峰彇褰撳墠宸查�夐」鐩拰鏂伴�夋嫨鐨勯」鐩� + const currentProject = getApp().globalData.selectedProject; + const newProject = this.data.selectedProject; + console.log('褰撳墠椤圭洰:', currentProject, '鏂伴�夋嫨椤圭洰:', newProject); + console.log('PROJECT_CONFIG 鍐呭:', PROJECT_CONFIG); + + const projectConfig = PROJECT_CONFIG[newProject]; + console.log('閫夋嫨鐨勯」鐩厤缃�:', projectConfig); + + if (!projectConfig) { + wx.showToast({ + title: '椤圭洰閰嶇疆閿欒', + icon: 'none' + }); + return; + } + + // 妫�鏌ユ槸鍚﹀垏鎹簡椤圭洰锛堝鏋滃綋鍓嶉」鐩笉鍚屼簬鏂伴�夋嫨鐨勯」鐩級 + const isProjectChanged = currentProject && currentProject !== newProject; + + // 娣诲姞浜屾纭 + const confirmText = isProjectChanged ? + `纭畾瑕佸皢椤圭洰浠�"${PROJECT_CONFIG[currentProject]?.displayName || '褰撳墠椤圭洰'}"鍒囨崲鍒�"${projectConfig.displayName}"鍚楋紵` : + `纭畾閫夋嫨"${projectConfig.displayName}"椤圭洰鍚楋紵`; + + wx.showModal({ + title: isProjectChanged ? '纭鍒囨崲椤圭洰' : '纭閫夋嫨椤圭洰', + content: confirmText, + confirmText: isProjectChanged ? '纭鍒囨崲' : '纭', + cancelText: '鍙栨秷', + success: (res) => { + if (res.confirm) { + // 鐢ㄦ埛纭閫夋嫨锛岀户缁鐞� + this.processProjectSelection(currentProject, newProject, projectConfig, isProjectChanged); + } else { + // 鐢ㄦ埛鍙栨秷锛屼笉杩涜浠讳綍鎿嶄綔 + console.log('鐢ㄦ埛鍙栨秷浜嗛」鐩�夋嫨'); + } + } + }); + }, + + // 澶勭悊椤圭洰閫夋嫨鐨勫悗缁搷浣� + processProjectSelection(currentProject, newProject, projectConfig, isProjectChanged) { + // 濡傛灉鍒囨崲浜嗛」鐩紝鍏堟竻闄ょ櫥褰曠姸鎬� + if (isProjectChanged) { + console.log(`姝e湪浠庨」鐩� ${currentProject} 鍒囨崲鍒� ${newProject}锛屽皢娓呴櫎鐧诲綍鐘舵�乣); + + // 娓呴櫎鍏ㄥ眬鐧诲綍鐘舵�� + getApp().globalData.sessionId = ''; + getApp().globalData.clientId = ''; + getApp().globalData.isLoggedIn = false; + getApp().globalData.userInfo = null; + getApp().globalData.vcId = ''; + getApp().globalData.operator = ''; + + // 娓呴櫎瀛樺偍涓殑鐧诲綍鐘舵�� + try { + // 娓呴櫎鍩烘湰鐧诲綍鏁版嵁 + wx.removeStorageSync('sessionId'); + wx.removeStorageSync('clientId'); + wx.removeStorageSync('userData'); + wx.removeStorageSync('isLoggedIn'); + + // 娓呴櫎涔嬪墠椤圭洰鐨勭壒瀹氭暟鎹� + if (currentProject) { + wx.removeStorageSync(`${currentProject}_params`); + } + + // 娓呴櫎鍏朵粬鍙兘鐨勭紦瀛樻暟鎹� + wx.removeStorageSync('_attempted_login_redirect'); + + console.log('宸叉竻闄ょ櫥褰曠浉鍏崇殑瀛樺偍鏁版嵁'); + } catch (e) { + console.error('娓呴櫎瀛樺偍鏁版嵁澶辫触:', e); + } + + // 閲嶇疆UI鏄剧ず鐘舵�� + if (projectConfig.needLogin === false) { + // 涓嶉渶瑕佺櫥褰曠殑椤圭洰锛屾樉绀洪」鐩悕绉颁綔涓簎serName + this.setData({ + userName: projectConfig.displayName, + userPhone: "", + listData: [] + }); + } else { + // 闇�瑕佺櫥褰曠殑椤圭洰锛屾樉绀�"璇风偣鍑荤櫥褰�" + this.setData({ + userName: "璇风偣鍑荤櫥褰�", + userPhone: "", + listData: [] + }); + } + } + + // 淇濆瓨椤圭洰閫夋嫨鍒版湰鍦板瓨鍌� + storage.setItem('selectedProject', newProject).then(() => { + // 璋冪敤setBaseUrl鏉ユ洿鏂板熀纭�URL + try { + console.log('灏濊瘯璁剧疆鍩虹URL锛岄」鐩�:', newProject); + const result = config.setBaseUrl(newProject); + console.log('璁剧疆鍩虹URL缁撴灉:', result); + } catch (error) { + console.error('璁剧疆鍩虹URL鍑洪敊:', error); + // 缁х画鎵ц锛屼笉涓柇娴佺▼ + } + + // 鏇存柊鍏ㄥ眬鍙橀噺 + getApp().globalData = getApp().globalData || {}; + getApp().globalData.selectedProject = newProject; + getApp().globalData.baseUrl = projectConfig.serverUrl; + getApp().globalData.serverId = projectConfig.serverId; + + // 閫氳繃閰嶇疆瀵硅薄缁熶竴璁剧疆椤圭洰鍙傛暟 + getApp().globalData.tag = projectConfig.tag; + + // 瀵逛簬涓嶉渶瑕佺櫥褰曠殑椤圭洰锛岀洿鎺ヨ缃畂perator鍜宑lientId + if (!projectConfig.needLogin && projectConfig.operatorId) { + const operatorId = projectConfig.operatorId; + getApp().globalData.operator = operatorId; + getApp().globalData.clientId = operatorId; + getApp().globalData.isLoggedIn = true; + getApp().globalData.sessionId = operatorId; + + // 濡傛灉鏈塿cId锛屼篃璁剧疆 + if (projectConfig.vcId) { + getApp().globalData.vcId = projectConfig.vcId; + } + + // 鎸佷箙鍖栧瓨鍌ㄩ」鐩弬鏁� + const params = { + operator: operatorId, + clientId: operatorId, + isLoggedIn: true, + sessionId: operatorId + }; + + if (projectConfig.vcId) { + params.vcId = projectConfig.vcId; + } + + storage.setItem(`${newProject}_params`, params); + } + + console.log('宸插垏鎹㈠埌椤圭洰:', projectConfig.displayName, '鏈嶅姟鍣�:', projectConfig.serverId, 'tag:', getApp().globalData.tag); + + this.setData({ + showProjectDialog: false + }); + + // 鏄剧ず鍒囨崲鎴愬姛鎻愮ず + wx.showToast({ + title: `宸查�夋嫨${projectConfig.displayName}`, + icon: 'success', + duration: 2000 + }); + setTimeout(() => { + console.log('椤圭洰宸插垏鎹紝姝e湪鍒濆鍖栨暟鎹�'); + // 纭繚鏄剧ず姝g‘鐨勭敤鎴峰悕 + if (!projectConfig.needLogin) { + this.setData({ + userName: projectConfig.displayName + }); + } else { + this.setData({ + userName: "璇风偣鍑荤櫥褰�" + }); + } + this.initData(); + }, 1000); + + }).catch(err => { + console.error('淇濆瓨椤圭洰閫夋嫨澶辫触锛�', err); + wx.showToast({ + title: '淇濆瓨澶辫触锛岃閲嶈瘯', + icon: 'none', + duration: 2000 + }); + }); + }, + + // 妫�鏌ョ櫥褰曠姸鎬� + checkLoginStatus() { + const app = getApp(); + + // 妫�鏌ユ槸鍚﹀凡鐧诲綍 + if (app.globalData.isLoggedIn && app.globalData.sessionId) { + console.log('宸蹭粠鍏ㄥ眬鍙橀噺妫�娴嬪埌鐧诲綍鐘舵��'); + return; + } + + // 妫�鏌ユ湰椤甸潰鏄惁姝e湪澶勭悊杩斿洖閫昏緫 + const fromLogin = this.getFromLogin(); + if (fromLogin) { + console.log('浠庣櫥褰曢〉杩斿洖锛屼笉鍐嶉噸瀹氬悜'); + return; + } + + // 妫�鏌ュ綋鍓嶉」鐩槸鍚﹂渶瑕佺櫥褰� + const currentProject = app.globalData.selectedProject; + if (currentProject && PROJECT_CONFIG[currentProject] && !PROJECT_CONFIG[currentProject].needLogin) { + console.log('褰撳墠椤圭洰涓嶉渶瑕佺櫥褰�:', currentProject); + 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 + }); + 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; + } + + // 妫�鏌ラ」鐩槸鍚﹂渶瑕佺櫥褰� + if (currentProject && PROJECT_CONFIG[currentProject] && !PROJECT_CONFIG[currentProject].needLogin) { + console.log('鏈�缁堟鏌�: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰�:', currentProject); + return; + } + + console.log('纭闇�瑕佽烦杞埌鐧诲綍椤�'); + + // 璺宠浆鍓嶅啀娆℃鏌ョ櫥褰曢〉闈复鏃舵爣璁� + try { + 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) + // }); + } + }) + .catch(err => { + console.error('妫�鏌ョ櫥褰曠姸鎬佹椂鍑洪敊:', err); + + // 鏍囪褰撳墠椤甸潰姝e湪澶勭悊杩斿洖閫昏緫 + this.setData({ + isFromLogin: true + }); + + // 鍐嶆妫�鏌ユ槸鍚﹀凡浠庣櫥褰曢〉杩斿洖 + if (this.getFromLogin()) { + console.log('閿欒澶勭悊: 宸蹭粠鐧诲綍椤佃繑鍥烇紝涓嶅啀璺宠浆'); + return; } + // 妫�鏌ラ」鐩槸鍚﹂渶瑕佺櫥褰� + if (currentProject && PROJECT_CONFIG[currentProject] && !PROJECT_CONFIG[currentProject].needLogin) { + console.log('閿欒澶勭悊: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰�:', currentProject); + 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; + } + // 褰撳紑闃�鎴愬姛鍚庤皟鐢ㄥ埛鏂� + 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) { - wx.showLoading({ - title: '姝e湪鐧诲綍璇风◢鍊�...', - mask: true - }); + console.log('寤惰繜妫�鏌ワ細鏈櫥褰曚笖涓嶆槸浠庣櫥褰曢〉杩斿洖锛屾墽琛岀櫥褰曠姸鎬佹鏌�'); + this.checkLoginStatus(); + } + }, 500); + } else { + console.log('浠庣櫥褰曢〉杩斿洖锛屼笉妫�鏌ョ櫥褰曠姸鎬�'); + } + }, - wx.login({ - success: (res) => { - if (res.code) { - // 灏哻ode鍙戦�佸埌鏈嶅姟鍣ㄨ幏鍙杘penid - 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; + // 寰俊鐧诲綍 + wxLogin() { + // 妫�鏌ュ綋鍓嶉」鐩槸鍚﹂渶瑕佺櫥褰� + const currentProject = getApp().globalData.selectedProject; + if (currentProject && PROJECT_CONFIG[currentProject]) { + const projectConfig = PROJECT_CONFIG[currentProject]; + + if (!projectConfig.needLogin) { + console.log('wxLogin: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰�:', currentProject); + // 涓嶉渶瑕佺櫥褰曠殑椤圭洰锛屾樉绀洪」鐩悕绉� + this.setData({ + userName: projectConfig.displayName + }); + return; + } + } - // 璁剧疆鍏ㄥ眬鍙橀噺 - getApp().globalData.sessionId = sessionId; - getApp().globalData.clientId = clientId; - getApp().globalData.isLoggedIn = true; + if (!getApp().globalData.isLoggedIn) { + wx.showLoading({ + title: '姝e湪鐧诲綍璇风◢鍊�...', + mask: true + }); - // 璁剧疆姝g‘鐨勯」鐩畉ag - const projectConfig = PROJECT_CONFIG[this.data.selectedProject]; - if (projectConfig) { - getApp().globalData.tag = projectConfig.tag; - } + wx.login({ + success: (res) => { + if (res.code) { + // 灏哻ode鍙戦�佸埌鏈嶅姟鍣ㄨ幏鍙杘penid + post({ + url: "wx/client/code_login", + data: { + code: res.code + } + }).then(response => { + wx.hideLoading(); + if (response.code === "0001") { + if (response.content.client.clientId === "") { + // 鏈粦瀹氳处鍙凤紝璺宠浆鍒扮櫥褰曢〉闈㈠苟浼犻�掑綋鍓嶉」鐩俊鎭� + const projectInfo = PROJECT_CONFIG[this.data.selectedProject]; + wx.navigateTo({ + url: `/pages/login/login?project=${this.data.selectedProject}&projectName=${projectInfo.displayName}` + }); + } 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; - // 淇濆瓨鍒板瓨鍌� - storage.setItem("sessionId", sessionId); - storage.setItem("clientId", clientId); - storage.setItem("isLoggedIn", "true"); + // 璁剧疆鍏ㄥ眬鍙橀噺 + getApp().globalData.sessionId = sessionId; + getApp().globalData.clientId = clientId; + getApp().globalData.isLoggedIn = true; - // 淇濆瓨userData淇℃伅锛屽寘鍚玸essionId鍜宼ag - const userData = JSON.stringify({ - sessionId: sessionId, - tag: projectConfig ? projectConfig.tag : 'ym', - 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:', projectConfig ? projectConfig.tag : 'ym'); - this.initData(); - }) - .catch(err => { - console.warn('淇濆瓨userData澶辫触锛屼絾缁х画鍒濆鍖�:', err); - this.initData(); - }); + // 璁剧疆姝g‘鐨勯」鐩畉ag + const projectConfig = PROJECT_CONFIG[this.data.selectedProject]; + if (projectConfig) { + getApp().globalData.tag = projectConfig.tag; + } - } - } 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' + // 淇濆瓨鍒板瓨鍌� + storage.setItem("sessionId", sessionId); + storage.setItem("clientId", clientId); + storage.setItem("isLoggedIn", "true"); + + // 淇濆瓨userData淇℃伅锛屽寘鍚玸essionId鍜宼ag + const userData = JSON.stringify({ + sessionId: sessionId, + tag: projectConfig ? projectConfig.tag : 'ym', + 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:', projectConfig ? projectConfig.tag : 'ym'); + this.initData(); + }) + .catch(err => { + console.warn('淇濆瓨userData澶辫触锛屼絾缁х画鍒濆鍖�:', err); + this.initData(); }); + } + } else if (response.code === "1003") { + // 鏈粦瀹氳处鍙凤紝璺宠浆鍒扮櫥褰曢〉闈㈠苟浼犻�掑綋鍓嶉」鐩俊鎭� + const projectInfo = PROJECT_CONFIG[this.data.selectedProject]; + wx.navigateTo({ + url: `/pages/login/login?project=${this.data.selectedProject}&projectName=${projectInfo.displayName}` + }); + } else { + wx.showToast({ + title: '鐧诲綍澶辫触', + icon: 'error', + duration: 2000 + }); + } + }).catch(error => { + wx.hideLoading(); + console.error('鐧诲綍璇锋眰澶辫触:', error); + if(error.code==="1003"){ + // 鏈粦瀹氳处鍙凤紝璺宠浆鍒扮櫥褰曢〉闈㈠苟浼犻�掑綋鍓嶉」鐩俊鎭� + const projectInfo = PROJECT_CONFIG[this.data.selectedProject]; + wx.navigateTo({ + url: `/pages/login/login?project=${this.data.selectedProject}&projectName=${projectInfo.displayName}` + }); + }else{ + wx.showToast({ + title: '鐧诲綍澶辫触锛岃閲嶈瘯', + icon: 'none' + }); + } }); - } - }, - - // 杈呭姪鍑芥暟锛氭竻鐞嗕复鏃舵爣璁� - 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湪瑙g粦璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧 - mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false - }); - const data = { - sessionId: getApp().globalData.sessionId //鍙栨按鍙D - }; - post({ - url: 'wx/client/unbind', - data: data, - useParams: true - }).then(response => { - // 澶勭悊鎴愬姛鍝嶅簲 - console.log('璇锋眰鎴愬姛:', response); - // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + } else { wx.hideLoading(); - 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({ - userName: "璇风偣鍑荤櫥褰�", - userPhone: "", - listData: [] - }); - }) - .catch(err => { - console.error('瑙g粦杩囩▼涓嚭閿�:', err); - wx.showToast({ - title: '瑙g粦澶辫触锛岃閲嶈瘯', - icon: 'none', - duration: 2000 - }); - }); - }).catch(error => { - // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� - wx.hideLoading(); - // 澶勭悊閿欒鍝嶅簲 - console.error('璇锋眰澶辫触:', error); + console.log('鐧诲綍澶辫触锛�' + res.errMsg); wx.showToast({ - title: '瑙g粦澶辫触', - icon: 'error', - duration: 3000 - }) + title: '寰俊鐧诲綍澶辫触', + icon: 'none' + }); + } + }, + fail: (err) => { + wx.hideLoading(); + console.error('寰俊鐧诲綍API璋冪敤澶辫触:', err); + wx.showToast({ + title: '鐧诲綍澶辫触锛岃閲嶈瘯', + icon: 'none' + }); + } + }); + } + }, + + // 杈呭姪鍑芥暟锛氭竻鐞嗕复鏃舵爣璁� + cleanupTempMarkers() { + // 鍙湁鍦╥sFromLogin涓簍rue鏃舵墠杩涜娓呯悊 + if (this.data.isFromLogin) { + + + // 閲嶈isFromLogin涓篺alse锛屼絾娣诲姞寤惰繜锛岄伩鍏嶅奖鍝嶅綋鍓嶉〉闈㈢殑杩斿洖閫昏緫 + setTimeout(() => { + this.setData({ + isFromLogin: false }); - }, - onShareAppMessage: function (options) { - // 璁剧疆鍒嗕韩鍐呭 - return { - title: '澶х鐏屾簤鍔╂墜', // 鍒嗕韩鏍囬 - path: '/pages/home/home', // 鍒嗕韩璺緞锛岃璺緞闇�瑕佹槸褰撳墠灏忕▼搴忓瓨鍦ㄧ殑椤甸潰璺緞 - imageUrl: '/images/logo2.jpg', // 鍒嗕韩鍥炬爣锛屽彲浠ユ槸缃戠粶鍥剧墖璺緞鎴栨湰鍦板浘鐗囪矾寰� - success: function (res) { - // 鍒嗕韩鎴愬姛鐨勫洖璋冨嚱鏁� - }, - fail: function (res) { - // 鍒嗕韩澶辫触鐨勫洖璋冨嚱鏁� - } - }; - }, - //鐐瑰嚮鎻愮ず鎸夐挳 - infoShow() { - this.setData({ - showInfoDialog: true + console.log('閲嶇疆isFromLogin=false'); + }, 5000); + } + }, //纭瑙g粦 + unBindPost() { + this.setData({ + showUnBind: false + }) + wx.showLoading({ + title: '姝e湪瑙g粦璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧 + mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false + }); + const data = { + sessionId: getApp().globalData.sessionId //鍙栨按鍙D + }; + post({ + url: 'wx/client/unbind', + data: data, + useParams: true + }).then(response => { + // 澶勭悊鎴愬姛鍝嶅簲 + console.log('璇锋眰鎴愬姛:', response); + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + 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({ + userName: "璇风偣鍑荤櫥褰�", + userPhone: "", + listData: [] + }); }) - }, - //鎻愮ず绐楃‘璁ゆ寜閽� - confirmBtnInfoDialog() { - this.setData({ - showInfoDialog: false - }) - }, + .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) { + // 鍒嗕韩澶辫触鐨勫洖璋冨嚱鏁� + } + }; + }, + //鐐瑰嚮鎻愮ず鎸夐挳 + infoShow() { + this.setData({ + showInfoDialog: true + }) + }, + //鎻愮ず绐楃‘璁ゆ寜閽� + confirmBtnInfoDialog() { + this.setData({ + showInfoDialog: false + }) + }, //寮哄埗鍒犻櫎 onDelete(e) { const item = e.currentTarget.dataset.item; const that = this; - + if (this.data.useTestData) { // 娴嬭瘯鏁版嵁妯″紡涓嬶紝妯℃嫙鍒犻櫎鎿嶄綔 wx.showLoading({ - title: '姝e湪寮哄埗鍒犻櫎璇风◢鍊�...', - mask: true + title: '姝e湪寮哄埗鍒犻櫎璇风◢鍊�...', + mask: true }); - + // 妯℃嫙璇锋眰寤惰繜 setTimeout(() => { wx.hideLoading(); - + // 浠庡垪琛ㄤ腑绉婚櫎琚垹闄ょ殑椤� - const updatedList = this.data.listData.filter(listItem => + const updatedList = this.data.listData.filter(listItem => listItem.orderNo !== item.orderNo ); - + this.setData({ listData: updatedList }); - + wx.showToast({ title: '鍒犻櫎鎴愬姛', icon: 'success', @@ -1623,7 +1678,7 @@ }, 1500); return; } - + wx.showLoading({ title: '姝e湪寮哄埗鍒犻櫎璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧 mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false @@ -1666,7 +1721,7 @@ } else { time = this.extractTime(item.dt) } - if (item.waterInstant===null) { + if (item.waterInstant === null) { item.waterInstant = "鏆傛棤" } @@ -1682,62 +1737,62 @@ listData: updatedList }); }, - //澶勭悊鏃堕棿鍘绘帀骞存湀鏃� - extractTime(datetimeString) { - const formattedDate = datetimeString.replace(" ", "T"); - const date = new Date(formattedDate); - // 鑾峰彇灏忔椂銆佸垎閽熷拰绉� - const hours = date.getHours().toString().padStart(2, '0'); - const minutes = date.getMinutes().toString().padStart(2, '0'); - const seconds = date.getSeconds().toString().padStart(2, '0'); - return `${hours}:${minutes}:${seconds}`; - }, - - // 鍒囨崲椤圭洰 - switchProject(e) { - const project = e.currentTarget.dataset.project; - - if (config.setBaseUrl(project)) { - this.setData({ - selectedProject: project - }); - - // 淇濆瓨閫夋嫨鍒版湰鍦板瓨鍌� - try { - wx.setStorageSync('selectedProject', project); - } catch (e) { - console.error('淇濆瓨椤圭洰閫夋嫨澶辫触:', e); + //澶勭悊鏃堕棿鍘绘帀骞存湀鏃� + extractTime(datetimeString) { + const formattedDate = datetimeString.replace(" ", "T"); + const date = new Date(formattedDate); + // 鑾峰彇灏忔椂銆佸垎閽熷拰绉� + const hours = date.getHours().toString().padStart(2, '0'); + const minutes = date.getMinutes().toString().padStart(2, '0'); + const seconds = date.getSeconds().toString().padStart(2, '0'); + return `${hours}:${minutes}:${seconds}`; + }, + + // 鍒囨崲椤圭洰 + switchProject(e) { + const project = e.currentTarget.dataset.project; + + if (config.setBaseUrl(project)) { + this.setData({ + selectedProject: project + }); + + // 淇濆瓨閫夋嫨鍒版湰鍦板瓨鍌� + try { + wx.setStorageSync('selectedProject', project); + } catch (e) { + console.error('淇濆瓨椤圭洰閫夋嫨澶辫触:', e); + } + + // 鏇存柊鍏ㄥ眬鍙橀噺 + const app = getApp(); + if (app && app.globalData) { + app.globalData.selectedProject = project; + + // 鏍规嵁椤圭洰閰嶇疆璁剧疆鐩稿叧鍙傛暟 + const projectConfig = PROJECT_CONFIG[project]; + if (projectConfig) { + app.globalData.tag = projectConfig.tag; + if (!projectConfig.needLogin) { + app.globalData.operator = projectConfig.operatorId; + app.globalData.clientId = projectConfig.operatorId; + app.globalData.isLoggedIn = true; + app.globalData.sessionId = projectConfig.operatorId; + // 濡傛灉鏈塿cId锛屼篃璁剧疆 + if (projectConfig.vcId) { + app.globalData.vcId = projectConfig.vcId; } - - // 鏇存柊鍏ㄥ眬鍙橀噺 - const app = getApp(); - if (app && app.globalData) { - app.globalData.selectedProject = project; - - // 鏍规嵁椤圭洰閰嶇疆璁剧疆鐩稿叧鍙傛暟 - const projectConfig = PROJECT_CONFIG[project]; - if (projectConfig) { - app.globalData.tag = projectConfig.tag; - if (!projectConfig.needLogin) { - app.globalData.operator = projectConfig.operatorId; - app.globalData.clientId = projectConfig.operatorId; - app.globalData.isLoggedIn = true; - app.globalData.sessionId = projectConfig.operatorId; - // 濡傛灉鏈塿cId锛屼篃璁剧疆 - if (projectConfig.vcId) { - app.globalData.vcId = projectConfig.vcId; - } - } - } - } - - // 閲嶆柊鍔犺浇椤甸潰鏁版嵁 - this.initData(); - } else { - wx.showToast({ - title: '鍒囨崲椤圭洰澶辫触', - icon: 'none' - }); + } } - }, + } + + // 閲嶆柊鍔犺浇椤甸潰鏁版嵁 + this.initData(); + } else { + wx.showToast({ + title: '鍒囨崲椤圭洰澶辫触', + icon: 'none' + }); + } + }, }) \ No newline at end of file diff --git a/pages/home/home.wxml b/pages/home/home.wxml index 327b1dd..97715ff 100644 --- a/pages/home/home.wxml +++ b/pages/home/home.wxml @@ -3,7 +3,13 @@ <view class="head-wrapper"> <view class="head-top"> - <t-avatar class="avatar-example" image="{{image}}" size="120rpx" bind:tap="handleAvatarTap" /> + <view class="avatar-project-container"> + + <t-avatar class="avatar-example" image="{{image}}" size="120rpx" bind:tap="handleAvatarTap" /> + <view class="current-project"> + <text>{{ projectConfig[selectedProject].displayName }}</text> + </view> + </view> <view class="head-text-wrapper"> <text bind:tap="wxLogin">{{userName}}</text> <text class="head-bottom">{{userPhone}}</text> diff --git a/pages/home/home.wxss b/pages/home/home.wxss index 4f09e97..71b6d7c 100644 --- a/pages/home/home.wxss +++ b/pages/home/home.wxss @@ -38,6 +38,7 @@ align-items: left; justify-content: center; margin-left: 15rpx; + margin-bottom: 70rpx; } .head-button-wrapper { @@ -752,4 +753,44 @@ font-size: 32rpx; color: #888; } + +.current-project { + display: flex; + flex-direction: column; + justify-content: center; + margin-left: 20rpx; + margin-right: 10rpx; + margin-top: 10rpx; +} + +.current-project text { + font-size: 28rpx; + color: #ffffff; + font-weight: bold; + background-color: rgba(255, 255, 255, 0.2); + border-radius: 15rpx; + padding: 6rpx 14rpx; +} + +.avatar-project-container { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; +} + +.current-project { + display: flex; + justify-content: center; + margin-bottom: 10rpx; +} + +.current-project text { + font-size: 28rpx; + color: #ffffff; + font-weight: bold; + background-color: rgba(255, 255, 255, 0.2); + border-radius: 15rpx; + padding: 6rpx 14rpx; +} \ No newline at end of file diff --git a/pages/irrigation/irrigation.js b/pages/irrigation/irrigation.js index e30bf8d..1a6493f 100644 --- a/pages/irrigation/irrigation.js +++ b/pages/irrigation/irrigation.js @@ -347,7 +347,8 @@ planId: id, operatorId: app.globalData.clientId }, - isShowLoding: true + isShowLoding: true, + timeout: 180000 }).then(res => { if (res.success) { wx.showToast({ @@ -449,7 +450,8 @@ planId: planID, operatorId: app.globalData.clientId }, - isShowLoding: true + isShowLoding: true, + timeout: 180000 }).then(res => { if (res.success) { wx.showToast({ diff --git a/pages/login/login.js b/pages/login/login.js index 6d237be..090adb9 100644 --- a/pages/login/login.js +++ b/pages/login/login.js @@ -185,12 +185,11 @@ manualNavigate: false // 鏍囪鏄惁鏄�氳繃缂栫▼鏂瑰紡瀵艰埅鐨� }); - // 鑾峰彇閫夋嫨鐨勯」鐩� - 浼樺厛浣跨敤URL鍙傛暟 + // 浠嶶RL鍙傛暟鑾峰彇椤圭洰淇℃伅 if (options && options.project) { const project = options.project; - const projectName = project === 'JYG' ? '鍢夊唱鍏抽」鐩�' : - project === 'MQ' ? '姘戝嫟椤圭洰' : - project === 'TEST' ? '娴嬭瘯椤圭洰' : '鏈煡椤圭洰'; + // 鐩存帴浣跨敤浼犲叆鐨勯」鐩悕绉帮紝涓嶅啀鎵嬪姩杞崲 + const projectName = options.projectName || '榛樿椤圭洰'; console.log(`浠嶶RL鍙傛暟鑾峰彇椤圭洰淇℃伅: ${project} (${projectName})`); @@ -218,30 +217,8 @@ console.error('璁剧疆baseUrl澶辫触:', e); } } - - // 淇濆瓨椤圭洰閫夋嫨鍒版湰鍦板瓨鍌紝纭繚椤圭洰淇℃伅涓�鑷� - storage.setItem('selectedProject', project) - .then(() => console.log('鎴愬姛淇濆瓨椤圭洰閫夋嫨鍒板瓨鍌�')) - .catch(err => console.error('淇濆瓨椤圭洰閫夋嫨鍒板瓨鍌ㄥけ璐�:', err)); } else { - // 浠庢湰鍦板瓨鍌ㄨ幏鍙栧凡閫夋嫨鐨勯」鐩� - storage.getItemSafe('selectedProject').then(project => { - if (project) { - const projectName = project === 'JYG' ? '鍢夊唱鍏抽」鐩�' : - project === 'MQ' ? '姘戝嫟椤圭洰' : - project === 'TEST' ? '娴嬭瘯椤圭洰' : '鏈煡椤圭洰'; - console.log(`浠庡瓨鍌ㄨ幏鍙栭」鐩俊鎭�: ${project} (${projectName})`); - - this.setData({ - selectedProject: project, - projectName: projectName - }); - } else { - console.log('鏈壘鍒板凡閫夋嫨鐨勯」鐩紝浣跨敤榛樿椤圭洰'); - } - }).catch(err => { - console.error('鑾峰彇宸查�夋嫨椤圭洰澶辫触:', err); - }); + console.log('鏈粠URL鑾峰彇鍒伴」鐩俊鎭紝浣跨敤榛樿鍊�'); } }, @@ -327,41 +304,9 @@ } }, - // 澶囩敤鐨勮繑鍥為椤垫柟娉� - backupReturnToHome() { - console.log('浣跨敤澶囩敤鏂规硶杩斿洖棣栭〉'); + - // 灏濊瘯浣跨敤switchTab锛堝鏋滈椤靛湪tabBar涓級 - const useReLaunch = () => { - console.log('浣跨敤reLaunch杩斿洖棣栭〉'); - wx.reLaunch({ - url: '/pages/home/home?fromLogin=true', - success: () => console.log('reLaunch鎴愬姛杩斿洖棣栭〉'), - fail: (err) => { - console.error('reLaunch杩斿洖棣栭〉澶辫触:', err); - // 鏈�鍚庣殑澶囩敤鏂规锛氫娇鐢╮edirectTo - setTimeout(() => { - console.log('寤惰繜浣跨敤redirectTo灏濊瘯杩斿洖棣栭〉'); - wx.redirectTo({ - url: '/pages/home/home?fromLogin=true', - success: () => console.log('redirectTo鎴愬姛杩斿洖棣栭〉'), - fail: (err) => console.error('鎵�鏈夎繑鍥炴柟娉曢兘澶辫触:', err) - }); - }, 100); - } - }); - }; - - // 鍏堝皾璇曚娇鐢╯witchTab锛堟煇浜涚増鏈彲鑳藉皢棣栭〉璁剧疆涓簍abBar锛� - wx.switchTab({ - url: '/pages/home/home', - success: () => console.log('switchTab鎴愬姛杩斿洖棣栭〉'), - fail: (err) => { - console.log('switchTab澶辫触锛堝彲鑳介椤典笉鍦╰abBar涓級:', err); - useReLaunch(); - } - }); - }, + /** * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 @@ -469,11 +414,6 @@ getApp().globalData.clientId = String(data.content.clientId); storage.setItem("clientId", String(data.content.clientId)); - // 璁剧疆褰撳墠椤圭洰鐨則ag - const tag = this.data.selectedProject === 'JYG' ? 'ym' : - this.data.selectedProject === 'MQ' ? 'mq' : - this.data.selectedProject === 'TEST' ? 'test' : 'unknown'; - getApp().globalData.tag = tag; // 淇濆瓨鐢ㄦ埛淇℃伅 const userInfo = { @@ -481,8 +421,7 @@ clientId: String(data.content.clientId), phone: this.data.phone, token: data.content.token || '', - project: this.data.selectedProject, - tag: tag + project: this.data.selectedProject }; // 淇濆瓨鍒板叏灞�鍙橀噺 @@ -554,7 +493,7 @@ wx.redirectTo({ url: '/pages/home/home' }); - }, 1500); + }); } }); }, diff --git a/pages/login/login.wxml b/pages/login/login.wxml index cef1f9f..b45afd7 100644 --- a/pages/login/login.wxml +++ b/pages/login/login.wxml @@ -25,7 +25,7 @@ </view> </view> - <view class="project-info {{selectedProject === 'MQ' ? 'mq' : 'jyg'}}"> + <view class="project-info"> <text>褰撳墠椤圭洰: {{projectName}}</text> </view> diff --git a/pages/waterIntake/waterIntake.js b/pages/waterIntake/waterIntake.js index 9305679..78ce934 100644 --- a/pages/waterIntake/waterIntake.js +++ b/pages/waterIntake/waterIntake.js @@ -238,14 +238,14 @@ isRefreshing_all: false }); if (data.success && data.code === "0001") { - if (!data.content) { + if (!data.content || data.content.itemTotal === 0 || !data.content.obj || data.content.obj.length === 0) { wx.showToast({ title: '娌℃湁鎼滅储鍒板彇姘村彛', icon: 'error', }) } else { this.setData({ - allWaterPoints: [data.content] + allWaterPoints: data.content.obj }); } diff --git a/utils/projectConfig.js b/utils/projectConfig.js index 4c14689..8bae1d0 100644 --- a/utils/projectConfig.js +++ b/utils/projectConfig.js @@ -31,9 +31,8 @@ TEST: { tag: 'ym', displayName: '娴嬭瘯椤圭洰', - operatorId: '2024122617295800009', // 缁熶竴ID鐢ㄤ簬operator鍜宑lientId - vcId: '2024122617295800009', - needLogin: false, // 涓嶉渶瑕佺櫥褰� + operatorId: '', // 缁熶竴ID鐢ㄤ簬operator鍜宑lientId + needLogin: true, // 闇�瑕佺櫥褰� serverId: '166', get serverUrl() { return SERVER_INFO.URL_166; @@ -42,8 +41,8 @@ JC: { tag: 'jc', displayName: '閲戞槍椤圭洰', - operatorId: '2025041710412400006', // 缁熶竴ID鐢ㄤ簬operator鍜宑lientId - needLogin: false, // 涓嶉渶瑕佺櫥褰� + operatorId: '', // 缁熶竴ID鐢ㄤ簬operator鍜宑lientId 2025041710412400006 + needLogin: true, // 闇�瑕佺櫥褰� serverId: '121', get serverUrl() { return SERVER_INFO.URL_121; @@ -51,49 +50,9 @@ }, GSCLT: { tag: 'test', - displayName: '鐢樿們鍐滅闄�-宕旈緳澶�', - operatorId: '2025041912201400006', // 缁熶竴ID鐢ㄤ簬operator鍜宑lientId - needLogin: false, // 涓嶉渶瑕佺櫥褰� - serverId: '233', - get serverUrl() { - return SERVER_INFO.URL_233; - } - }, - GSWJ: { - tag: 'test', - displayName: '鐢樿們鍐滅闄�-鐜嬪', - operatorId: '2025042115424500006', // 缁熶竴ID鐢ㄤ簬operator鍜宑lientId - needLogin: false, // 涓嶉渶瑕佺櫥褰� - serverId: '233', - get serverUrl() { - return SERVER_INFO.URL_233; - } - }, - GSCLT2: { - tag: 'test', - displayName: '鐢樿們鍐滅闄�-鏅佺帀浜�', - operatorId: '2025042115452400006', // 缁熶竴ID鐢ㄤ簬operator鍜宑lientId - needLogin: false, // 涓嶉渶瑕佺櫥褰� - serverId: '233', - get serverUrl() { - return SERVER_INFO.URL_233; - } - }, - GSCLT3: { - tag: 'test', - displayName: '鐢樿們鍐滅闄�-榛勮檸鐢�', - operatorId: '2025042115454100006', // 缁熶竴ID鐢ㄤ簬operator鍜宑lientId - needLogin: false, // 涓嶉渶瑕佺櫥褰� - serverId: '233', - get serverUrl() { - return SERVER_INFO.URL_233; - } - }, - GSCLT4: { - tag: 'test', - displayName: '鐢樿們鍐滅闄�-鏈卞厗瀹�', - operatorId: '2025042115455900006', // 缁熶竴ID鐢ㄤ簬operator鍜宑lientId - needLogin: false, // 涓嶉渶瑕佺櫥褰� + displayName: '鐢樿們鍐滅闄�', + operatorId: '', // 缁熶竴ID鐢ㄤ簬operator鍜宑lientId + needLogin: true, // 涓嶉渶瑕佺櫥褰� serverId: '233', get serverUrl() { return SERVER_INFO.URL_233; -- Gitblit v1.8.0