From 25ebc714977470b5ed02b0ec7f30ea0615ebd89f Mon Sep 17 00:00:00 2001
From: zuoxiao <zuoxiao>
Date: 星期五, 14 三月 2025 16:48:09 +0800
Subject: [PATCH] 更新应用配置,添加AppID并修改页面路由;优化取水口界面,增加定时开阀功能和相关参数设置;修复首页反馈图标及提示信息。
---
pages/home/home.js | 295 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 271 insertions(+), 24 deletions(-)
diff --git a/pages/home/home.js b/pages/home/home.js
index d0a7f0b..d38e37d 100644
--- a/pages/home/home.js
+++ b/pages/home/home.js
@@ -4,6 +4,7 @@
get,
post
} = require('../../api/request.js');
+const { PROJECT_URLS } = require('../../api/config.js');
Page({
/**
@@ -15,8 +16,8 @@
myItem: {},
waterIntakeName: "",
image: "/images/ic_head_bg.jpg",
- userPhone: "158****0723",
- userName: "寮犱笁",
+ userPhone: "",
+ userName: "璇风櫥褰�",
scrollViewHeight: 0,
listData: [],
isRefreshing: false,
@@ -28,7 +29,10 @@
},
errorDialogTitle: "鍏抽榾閿欒",
showForceConfirm: false, //鏄惁寮哄埗寮�闃�
- lastIntakeName: ""
+ lastIntakeName: "",
+ showProjectDialog: false,
+ selectedProject: '',
+ avatarTapCount: 0
},
openValve: function (e) {
@@ -75,24 +79,67 @@
* 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
*/
onLoad(options) {
- //鍒ゆ柇鏈湴鏄惁淇濆瓨sessionId
-
-
- // 浣跨敤 wx.nextTick 绛夊緟椤甸潰娓叉煋瀹屾垚
- wx.nextTick(() => {
- this.calculateScrollViewHeight();
+ // 妫�鏌ユ槸鍚﹀凡閫夋嫨椤圭洰
+ const { PROJECT_URLS } = require('../../api/config.js');
+
+ storage.getItem('selectedProject').then((project) => {
+ if (project) {
+ this.setData({
+ selectedProject: project
+ });
+
+ // 纭繚鍏ㄥ眬鍙橀噺瀛樺湪
+ getApp().globalData = getApp().globalData || {};
+ // 璁剧疆 baseUrl
+ const baseUrl = PROJECT_URLS[project];
+ getApp().globalData.baseUrl = baseUrl;
+ getApp().globalData.selectedProject = project;
+
+ // 鏍规嵁椤圭洰璁剧疆瀵瑰簲鐨則ag
+ if (project === 'JYG') {
+ getApp().globalData.tag = 'ym'; // 鍢夊唱鍏抽」鐩搴攖ag涓簓m
+ } else if (project === 'MQ') {
+ getApp().globalData.tag = 'mq'; // 姘戝嫟椤圭洰瀵瑰簲tag涓簃q
+ }
+
+ console.log('鍔犺浇宸蹭繚瀛樼殑椤圭洰:', project, '鍩熷悕:', baseUrl, 'tag:', getApp().globalData.tag);
+
+ // 妫�鏌ョ櫥褰曠姸鎬�
+ if (!getApp().globalData.isLoggedIn) {
+ this.checkLoginStatus();
+ return; // 濡傛灉鏈櫥褰曪紝绛夊緟璺宠浆鍒扮櫥褰曢〉闈�
+ }
+ } else {
+ // 棣栨杩涘叆锛屾樉绀洪」鐩�夋嫨寮圭獥
+ this.setData({
+ showProjectDialog: true
+ });
+ return; // 绛夊緟鐢ㄦ埛閫夋嫨椤圭洰
+ }
+
+ //鍒ゆ柇鏈湴鏄惁淇濆瓨sessionId
+ // 浣跨敤 wx.nextTick 绛夊緟椤甸潰娓叉煋瀹屾垚
+ wx.nextTick(() => {
+ this.calculateScrollViewHeight();
+ });
+ //褰撳紑闃�鎴愬姛鍚庤皟鐢ㄥ埛鏂�
+ console.log("onLoad锛�" + options.param);
+ if (options.param) {
+ wx.showToast({
+ title: '寮�闃�鎴愬姛',
+ icon: 'success',
+ duration: 3000
+ })
+ this.getOpenList();
+ }
+ this.initData();
+ }).catch(err => {
+ console.error('Failed to get selectedProject:', err);
+ // 鍑洪敊鏃朵篃鏄剧ず椤圭洰閫夋嫨寮圭獥
+ this.setData({
+ showProjectDialog: true
+ });
});
- //褰撳紑闃�鎴愬姛鍚庤皟鐢ㄥ埛鏂�
- console.log("onLoad锛�" + options.param);
- if (options.param) {
- wx.showToast({
- title: '寮�闃�鎴愬姛',
- icon: 'success',
- duration: 3000
- })
- this.getOpenList();
- }
- this.initData();
},
/**
@@ -214,7 +261,7 @@
rtuAddr: rtuAddr,
vcNum: vcNum, //铏氭嫙鍗D
orderNo: orderNo,
- operator: app.globalData.sessionId //鎿嶄綔鍛�
+ operator: app.globalData.operator //鎿嶄綔鍛�
};
console.log("postCloseValaue" + data);
post({
@@ -254,7 +301,7 @@
const params = {
url: 'wx/valve/get',
data: {
- operator: app.globalData.sessionId
+ operator: app.globalData.operator
}
};
get(params).then(data => {
@@ -374,7 +421,7 @@
const data = {
intakeName: intakeName, //鍙栨按鍙D
// vcId: vcId, //铏氭嫙鍗D
- operator: app.globalData.sessionId, //鎿嶄綔鍛�
+ operator: app.globalData.operator, //鎿嶄綔鍛�
forceOpen: !!isforce // 浣跨敤閫昏緫闈炴搷浣滅 !! 鏉ョ‘淇� isForce 鏄竷灏斿��
};
post({
@@ -440,5 +487,205 @@
console.log('Failed to load parameter:false');
}
- }
+ },
+ // 澶勭悊澶村儚鐐瑰嚮
+ 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() {
+ if (!this.data.selectedProject) {
+ wx.showToast({
+ title: '璇烽�夋嫨椤圭洰',
+ icon: 'none'
+ });
+ return;
+ }
+ const projectName = this.data.selectedProject === 'JYG' ? '鍢夊唱鍏抽」鐩�' : '姘戝嫟椤圭洰';
+
+ // 淇濆瓨椤圭洰閫夋嫨鍒版湰鍦板瓨鍌�
+ storage.setItem('selectedProject', this.data.selectedProject).then(() => {
+ // 鏇存柊 BASEURL
+ const { PROJECT_URLS } = require('../../api/config.js');
+ const baseUrl = PROJECT_URLS[this.data.selectedProject];
+
+ // 鐩存帴淇敼鍏ㄥ眬鍙橀噺
+ getApp().globalData = getApp().globalData || {};
+ getApp().globalData.baseUrl = baseUrl;
+ getApp().globalData.selectedProject = this.data.selectedProject;
+
+ // 鏍规嵁椤圭洰璁剧疆瀵瑰簲鐨則ag
+ if (this.data.selectedProject === 'JYG') {
+ getApp().globalData.tag = 'ym'; // 鍢夊唱鍏抽」鐩搴攖ag涓簓m
+ } else if (this.data.selectedProject === 'MQ') {
+ getApp().globalData.tag = 'mq'; // 姘戝嫟椤圭洰瀵瑰簲tag涓簃q
+ }
+
+ console.log('宸插垏鎹㈠埌椤圭洰:', projectName, '鍩熷悕:', baseUrl, 'tag:', getApp().globalData.tag);
+
+ this.setData({
+ showProjectDialog: false
+ });
+
+ wx.showToast({
+ title: `宸查�夋嫨${projectName}`,
+ icon: 'success',
+ duration: 2000
+ });
+
+ // 妫�鏌ョ櫥褰曠姸鎬�
+ // setTimeout(() => {
+ // this.checkLoginStatus();
+ // }, 500);
+ }).catch(err => {
+ console.error('淇濆瓨椤圭洰閫夋嫨澶辫触锛�', err);
+ wx.showToast({
+ title: '淇濆瓨澶辫触锛岃閲嶈瘯',
+ icon: 'success',
+ duration: 2000
+ });
+ });
+ },
+
+ // 妫�鏌ョ櫥褰曠姸鎬�
+ checkLoginStatus() {
+ const app = getApp();
+
+ // 妫�鏌ユ槸鍚﹀凡鐧诲綍
+ if (app.globalData.isLoggedIn && app.globalData.sessionId) {
+ // 宸茬櫥褰曪紝閲嶆柊鍔犺浇椤甸潰
+ wx.reLaunch({
+ url: '/pages/home/home'
+ });
+ } else {
+ // 灏濊瘯浠庢湰鍦板瓨鍌ㄨ幏鍙栫敤鎴蜂俊鎭�
+ storage.getItem('userInfo').then(userInfoStr => {
+ if (userInfoStr) {
+ try {
+ const userInfo = JSON.parse(userInfoStr);
+ // 楠岃瘉鐢ㄦ埛淇℃伅鏄惁鏈夋晥
+ if (userInfo && userInfo.sessionId) {
+ // 鎭㈠鐧诲綍鐘舵��
+ app.globalData.sessionId = userInfo.sessionId;
+ app.globalData.token = userInfo.token;
+ app.globalData.userInfo = userInfo;
+ app.globalData.isLoggedIn = true;
+
+ // 宸茬櫥褰曪紝閲嶆柊鍔犺浇椤甸潰
+ wx.reLaunch({
+ url: '/pages/home/home'
+ });
+ return;
+ }
+ } catch (e) {
+ console.error('瑙f瀽鐢ㄦ埛淇℃伅澶辫触:', e);
+ }
+ }
+
+ // 鏈櫥褰曪紝璺宠浆鍒扮櫥褰曢〉闈�
+ wx.redirectTo({
+ url: `/pages/login/login?project=${this.data.selectedProject}`
+ });
+ }).catch(err => {
+ console.error('鑾峰彇鐢ㄦ埛淇℃伅澶辫触:', err);
+ // 鏈櫥褰曪紝璺宠浆鍒扮櫥褰曢〉闈�
+ wx.redirectTo({
+ url: `/pages/login/login?project=${this.data.selectedProject}`
+ });
+ });
+ }
+ },
+ wxLogin(){
+ if(!getApp().globalData.isLoggedIn){
+ const that = this;
+ wx.login({
+ success: function (res) {
+ if (res.code) {
+ var code = res.code;
+ console.log(code);
+ // 灏哻ode鍙戦�佸埌鏈嶅姟鍣ㄨ幏鍙杘penid
+ that.codeLogin(code);
+ } else {
+ console.log('鐧诲綍澶辫触锛�' + res.errMsg);
+
+ }
+ }
+ });
+ }
+ },
+ //寰俊code鐧诲綍
+ codeLogin(codeData) {
+ wx.showLoading({
+ title: '姝e湪鐧诲綍璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧
+ mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false
+ });
+ const data = {
+ code: codeData, //涓存椂鐧诲綍鍑瘉
+ };
+ post({
+ url: "wx/client/code_login",
+ data: data,
+ }).then(response => {
+ // 澶勭悊鎴愬姛鍝嶅簲
+ console.log('璇锋眰鎴愬姛:', response);
+ // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
+ wx.hideLoading();
+ if (response.code === "0001") {
+ //鍋囧涓虹┖鍒欒烦杞埌缁戝畾鐣岄潰
+ if (response.content.client.clientId === "") {
+ wx.navigateTo({
+ url: '/pages/login/login'
+ })
+ } else {
+ //缂撳瓨鍦ㄦ湰鍦�
+ this.setData({
+ isLogin: true
+ })
+ getApp().globalData.sessionId = response.content.client.sessionId
+ storage.setItem("sessionId", response.content.client.sessionId)
+ getApp().globalData.clientId = response.content.client.clientId
+ storage.setItem("clientId", response.content.client.clientId)
+ this.initData();
+ }
+ } else {
+ wx.showToast({
+ title: 'title',
+ icon: 'error',
+ duration: 2000
+ })
+ }
+ }).catch(error => {
+ // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
+ wx.hideLoading();
+ // 澶勭悊閿欒鍝嶅簲
+ console.error('璇锋眰澶辫触:', error);
+ });
+ },
})
\ No newline at end of file
--
Gitblit v1.8.0