From dc49b96b835326a64056da9da0b43eabd2d96e32 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期五, 25 七月 2025 19:37:11 +0800
Subject: [PATCH] 常用取水口列表搜索接口兼容性
---
pages/home/home.js | 1138 ++++++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 887 insertions(+), 251 deletions(-)
diff --git a/pages/home/home.js b/pages/home/home.js
index 773340d..a7d4ac1 100644
--- a/pages/home/home.js
+++ b/pages/home/home.js
@@ -4,9 +4,14 @@
get,
post
} = require('../../api/request.js');
+const config = require('../../api/config.js');
const {
- PROJECT_URLS
-} = require('../../api/config.js');
+ PROJECT_CONFIG
+} = require('../../utils/projectConfig.js');
+const {
+ ENV
+} = require('../../api/env.js');
+
Page({
/**
@@ -34,32 +39,64 @@
lastIntakeName: "",
showProjectDialog: false,
selectedProject: '',
+ tempSelectedProject: '', // 娣诲姞涓存椂閫夋嫨鍙橀噺锛岀敤浜庝繚瀛樼敤鎴峰湪瀵硅瘽妗嗕腑閫夋嫨浣嗗皻鏈‘璁ょ殑椤圭洰
avatarTapCount: 0,
isFromLogin: false,
- showTipDialog: ''
+ 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'
- })
+ // 妫�鏌ュ綋鍓嶉」鐩槸鍚﹂渶瑕佺櫥褰�
+ const currentProject = app.globalData.selectedProject;
+ if (currentProject && PROJECT_CONFIG[currentProject] && PROJECT_CONFIG[currentProject].needLogin) {
+ // 闇�瑕佺櫥褰曠殑椤圭洰锛屾鏌ユ槸鍚﹀凡鐧诲綍
+ if (!app.globalData.isLoggedIn) {
+ // 鏈櫥褰曪紝鏄剧ず鎻愮ず骞堕樆姝㈡搷浣�
+ wx.showToast({
+ title: '璇峰厛鐧诲綍',
+ icon: 'error',
+ duration: 2000
+ });
+
+ // 鑾峰彇椤圭洰閰嶇疆
+ const projectConfig = PROJECT_CONFIG[currentProject];
+ if (projectConfig) {
+ // 璇㈤棶鐢ㄦ埛鏄惁鍓嶅線鐧诲綍
+ wx.showModal({
+ title: '鎻愮ず',
+ content: '鎮ㄩ渶瑕佺櫥褰曞悗鎵嶈兘浣跨敤寮�闃�鍔熻兘锛屾槸鍚︾珛鍗崇櫥褰曪紵',
+ confirmText: '鍓嶅線鐧诲綍',
+ cancelText: '鍙栨秷',
+ success: (res) => {
+ if (res.confirm) {
+ // 鐢ㄦ埛鐐瑰嚮纭锛岀洿鎺ヨ皟鐢╳xLogin鏂规硶
+ this.wxLogin();
+ }
+ }
+ });
+ }
+ return;
+ }
}
+
+ // 宸茬櫥褰曟垨涓嶉渶瑕佺櫥褰曠殑椤圭洰锛屾墽琛屽紑闃�鎿嶄綔
+ wx.navigateTo({
+ url: '/pages/waterIntake/waterIntake',
+ })
},
- calculateScrollViewHeight: function () {
- wx.createSelectorQuery().selectAll('.list-item').boundingClientRect((rects) => {
- let totalHeight = rects.reduce((sum, rect) => sum + rect.height, 0);
- this.setData({
- scrollViewHeight: totalHeight,
- });
- }).exec();
- },
+
+ // 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) {
@@ -79,18 +116,6 @@
},
- //鑾峰彇鐢ㄦ埛鏁版嵁
- getUserData() {
- get('/items')
- .then((data) => {
- this.setData({
- items: data
- });
- })
- .catch((error) => {
- console.error('Failed to fetch data:', error);
- });
- },
@@ -99,6 +124,10 @@
*/
onLoad(options) {
console.log('home椤甸潰onLoad寮�濮嬶紝鍙傛暟:', options);
+
+ // 鍒濆鍖栭」鐩垪琛ㄦ暟鎹�
+ this.initProjectList();
+
//褰撳紑闃�鎴愬姛鍚庤皟鐢ㄥ埛鏂�
if (options.param === "1" || options.param === "2") {
this.setData({
@@ -130,6 +159,44 @@
}, 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;
+ }
+ } catch (e) {
+ console.error('浠庢湰鍦板瓨鍌ㄨ幏鍙栭」鐩け璐�:', e);
+ }
+ }
+
+ // 璁剧疆鍒伴〉闈㈡暟鎹腑
+ this.setData({
+ projectList,
+ selectedProject: currentSelectedProject
+ });
+
+ console.log('椤圭洰鍒楄〃宸插垵濮嬪寲:', projectList, '褰撳墠閫変腑椤圭洰:', currentSelectedProject);
+ },
+
// 鏂板鐨勫垵濮嬪寲椤甸潰杈呭姪鍑芥暟锛屽垎绂诲嚭onLoad涓殑閫昏緫浠ヤ究寤惰繜鎵ц
initializePage(options, fromLogin) {
// 妫�鏌ユ槸鍚﹀凡閫夋嫨椤圭洰
@@ -148,49 +215,57 @@
});
// 璁剧疆 baseUrl
- const baseUrl = PROJECT_URLS[project];
- getApp().globalData.baseUrl = baseUrl;
- getApp().globalData.selectedProject = project;
+ const serverUrl = PROJECT_CONFIG[project]?.serverUrl;
+ if (serverUrl) {
+ getApp().globalData.baseUrl = serverUrl;
+ getApp().globalData.selectedProject = project;
+ console.log('璁剧疆baseUrl:', serverUrl);
+ }
// 鏍规嵁椤圭洰璁剧疆瀵瑰簲鐨則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();
+ const projectConfig = PROJECT_CONFIG[project];
+ if (projectConfig) {
+ getApp().globalData.tag = projectConfig.tag;
+
+ // 鏍规嵁椤圭洰鏄惁闇�瑕佺櫥褰曪紝璁剧疆涓嶅悓鐨剈serName
+ if (projectConfig.needLogin === false) {
+ // 涓嶉渶瑕佺櫥褰曠殑椤圭洰锛屾樉绀洪」鐩悕绉�
+ this.setData({
+ userName: projectConfig.displayName
});
- } 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();
+ } 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);
}
// 缁х画鍒濆鍖栭〉闈�
@@ -219,7 +294,7 @@
console.log('鑾峰彇瀛樺偍鏁版嵁涓柇:', error.message);
// 濡傛灉鏄粠鐧诲綍椤佃繑鍥炴垨宸茬櫥褰曪紝涓嶅啀璺宠浆
- if (fromLogin || getApp().globalData.isLoggedIn) {
+ if (fromLogin) {
console.log('浠庣櫥褰曢〉杩斿洖鎴栧凡鐧诲綍锛岀户缁垵濮嬪寲椤甸潰');
this.continueInitPage(options);
return;
@@ -273,9 +348,34 @@
});
}
+ // 灏濊瘯鑾峰彇eventChannel锛岀敤浜庣洃鍚櫥褰曢〉闈㈠彂鍥炵殑娑堟伅
+ try {
+ const eventChannel = currentPage.getOpenerEventChannel();
+ if (eventChannel && eventChannel.on) {
+ eventChannel.on('fromLogin', (data) => {
+ console.log('onShow: 鎺ユ敹鍒扮櫥褰曢〉闈㈣繑鍥炵殑娑堟伅', data);
+ if (data && data.fromLogin) {
+ fromLogin = true;
+ this.setData({
+ isFromLogin: true
+ });
+
+ // 鐧诲綍鎴愬姛鍚庡埛鏂版暟鎹�
+ console.log('鐧诲綍鎴愬姛鍚庡埛鏂版暟鎹�');
+ this.initData();
+ }
+ });
+ }
+ } catch (e) {
+ console.error('鑾峰彇eventChannel澶辫触:', e);
+ }
+
// 鍒濆鍖栧鐞�
if (fromLogin || this.data.isFromLogin) {
console.log('onShow: 浠庣櫥褰曢〉杩斿洖锛屼笉杩涜鐧诲綍妫�鏌�');
+
+ // 濡傛灉鏄粠鐧诲綍椤佃繑鍥烇紝閲嶆柊鍔犺浇鏁版嵁
+ this.initData();
} else {
console.log('onShow: 姝e父鏄剧ず椤甸潰');
// 寤惰繜妫�鏌ョ櫥褰曠姸鎬侊紝纭繚鑳芥纭瘑鍒复鏃舵爣璁�
@@ -290,12 +390,6 @@
// 鍐嶆纭鏄惁浠庣櫥褰曢〉杩斿洖
if (this.getFromLogin()) {
console.log('妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝涓嶈繘琛岀櫥褰曟鏌�');
- return;
- }
-
- // 鍐嶆妫�鏌ュ叏灞�鐧诲綍鐘舵��
- if (getApp().globalData.isLoggedIn) {
- console.log('妫�娴嬪埌鍏ㄥ眬鐧诲綍鐘舵�侊紝涓嶈繘琛岀櫥褰曟鏌�');
return;
}
@@ -357,12 +451,43 @@
})
},
openValveList() {
- // wx.navigateTo({
- // url: '/pages/valveList/valveList',
- // })
- wx.showToast({
- title: '鏆傛湭寮�鏀�',
- icon: 'none'
+ const app = getApp();
+ // 妫�鏌ュ綋鍓嶉」鐩槸鍚﹂渶瑕佺櫥褰�
+ const currentProject = app.globalData.selectedProject;
+ if (currentProject && PROJECT_CONFIG[currentProject] && PROJECT_CONFIG[currentProject].needLogin) {
+ // 闇�瑕佺櫥褰曠殑椤圭洰锛屾鏌ユ槸鍚﹀凡鐧诲綍
+ if (!app.globalData.isLoggedIn) {
+ // 鏈櫥褰曪紝鏄剧ず鎻愮ず骞堕樆姝㈡搷浣�
+ wx.showToast({
+ title: '璇峰厛鐧诲綍',
+ icon: 'error',
+ duration: 2000
+ });
+
+ // 鑾峰彇椤圭洰閰嶇疆
+ const projectConfig = PROJECT_CONFIG[currentProject];
+ if (projectConfig) {
+ // 璇㈤棶鐢ㄦ埛鏄惁鍓嶅線鐧诲綍
+ wx.showModal({
+ title: '鎻愮ず',
+ content: '鎮ㄩ渶瑕佺櫥褰曞悗鎵嶈兘鏌ョ湅寮�鍏抽榾璁板綍锛屾槸鍚︾珛鍗崇櫥褰曪紵',
+ confirmText: '鍓嶅線鐧诲綍',
+ cancelText: '鍙栨秷',
+ success: (res) => {
+ if (res.confirm) {
+ // 鐢ㄦ埛鐐瑰嚮纭锛岀洿鎺ヨ皟鐢╳xLogin鏂规硶
+ this.wxLogin();
+ }
+ }
+ });
+ }
+ return;
+ }
+ }
+
+ // 宸茬櫥褰曟垨涓嶉渶瑕佺櫥褰曠殑椤圭洰锛屾墽琛屾煡鐪嬭褰曟搷浣�
+ wx.navigateTo({
+ url: '/pages/valveList/valveList',
})
},
feedBack() {
@@ -373,13 +498,40 @@
},
//瑙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: '纭畾瑕佽В缁戝綋鍓嶈处鍙峰悧锛�',
+ content: '纭畾瑕佽В缁戝綋鍓嶈处鍙峰悧锛熻В缁戝悗灏嗘棤娉曚娇鐢ㄧ浉鍏冲姛鑳斤紝闇�閲嶆柊缁戝畾銆�',
+ confirmText: '纭瑙g粦',
+ confirmColor: '#e34d59',
+ cancelText: '鍙栨秷',
success: (res) => {
if (res.confirm) {
- this.unBindPost()
+ this.unBindPost();
}
}
});
@@ -387,22 +539,48 @@
wx.showToast({
title: '杩樻湭缁戝畾',
icon: 'error'
- })
+ });
}
-
},
- //杞亴
irrigation() {
- if (getApp().globalData.isLoggedIn) {
- wx.navigateTo({
- url: '/pages/irrigation/irrigation',
- })
- } else {
- wx.showToast({
- title: '璇峰厛鐧诲綍',
- icon: 'error'
- })
+ const app = getApp();
+ // 妫�鏌ュ綋鍓嶉」鐩槸鍚﹂渶瑕佺櫥褰�
+ const currentProject = app.globalData.selectedProject;
+ if (currentProject && PROJECT_CONFIG[currentProject] && PROJECT_CONFIG[currentProject].needLogin) {
+ // 闇�瑕佺櫥褰曠殑椤圭洰锛屾鏌ユ槸鍚﹀凡鐧诲綍
+ if (!app.globalData.isLoggedIn) {
+ // 鏈櫥褰曪紝鏄剧ず鎻愮ず骞堕樆姝㈡搷浣�
+ wx.showToast({
+ title: '璇峰厛鐧诲綍',
+ icon: 'error',
+ duration: 2000
+ });
+
+ // 鑾峰彇椤圭洰閰嶇疆
+ const projectConfig = PROJECT_CONFIG[currentProject];
+ if (projectConfig) {
+ // 璇㈤棶鐢ㄦ埛鏄惁鍓嶅線鐧诲綍
+ wx.showModal({
+ title: '鎻愮ず',
+ content: '鎮ㄩ渶瑕佺櫥褰曞悗鎵嶈兘浣跨敤杞亴鍔熻兘锛屾槸鍚︾珛鍗崇櫥褰曪紵',
+ confirmText: '鍓嶅線鐧诲綍',
+ cancelText: '鍙栨秷',
+ success: (res) => {
+ if (res.confirm) {
+ // 鐢ㄦ埛鐐瑰嚮纭锛岀洿鎺ヨ皟鐢╳xLogin鏂规硶
+ this.wxLogin();
+ }
+ }
+ });
+ }
+ return;
+ }
}
+
+ // 宸茬櫥褰曟垨涓嶉渶瑕佺櫥褰曠殑椤圭洰锛屾墽琛岃疆鐏屾搷浣�
+ wx.navigateTo({
+ url: '/pages/irrigation/irrigation',
+ })
},
handleChange(e) {
const item = e.currentTarget.dataset.item;
@@ -465,14 +643,22 @@
})
}).catch(error => {
wx.hideLoading();
- this.setData({
- showErrorDialog: true,
- errorData: error.msg,
- errorDialogTitle: "鍏抽榾閿欒"
- })
// 澶勭悊閿欒鍝嶅簲
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: "鍏抽榾閿欒"
+ })
+ }
});
},
/**
@@ -534,11 +720,8 @@
isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
});
+ this.updateDisplayText();
- // 鎴愬姛鑾峰彇鏁版嵁鍚庡埛鏂癠I楂樺害
- setTimeout(() => {
- this.calculateScrollViewHeight();
- }, 200);
}).catch(err => {
console.error('鑾峰彇鍒楄〃鏁版嵁澶辫触:', err);
// 閿欒鍥炶皟
@@ -581,12 +764,6 @@
},
//鏍规嵁session鑾峰彇鍐滄埛淇℃伅
getUserDataBySession() {
- // 鍏堟鏌ユ槸鍚︿粠鐧诲綍椤佃繑鍥�
- if (this.getFromLogin()) {
- console.log('getUserDataBySession: 妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝涓嶆墽琛孉PI璇锋眰');
- return;
- }
-
const app = getApp();
// 妫�鏌ユ槸鍚︽湁sessionId
@@ -631,13 +808,6 @@
duration: 3000
});
}
- } else {
- // 鍏朵粬閿欒锛屾樉绀洪敊璇俊鎭�
- wx.showToast({
- title: err.msg || '鑾峰彇鐢ㄦ埛淇℃伅澶辫触',
- icon: 'none',
- duration: 3000
- });
}
});
},
@@ -659,6 +829,41 @@
* 鎵爜寮�闃�
*/
scenCode() {
+ const app = getApp();
+ // 妫�鏌ュ綋鍓嶉」鐩槸鍚﹂渶瑕佺櫥褰�
+ const currentProject = app.globalData.selectedProject;
+ if (currentProject && PROJECT_CONFIG[currentProject] && PROJECT_CONFIG[currentProject].needLogin) {
+ // 闇�瑕佺櫥褰曠殑椤圭洰锛屾鏌ユ槸鍚﹀凡鐧诲綍
+ if (!app.globalData.isLoggedIn) {
+ // 鏈櫥褰曪紝鏄剧ず鎻愮ず骞堕樆姝㈡壂鐮�
+ wx.showToast({
+ title: '璇峰厛鐧诲綍',
+ icon: 'error',
+ duration: 2000
+ });
+
+ // 鑾峰彇椤圭洰閰嶇疆
+ const projectConfig = PROJECT_CONFIG[currentProject];
+ if (projectConfig) {
+ // 璇㈤棶鐢ㄦ埛鏄惁鍓嶅線鐧诲綍
+ wx.showModal({
+ title: '鎻愮ず',
+ content: '鎮ㄩ渶瑕佺櫥褰曞悗鎵嶈兘浣跨敤鎵爜寮�闃�鍔熻兘锛屾槸鍚︾珛鍗崇櫥褰曪紵',
+ confirmText: '鍓嶅線鐧诲綍',
+ cancelText: '鍙栨秷',
+ success: (res) => {
+ if (res.confirm) {
+ // 鐢ㄦ埛鐐瑰嚮纭锛岀洿鎺ヨ皟鐢╳xLogin鏂规硶
+ this.wxLogin();
+ }
+ }
+ });
+ }
+ return;
+ }
+ }
+
+ // 宸茬櫥褰曟垨涓嶉渶瑕佺櫥褰曠殑椤圭洰锛屾墽琛屾壂鐮佹搷浣�
const that = this;
wx.scanCode({
success(res) {
@@ -757,36 +962,81 @@
// 棣栧厛妫�鏌ユ槸鍚︿粠鐧诲綍椤佃繑鍥�
if (this.getFromLogin()) {
- console.log('initData: 妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝浠呰幏鍙栧熀鏈暟鎹�');
+ 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 {
+ // 妫�鏌ユ槸鍚︽湁sessionId鍜宑lientId锛屼紭鍏堜娇鐢ㄥ叏灞�鍙橀噺
+ if (app.globalData.sessionId && app.globalData.clientId) {
+ console.log('initData: 鍏ㄥ眬鍙橀噺涓湁鐧诲綍淇℃伅锛岀洿鎺ヨ幏鍙栫敤鎴锋暟鎹拰寮�闃�鍒楄〃');
+ this.getUserDataBySession();
this.getOpenList();
+ return;
}
+
+ // 濡傛灉娌℃湁鍏ㄥ眬鍙橀噺锛屽皾璇曚粠鏈湴瀛樺偍涓仮澶�
+ Promise.all([
+ storage.getItemSafe('userData'),
+ storage.getItemSafe('sessionId'),
+ storage.getItemSafe('clientId')
+ ]).then(([userData, sessionId, clientId]) => {
+ if (userData) {
+ try {
+ // 瑙f瀽userData骞惰缃叏灞�鍙橀噺
+ let jsonObj = JSON.parse(userData);
+ app.globalData.sessionId = jsonObj.sessionId;
+ app.globalData.clientId = jsonObj.clientId || clientId;
+ app.globalData.tag = jsonObj.tag;
+ app.globalData.isLoggedIn = true;
+
+ // 鐩存帴浠巙serData璁剧疆鐢ㄦ埛淇℃伅
+ if (jsonObj.clientName && jsonObj.phone) {
+ this.setData({
+ userName: jsonObj.clientName,
+ userPhone: this.maskPhoneNumber(jsonObj.phone)
+ });
+ } else {
+ // 濡傛灉userData涓病鏈夌敤鎴蜂俊鎭紝璋冪敤鎺ュ彛鑾峰彇
+ this.getUserDataBySession();
+ }
+
+ console.log("userData宸插姞杞�:", userData);
+ } catch (e) {
+ console.error('userData瑙f瀽澶辫触:', e);
+ if (sessionId && clientId) {
+ app.globalData.sessionId = sessionId;
+ app.globalData.clientId = clientId;
+ app.globalData.isLoggedIn = true;
+ this.getUserDataBySession();
+ }
+ }
+ } else if (sessionId && clientId) {
+ // 濡傛灉娌℃湁userData浣嗘湁session鍜宑lient ID
+ app.globalData.sessionId = sessionId;
+ app.globalData.clientId = clientId;
+ app.globalData.isLoggedIn = true;
+ this.getUserDataBySession();
+ }
+
+ // 鏃犺濡備綍閮藉皾璇曡幏鍙栧紑闃�鍒楄〃
+ this.getOpenList();
+ }).catch(err => {
+ console.error('鎭㈠鐧诲綍鐘舵�佸け璐�:', err);
+ this.getOpenList();
+ });
+
return;
+ }
+
+ // 妫�鏌ュ綋鍓嶉」鐩槸鍚﹂渶瑕佺櫥褰�
+ const currentProject = app.globalData.selectedProject;
+ const projectConfig = PROJECT_CONFIG[currentProject];
+ const needLogin = projectConfig && projectConfig.needLogin;
+
+ // 鏍规嵁椤圭洰鏄惁闇�瑕佺櫥褰曪紝璁剧疆涓嶅悓鐨剈serName
+ if (projectConfig && projectConfig.needLogin === false) {
+ // 涓嶉渶瑕佺櫥褰曠殑椤圭洰锛屾樉绀洪」鐩悕绉�
+ this.setData({
+ userName: projectConfig.displayName
+ });
}
// 灏濊瘯鑾峰彇鐢ㄦ埛鏁版嵁鍜屽凡寮�闃�璁板綍
@@ -794,7 +1044,15 @@
// 浼樺厛妫�鏌ュ叏灞�鍙橀噺涓槸鍚︽湁sessionId
if (app.globalData.sessionId) {
console.log('initData: 浣跨敤鍏ㄥ眬sessionId鑾峰彇鏁版嵁');
- this.getUserDataBySession();
+
+ // 鍙湁闇�瑕佺櫥褰曠殑椤圭洰鎵嶈皟鐢╣etUserDataBySession
+ if (needLogin) {
+ console.log('initData: 褰撳墠椤圭洰闇�瑕佺櫥褰曪紝鑾峰彇鐢ㄦ埛鏁版嵁');
+ this.getUserDataBySession();
+ } else {
+ console.log('initData: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰曪紝璺宠繃鑾峰彇鐢ㄦ埛鏁版嵁');
+ }
+
this.getOpenList();
return;
}
@@ -817,8 +1075,15 @@
console.error('userData瑙f瀽澶辫触:', e);
}
}
- // 鏃犺濡備綍閮藉皾璇曡幏鍙栫敤鎴蜂俊鎭拰寮�闃�鍒楄〃
- this.getUserDataBySession();
+
+ // 鍙湁闇�瑕佺櫥褰曠殑椤圭洰鎵嶈皟鐢╣etUserDataBySession
+ if (needLogin) {
+ console.log('initData: 褰撳墠椤圭洰闇�瑕佺櫥褰曪紝鑾峰彇鐢ㄦ埛鏁版嵁');
+ this.getUserDataBySession();
+ } else {
+ console.log('initData: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰曪紝璺宠繃鑾峰彇鐢ㄦ埛鏁版嵁');
+ }
+
this.getOpenList();
})
.catch((err) => {
@@ -829,7 +1094,14 @@
console.log('initData:catch: 妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝鍙幏鍙栧紑闃�鍒楄〃');
this.getOpenList();
} else {
- this.getUserDataBySession();
+ // 鍙湁闇�瑕佺櫥褰曠殑椤圭洰鎵嶈皟鐢╣etUserDataBySession
+ if (needLogin) {
+ console.log('initData:catch: 褰撳墠椤圭洰闇�瑕佺櫥褰曪紝鑾峰彇鐢ㄦ埛鏁版嵁');
+ this.getUserDataBySession();
+ } else {
+ console.log('initData:catch: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰曪紝璺宠繃鑾峰彇鐢ㄦ埛鏁版嵁');
+ }
+
this.getOpenList();
}
});
@@ -841,7 +1113,14 @@
console.log('initData:else: 妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝鍙幏鍙栧紑闃�鍒楄〃');
this.getOpenList();
} else {
- this.getUserDataBySession();
+ // 鍙湁闇�瑕佺櫥褰曠殑椤圭洰鎵嶈皟鐢╣etUserDataBySession
+ if (needLogin) {
+ console.log('initData:else: 褰撳墠椤圭洰闇�瑕佺櫥褰曪紝鑾峰彇鐢ㄦ埛鏁版嵁');
+ this.getUserDataBySession();
+ } else {
+ console.log('initData:else: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰曪紝璺宠繃鑾峰彇鐢ㄦ埛鏁版嵁');
+ }
+
this.getOpenList();
}
}
@@ -853,8 +1132,14 @@
console.log('initData:error: 妫�娴嬪埌浠庣櫥褰曢〉杩斿洖鐨勬爣璁帮紝鍙幏鍙栧紑闃�鍒楄〃');
this.getOpenList();
} else {
- // 鍑洪敊鏃朵粛灏濊瘯鑾峰彇鏁版嵁
- this.getUserDataBySession();
+ // 鍙湁闇�瑕佺櫥褰曠殑椤圭洰鎵嶈皟鐢╣etUserDataBySession
+ if (needLogin) {
+ console.log('initData:error: 褰撳墠椤圭洰闇�瑕佺櫥褰曪紝鑾峰彇鐢ㄦ埛鏁版嵁');
+ this.getUserDataBySession();
+ } else {
+ console.log('initData:error: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰曪紝璺宠繃鑾峰彇鐢ㄦ埛鏁版嵁');
+ }
+
this.getOpenList();
}
}
@@ -868,7 +1153,8 @@
if (this.data.avatarTapCount >= 5) {
this.setData({
showProjectDialog: true,
- avatarTapCount: 0
+ avatarTapCount: 0,
+ tempSelectedProject: this.data.selectedProject // 鍒濆鍖栦复鏃堕�夋嫨涓哄綋鍓嶉�夋嫨
});
}
},
@@ -880,21 +1166,28 @@
return;
}
this.setData({
- showProjectDialog: e.detail.visible
+ showProjectDialog: e.detail.visible,
+ // 褰撴樉绀哄璇濇鏃讹紝鍒濆鍖栦复鏃堕�夋嫨涓哄綋鍓嶉�夋嫨
+ tempSelectedProject: e.detail.visible ? this.data.selectedProject : ''
});
},
// 澶勭悊椤圭洰閫夋嫨鍙樺寲
onProjectChange(event) {
console.log('閫夋嫨鐨勯」鐩細', event.detail.value);
+ // 涓嶇珛鍗宠缃埌state锛岃�屾槸瀛樺偍鍒颁复鏃跺彉閲忎腑
this.setData({
- selectedProject: event.detail.value
+ tempSelectedProject: event.detail.value
});
},
// 澶勭悊椤圭洰閫夋嫨纭
handleProjectConfirm() {
- if (!this.data.selectedProject) {
+ // 浠庝复鏃跺彉閲忚幏鍙栭�夋嫨鐨勯」鐩�
+ const selectedProject = this.data.tempSelectedProject || this.data.selectedProject;
+ console.log('寮�濮嬪鐞嗛」鐩�夋嫨纭', selectedProject, this.data.projectList);
+
+ if (!selectedProject) {
wx.showToast({
title: '璇烽�夋嫨椤圭洰',
icon: 'none'
@@ -904,14 +1197,56 @@
// 鑾峰彇褰撳墠宸查�夐」鐩拰鏂伴�夋嫨鐨勯」鐩�
const currentProject = getApp().globalData.selectedProject;
- const newProject = this.data.selectedProject;
- const projectName = newProject === 'JYG' ? '鍢夊唱鍏抽」鐩�' :
- newProject === 'MQ' ? '姘戝嫟椤圭洰' :
- newProject === 'TEST' ? '娴嬭瘯椤圭洰' : '鏈煡椤圭洰';
+ const newProject = 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.setData({
+ selectedProject: newProject
+ });
+ // 鐢ㄦ埛纭閫夋嫨锛岀户缁鐞�
+ this.processProjectSelection(currentProject, newProject, projectConfig, isProjectChanged);
+ } else {
+ // 鐢ㄦ埛鍙栨秷锛屼笉杩涜浠讳綍鎿嶄綔
+ console.log('鐢ㄦ埛鍙栨秷浜嗛」鐩�夋嫨');
+ // 鎭㈠涔嬪墠鐨勯�夋嫨鐘舵��
+ this.setData({
+ tempSelectedProject: this.data.selectedProject
+ });
+ }
+ }
+ });
+ },
+
+ // 澶勭悊椤圭洰閫夋嫨鐨勫悗缁搷浣�
+ processProjectSelection(currentProject, newProject, projectConfig, isProjectChanged) {
// 濡傛灉鍒囨崲浜嗛」鐩紝鍏堟竻闄ょ櫥褰曠姸鎬�
if (isProjectChanged) {
console.log(`姝e湪浠庨」鐩� ${currentProject} 鍒囨崲鍒� ${newProject}锛屽皢娓呴櫎鐧诲綍鐘舵�乣);
@@ -921,82 +1256,98 @@
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鏄剧ず鐘舵��
- this.setData({
- userName: "璇风櫥褰�",
- userPhone: "",
- listData: []
- });
+ if (projectConfig.needLogin === false) {
+ // 涓嶉渶瑕佺櫥褰曠殑椤圭洰锛屾樉绀洪」鐩悕绉颁綔涓簎serName
+ this.setData({
+ userName: projectConfig.displayName,
+ userPhone: "",
+ listData: []
+ });
+ } else {
+ // 闇�瑕佺櫥褰曠殑椤圭洰锛屾樉绀�"璇风偣鍑荤櫥褰�"
+ this.setData({
+ userName: "璇风偣鍑荤櫥褰�",
+ userPhone: "",
+ listData: []
+ });
+ }
}
// 淇濆瓨椤圭洰閫夋嫨鍒版湰鍦板瓨鍌�
storage.setItem('selectedProject', newProject).then(() => {
- // 鏇存柊 BASEURL
- const {
- PROJECT_URLS
- } = require('../../api/config.js');
- const baseUrl = PROJECT_URLS[newProject];
+ // 璋冪敤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.baseUrl = baseUrl;
getApp().globalData.selectedProject = newProject;
+ getApp().globalData.baseUrl = projectConfig.serverUrl;
+ getApp().globalData.serverId = projectConfig.serverId;
- // 鏍规嵁椤圭洰璁剧疆瀵瑰簲鐨則ag鍜宑lientId
- if (newProject === 'JYG') {
- getApp().globalData.tag = 'ym'; // 鍢夊唱鍏抽」鐩搴攖ag涓簓m
- this.setData({
- userName: "鍢夊唱鍏抽」鐩�"
- });
- } else if (newProject === 'MQ') {
- getApp().globalData.tag = 'mq'; // 姘戝嫟椤圭洰瀵瑰簲tag涓簃q
- getApp().globalData.operator = '2025033115305200006';
- getApp().globalData.clientId = '2025033115305200006';
+ // 閫氳繃閰嶇疆瀵硅薄缁熶竴璁剧疆椤圭洰鍙傛暟
+ 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 = '2025033115305200006';
- this.setData({
- userName: "姘戝嫟椤圭洰"
- });
- // 鎸佷箙鍖栧瓨鍌ㄦ皯鍕ら」鐩弬鏁�
- storage.setItem('MQ_params', {
- operator: '2025033115305200006',
- clientId: '2025033115305200006',
+ getApp().globalData.sessionId = operatorId;
+
+ // 濡傛灉鏈塿cId锛屼篃璁剧疆
+ if (projectConfig.vcId) {
+ getApp().globalData.vcId = projectConfig.vcId;
+ }
+
+ // 鎸佷箙鍖栧瓨鍌ㄩ」鐩弬鏁�
+ const params = {
+ operator: operatorId,
+ clientId: operatorId,
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'
- });
+ sessionId: operatorId
+ };
+
+ if (projectConfig.vcId) {
+ params.vcId = projectConfig.vcId;
+ }
+
+ storage.setItem(`${newProject}_params`, params);
}
- console.log('宸插垏鎹㈠埌椤圭洰:', projectName, '鍩熷悕:', baseUrl, 'tag:', getApp().globalData.tag);
+ console.log('宸插垏鎹㈠埌椤圭洰:', projectConfig.displayName, '鏈嶅姟鍣�:', projectConfig.serverId, 'tag:', getApp().globalData.tag);
this.setData({
showProjectDialog: false
@@ -1004,12 +1355,22 @@
// 鏄剧ず鍒囨崲鎴愬姛鎻愮ず
wx.showToast({
- title: `宸查�夋嫨${projectName}`,
+ 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);
@@ -1040,6 +1401,13 @@
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];
@@ -1058,7 +1426,7 @@
}
// 濡傛灉褰撳墠宸插湪鐧诲綍椤碉紝涓嶅啀璺宠浆
- if (currentRoute === 'pages/login/login') {
+ if (currentRoute === 'pages/login/login' || currentRoute === 'pages/accountLogin/accountLogin') {
console.log('褰撳墠宸插湪鐧诲綍椤碉紝涓嶅啀璺宠浆');
return;
}
@@ -1100,6 +1468,12 @@
return;
}
+ // 妫�鏌ラ」鐩槸鍚﹂渶瑕佺櫥褰�
+ if (currentProject && PROJECT_CONFIG[currentProject] && !PROJECT_CONFIG[currentProject].needLogin) {
+ console.log('鏈�缁堟鏌�: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰�:', currentProject);
+ return;
+ }
+
console.log('纭闇�瑕佽烦杞埌鐧诲綍椤�');
// 璺宠浆鍓嶅啀娆℃鏌ョ櫥褰曢〉闈复鏃舵爣璁�
@@ -1107,11 +1481,26 @@
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)
- // });
+ // 鏍规嵁椤圭洰閰嶇疆鐨刲oginType鍐冲畾璺宠浆鍒板摢涓櫥褰曢〉闈�
+ // 姝ゅ涓嶅仛璺宠浆锛屾敞閲婃帀鍘熸湁浠g爜
+ // const projectInfo = PROJECT_CONFIG[currentProject];
+ // const loginType = projectInfo?.loginType || 'code'; // 榛樿浣跨敤楠岃瘉鐮佺櫥褰�
+
+ // if (loginType === 'account') {
+ // // 璐﹀彿瀵嗙爜鐧诲綍
+ // wx.navigateTo({
+ // url: `/pages/accountLogin/accountLogin?project=${currentProject}`,
+ // success: () => console.log('鎴愬姛璺宠浆鍒拌处鍙峰瘑鐮佺櫥褰曢〉'),
+ // fail: (err) => console.error('璺宠浆鍒拌处鍙峰瘑鐮佺櫥褰曢〉澶辫触:', err)
+ // });
+ // } else {
+ // // 楠岃瘉鐮佺櫥褰�
+ // wx.navigateTo({
+ // url: `/pages/login/login?project=${currentProject}`,
+ // success: () => console.log('鎴愬姛璺宠浆鍒伴獙璇佺爜鐧诲綍椤�'),
+ // fail: (err) => console.error('璺宠浆鍒伴獙璇佺爜鐧诲綍椤靛け璐�:', err)
+ // });
+ // }
}
})
.catch(err => {
@@ -1128,12 +1517,32 @@
return;
}
- // 鍑洪敊鏃朵篃璺宠浆鍒扮櫥褰曢〉
- // wx.navigateTo({
- // url: `/pages/login/login?project=${this.data.selectedProject}`,
- // success: () => console.log('閿欒鍚庢垚鍔熻烦杞埌鐧诲綍椤�'),
- // fail: (err) => console.error('閿欒鍚庤烦杞埌鐧诲綍椤靛け璐�:', err)
- // });
+ // 妫�鏌ラ」鐩槸鍚﹂渶瑕佺櫥褰�
+ if (currentProject && PROJECT_CONFIG[currentProject] && !PROJECT_CONFIG[currentProject].needLogin) {
+ console.log('閿欒澶勭悊: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰�:', currentProject);
+ return;
+ }
+
+ // 鍑洪敊鏃朵篃璺宠浆鍒扮櫥褰曢〉锛屾牴鎹甽oginType鍐冲畾璺宠浆鐩爣
+ // 姝ゅ涓嶅仛璺宠浆锛屾敞閲婃帀鍘熸湁浠g爜
+ // const projectInfo = PROJECT_CONFIG[currentProject];
+ // const loginType = projectInfo?.loginType || 'code'; // 榛樿浣跨敤楠岃瘉鐮佺櫥褰�
+
+ // if (loginType === 'account') {
+ // // 璐﹀彿瀵嗙爜鐧诲綍
+ // wx.navigateTo({
+ // url: `/pages/accountLogin/accountLogin?project=${currentProject}`,
+ // success: () => console.log('閿欒鍚庢垚鍔熻烦杞埌璐﹀彿瀵嗙爜鐧诲綍椤�'),
+ // fail: (err) => console.error('閿欒鍚庤烦杞埌璐﹀彿瀵嗙爜鐧诲綍椤靛け璐�:', err)
+ // });
+ // } else {
+ // // 楠岃瘉鐮佺櫥褰�
+ // wx.navigateTo({
+ // url: `/pages/login/login?project=${currentProject}`,
+ // success: () => console.log('閿欒鍚庢垚鍔熻烦杞埌楠岃瘉鐮佺櫥褰曢〉'),
+ // fail: (err) => console.error('閿欒鍚庤烦杞埌楠岃瘉鐮佺櫥褰曢〉澶辫触:', err)
+ // });
+ // }
});
},
@@ -1175,13 +1584,6 @@
console.log('continueInitPage: 浠庨〉闈㈡暟鎹腑妫�娴嬪埌isFromLogin=true');
fromLogin = true;
}
-
- // 鍒ゆ柇鏈湴鏄惁淇濆瓨sessionId
- // 浣跨敤 wx.nextTick 绛夊緟椤甸潰娓叉煋瀹屾垚
- wx.nextTick(() => {
- this.calculateScrollViewHeight();
- });
-
// 褰撳紑闃�鎴愬姛鍚庤皟鐢ㄥ埛鏂�
if (options && options.param) {
console.log("寮�闃�鎴愬姛鍙傛暟:", options.param);
@@ -1213,6 +1615,21 @@
// 寰俊鐧诲綍
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;
+ }
+ }
+
if (!getApp().globalData.isLoggedIn) {
wx.showLoading({
title: '姝e湪鐧诲綍璇风◢鍊�...',
@@ -1232,10 +1649,21 @@
wx.hideLoading();
if (response.code === "0001") {
if (response.content.client.clientId === "") {
- // 鏈粦瀹氳处鍙凤紝璺宠浆鍒扮櫥褰曢〉闈�
- // wx.navigateTo({
- // url: `/pages/login/login?project=${this.data.selectedProject}`
- // });
+ // 鏈粦瀹氳处鍙凤紝鏍规嵁椤圭洰閰嶇疆鐨刲oginType璺宠浆鍒扮浉搴旂殑鐧诲綍椤甸潰
+ const projectInfo = PROJECT_CONFIG[this.data.selectedProject];
+ const loginType = projectInfo?.loginType || 'code'; // 榛樿浣跨敤楠岃瘉鐮佺櫥褰�
+
+ if (loginType === 'account') {
+ // 璐﹀彿瀵嗙爜鐧诲綍
+ wx.navigateTo({
+ url: `/pages/accountLogin/accountLogin?project=${this.data.selectedProject}&projectName=${projectInfo.displayName}`
+ });
+ } else {
+ // 楠岃瘉鐮佺櫥褰�
+ wx.navigateTo({
+ url: `/pages/login/login?project=${this.data.selectedProject}&projectName=${projectInfo.displayName}`
+ });
+ }
} else {
this.setData({
userName: response.content.client.clientName,
@@ -1251,8 +1679,10 @@
getApp().globalData.isLoggedIn = true;
// 璁剧疆姝g‘鐨勯」鐩畉ag
- const tag = this.data.selectedProject === 'JYG' ? 'ym' : 'mq';
- getApp().globalData.tag = tag;
+ const projectConfig = PROJECT_CONFIG[this.data.selectedProject];
+ if (projectConfig) {
+ getApp().globalData.tag = projectConfig.tag;
+ }
// 淇濆瓨鍒板瓨鍌�
storage.setItem("sessionId", sessionId);
@@ -1262,14 +1692,14 @@
// 淇濆瓨userData淇℃伅锛屽寘鍚玸essionId鍜宼ag
const userData = JSON.stringify({
sessionId: sessionId,
- tag: tag,
+ 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:', tag);
+ console.log('鐢ㄦ埛鏁版嵁淇濆瓨鎴愬姛锛屽寘鍚」鐩俊鎭�:', this.data.selectedProject, 'tag:', projectConfig ? projectConfig.tag : 'ym');
this.initData();
})
.catch(err => {
@@ -1278,26 +1708,54 @@
});
}
+ } else if (response.code === "1003") {
+ // 鏈粦瀹氳处鍙凤紝鏍规嵁椤圭洰閰嶇疆鐨刲oginType璺宠浆鍒扮浉搴旂殑鐧诲綍椤甸潰
+ const projectInfo = PROJECT_CONFIG[this.data.selectedProject];
+ const loginType = projectInfo?.loginType || 'code'; // 榛樿浣跨敤楠岃瘉鐮佺櫥褰�
+
+ if (loginType === 'account') {
+ // 璐﹀彿瀵嗙爜鐧诲綍
+ wx.navigateTo({
+ url: `/pages/accountLogin/accountLogin?project=${this.data.selectedProject}&projectName=${projectInfo.displayName}`
+ });
+ } else {
+ // 楠岃瘉鐮佺櫥褰�
+ wx.navigateTo({
+ url: `/pages/login/login?project=${this.data.selectedProject}&projectName=${projectInfo.displayName}`
+ });
+ }
} 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}`
- // });
+ if(error.code==="1003"){
+ // 鏈粦瀹氳处鍙凤紝鏍规嵁椤圭洰閰嶇疆鐨刲oginType璺宠浆鍒扮浉搴旂殑鐧诲綍椤甸潰
+ const projectInfo = PROJECT_CONFIG[this.data.selectedProject];
+ const loginType = projectInfo?.loginType || 'code'; // 榛樿浣跨敤楠岃瘉鐮佺櫥褰�
+
+ if (loginType === 'account') {
+ // 璐﹀彿瀵嗙爜鐧诲綍
+ wx.navigateTo({
+ url: `/pages/accountLogin/accountLogin?project=${this.data.selectedProject}&projectName=${projectInfo.displayName}`
+ });
+ } else {
+ // 楠岃瘉鐮佺櫥褰�
+ wx.navigateTo({
+ url: `/pages/login/login?project=${this.data.selectedProject}&projectName=${projectInfo.displayName}`
+ });
+ }
+ }else{
+ wx.showToast({
+ title: '鐧诲綍澶辫触锛岃閲嶈瘯',
+ icon: 'none'
+ });
+ }
});
} else {
wx.hideLoading();
@@ -1416,5 +1874,183 @@
// 鍒嗕韩澶辫触鐨勫洖璋冨嚱鏁�
}
};
- }
+ },
+ //鐐瑰嚮鎻愮ず鎸夐挳
+ 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
+ });
+
+ // 妯℃嫙璇锋眰寤惰繜
+ setTimeout(() => {
+ wx.hideLoading();
+
+ // 浠庡垪琛ㄤ腑绉婚櫎琚垹闄ょ殑椤�
+ const updatedList = this.data.listData.filter(listItem =>
+ listItem.orderNo !== item.orderNo
+ );
+
+ this.setData({
+ listData: updatedList
+ });
+
+ wx.showToast({
+ title: '鍒犻櫎鎴愬姛',
+ icon: 'success',
+ duration: 2000
+ });
+ }, 1500);
+ return;
+ }
+
+ wx.showLoading({
+ title: '姝e湪寮哄埗鍒犻櫎璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧
+ mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false
+ });
+ const data = {
+ vcNum: item.vcNum, //鍙栨按鍙D
+ rtuAddr: item.rtuAddr, //闃�鎺у櫒鍦板潃
+ };
+ post({
+ url: "wx/valve/deleteUnclosed",
+ data: data,
+ timeout: 180000
+ }).then(response => {
+ // 澶勭悊鎴愬姛鍝嶅簲
+ console.log('璇锋眰鎴愬姛:', response);
+ // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
+ wx.hideLoading();
+ //閲嶆柊鑾峰彇鍒楄〃鍒锋柊鏁版嵁
+ this.getOpenList();
+ }).catch(error => {
+ // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
+ wx.hideLoading();
+ // 澶勭悊閿欒鍝嶅簲
+ console.error('璇锋眰澶辫触:', error);
+ });
+ },
+ //淇敼鎸夐挳鏂囧瓧
+ updateDisplayText() {
+ const updatedList = this.data.listData.map(item => {
+ let displayText = '';
+ if (item.planned) {
+ displayText = '鍙栨秷';
+ } else {
+ displayText = "鍏抽榾"
+ }
+ let deleteText = "鍒犻櫎"
+ let time;
+ if (!item.dt) {
+ time = "鏆傛棤"
+ } else {
+ time = this.extractTime(item.dt)
+ }
+ if (item.waterInstant === null) {
+ item.waterInstant = "鏆傛棤"
+ }
+
+ return {
+ ...item,
+ displayText,
+ deleteText,
+ time
+ }; // 淇濈暀鎵�鏈夊叾浠栧瓧娈碉紝骞舵坊鍔� displayText 瀛楁
+ });
+ // 鏇存柊鍒楄〃鏁版嵁
+ this.setData({
+ 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() {
+ // 鏄剧ず浜屾纭寮圭獥
+ wx.showModal({
+ title: '鍒囨崲椤圭洰',
+ content: '纭畾瑕佸垏鎹㈤」鐩悧锛熷垏鎹㈠悗闇�瑕侀噸鏂扮櫥褰曘��',
+ confirmText: '纭鍒囨崲',
+ confirmColor: '#1890FF',
+ cancelText: '鍙栨秷',
+ success: (res) => {
+ if (res.confirm) {
+ // 鐢ㄦ埛鐐瑰嚮纭锛屾樉绀洪」鐩�夋嫨寮圭獥
+ this.setData({
+ showProjectDialog: true
+ });
+ }
+ }
+ });
+ },
+
+ // 娣诲姞鐢ㄦ埛鐐瑰嚮澶村儚鎴栫敤鎴峰悕鐧诲綍鐨勫鐞嗛�昏緫
+ handleUserTap() {
+ const app = getApp();
+ // 濡傛灉宸茬櫥褰曪紝涓嶉渶瑕佽烦杞埌鐧诲綍椤甸潰
+ if (app.globalData.isLoggedIn) {
+ return;
+ }
+
+ // 妫�鏌ュ綋鍓嶉」鐩槸鍚﹂渶瑕佺櫥褰�
+ const currentProject = app.globalData.selectedProject;
+ if (currentProject && PROJECT_CONFIG[currentProject]) {
+ const projectConfig = PROJECT_CONFIG[currentProject];
+
+ if (!projectConfig.needLogin) {
+ console.log('handleUserTap: 褰撳墠椤圭洰涓嶉渶瑕佺櫥褰�:', currentProject);
+ // 涓嶉渶瑕佺櫥褰曠殑椤圭洰锛屾樉绀洪」鐩悕绉�
+ this.setData({
+ userName: projectConfig.displayName
+ });
+ return;
+ }
+
+ // 鏍规嵁椤圭洰閰嶇疆鐨刲oginType鍐冲畾璺宠浆鍒板摢涓櫥褰曢〉闈�
+ const loginType = projectConfig.loginType || 'code'; // 榛樿浣跨敤楠岃瘉鐮佺櫥褰�
+
+ if (loginType === 'account') {
+ // 璐﹀彿瀵嗙爜鐧诲綍
+ wx.navigateTo({
+ url: `/pages/accountLogin/accountLogin?project=${currentProject}&projectName=${projectConfig.displayName}`
+ });
+ } else {
+ // 楠岃瘉鐮佺櫥褰�
+ wx.navigateTo({
+ url: `/pages/login/login?project=${currentProject}&projectName=${projectConfig.displayName}`
+ });
+ }
+ } else {
+ // 濡傛灉娌℃湁褰撳墠椤圭洰閰嶇疆锛岄粯璁よ烦杞埌楠岃瘉鐮佺櫥褰�
+ wx.navigateTo({
+ url: '/pages/login/login'
+ });
+ }
+ },
})
\ No newline at end of file
--
Gitblit v1.8.0