管灌系统农户端微信小程序(嘉峪关应用)
优化首页和灌溉页面的样式,添加当前项目显示;重构项目配置,确保项目登录需求一致性;更新登录页面逻辑,简化项目选择和信息展示,提升用户体验。
8个文件已修改
298 ■■■■ 已修改文件
pages/home/home.js 109 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/home/home.wxml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/home/home.wxss 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/irrigation/irrigation.js 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/login/login.js 75 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/login/login.wxml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/waterIntake/waterIntake.js 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/projectConfig.js 55 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/home/home.js
@@ -197,9 +197,19 @@
                    const projectConfig = PROJECT_CONFIG[project];
                    if (projectConfig) {
                        getApp().globalData.tag = projectConfig.tag;
            // 根据项目是否需要登录,设置不同的userName
            if (projectConfig.needLogin === false) {
              // 不需要登录的项目,显示项目名称
                        this.setData({
                            userName: projectConfig.displayName
                        });
            } else {
              // 需要登录的项目,显示"请点击登录"
              this.setData({
                userName: "请点击登录"
              });
            }
                    }
                    // 根据项目设置对应的operator和clientId
@@ -696,13 +706,6 @@
                        duration: 3000
                    });
                }
            } else {
                // 其他错误,显示错误信息
                wx.showToast({
                    title: err.msg || '获取用户信息失败',
                    icon: 'none',
                    duration: 3000
                });
            }
        });
    },
@@ -858,6 +861,14 @@
        const currentProject = app.globalData.selectedProject;
        const projectConfig = PROJECT_CONFIG[currentProject];
        const needLogin = projectConfig && projectConfig.needLogin;
    // 根据项目是否需要登录,设置不同的userName
    if (projectConfig && projectConfig.needLogin === false) {
      // 不需要登录的项目,显示项目名称
      this.setData({
        userName: projectConfig.displayName
      });
    }
        // 尝试获取用户数据和已开阀记录
        try {
@@ -1030,9 +1041,9 @@
        const isProjectChanged = currentProject && currentProject !== newProject;
        // 添加二次确认
        const confirmText = isProjectChanged
            ? `确定要将项目从"${PROJECT_CONFIG[currentProject]?.displayName || '当前项目'}"切换到"${projectConfig.displayName}"吗?`
            : `确定选择"${projectConfig.displayName}"项目吗?`;
    const confirmText = isProjectChanged ?
      `确定要将项目从"${PROJECT_CONFIG[currentProject]?.displayName || '当前项目'}"切换到"${projectConfig.displayName}"吗?` :
      `确定选择"${projectConfig.displayName}"项目吗?`;
            
        wx.showModal({
            title: isProjectChanged ? '确认切换项目' : '确认选择项目',
@@ -1062,24 +1073,46 @@
            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) {
        // 不需要登录的项目,显示项目名称作为userName
            this.setData({
                userName: "请登录",
          userName: projectConfig.displayName,
                userPhone: "",
                listData: []
            });
      } else {
        // 需要登录的项目,显示"请点击登录"
        this.setData({
          userName: "请点击登录",
          userPhone: "",
          listData: []
        });
      }
        }
        // 保存项目选择到本地存储
@@ -1102,11 +1135,6 @@
            // 通过配置对象统一设置项目参数
            getApp().globalData.tag = projectConfig.tag;
            // 设置用户界面显示的项目名称
            this.setData({
                userName: projectConfig.displayName
            });
            // 对于不需要登录的项目,直接设置operator和clientId
            if (!projectConfig.needLogin && projectConfig.operatorId) {
@@ -1150,6 +1178,16 @@
            });
            setTimeout(() => {
                console.log('项目已切换,正在初始化数据');
        // 确保显示正确的用户名
        if (!projectConfig.needLogin) {
          this.setData({
            userName: projectConfig.displayName
          });
        } else {
          this.setData({
            userName: "请点击登录"
          });
        }
                this.initData();
            }, 1000);
@@ -1367,9 +1405,17 @@
    wxLogin() {
        // 检查当前项目是否需要登录
        const currentProject = getApp().globalData.selectedProject;
        if (currentProject && PROJECT_CONFIG[currentProject] && !PROJECT_CONFIG[currentProject].needLogin) {
    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) {
@@ -1391,10 +1437,11 @@
                            wx.hideLoading();
                            if (response.code === "0001") {
                                if (response.content.client.clientId === "") {
                                    // 未绑定账号,跳转到登录页面
                                    // wx.navigateTo({
                                    //   url: `/pages/login/login?project=${this.data.selectedProject}`
                                    // });
                  // 未绑定账号,跳转到登录页面并传递当前项目信息
                  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,
@@ -1439,26 +1486,34 @@
                                        });
                                }
              } 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
                                });
                                // wx.navigateTo({
                                //   url: `/pages/login/login?project=${this.data.selectedProject}`
                                // });
                            }
                        }).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'
                            });
                            // wx.redirectTo({
                            //   url: `/pages/login/login?project=${this.data.selectedProject}`
                            // });
              }
                        });
                    } else {
                        wx.hideLoading();
pages/home/home.wxml
@@ -3,7 +3,13 @@
  <view class="head-wrapper">
    <view class="head-top">
      <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>
pages/home/home.wxss
@@ -38,6 +38,7 @@
    align-items: left;
    justify-content: center;
    margin-left: 15rpx;
    margin-bottom: 70rpx;
}
.head-button-wrapper {
@@ -753,3 +754,43 @@
    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;
}
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({
pages/login/login.js
@@ -185,12 +185,11 @@
      manualNavigate: false // 标记是否是通过编程方式导航的
    });
    
    // 获取选择的项目 - 优先使用URL参数
    // 从URL参数获取项目信息
    if (options && options.project) {
      const project = options.project;
      const projectName = project === 'JYG' ? '嘉峪关项目' :
                         project === 'MQ' ? '民勤项目' :
                         project === 'TEST' ? '测试项目' : '未知项目';
      // 直接使用传入的项目名称,不再手动转换
      const projectName = options.projectName || '默认项目';
      
      console.log(`从URL参数获取项目信息: ${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);
          // 最后的备用方案:使用redirectTo
          setTimeout(() => {
            console.log('延迟使用redirectTo尝试返回首页');
            wx.redirectTo({
              url: '/pages/home/home?fromLogin=true',
              success: () => console.log('redirectTo成功返回首页'),
              fail: (err) => console.error('所有返回方法都失败:', err)
            });
          }, 100);
        }
      });
    };
    
    // 先尝试使用switchTab(某些版本可能将首页设置为tabBar)
    wx.switchTab({
      url: '/pages/home/home',
      success: () => console.log('switchTab成功返回首页'),
      fail: (err) => {
        console.log('switchTab失败(可能首页不在tabBar中):', err);
        useReLaunch();
      }
    });
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
@@ -469,11 +414,6 @@
        getApp().globalData.clientId = String(data.content.clientId);
        storage.setItem("clientId", String(data.content.clientId));
        
        // 设置当前项目的tag
        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);
        });
      }
    });
  },
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>
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
            });
          }
utils/projectConfig.js
@@ -31,9 +31,8 @@
  TEST: {
    tag: 'ym',
    displayName: '测试项目',
    operatorId: '2024122617295800009', // 统一ID用于operator和clientId
    vcId: '2024122617295800009',
    needLogin: false, // 不需要登录
    operatorId: '', // 统一ID用于operator和clientId
    needLogin: true, // 需要登录
    serverId: '166',
    get serverUrl() {
      return SERVER_INFO.URL_166;
@@ -42,8 +41,8 @@
  JC: {
    tag: 'jc',
    displayName: '金昌项目',
    operatorId: '2025041710412400006', // 统一ID用于operator和clientId
    needLogin: false, // 不需要登录
    operatorId: '', // 统一ID用于operator和clientId 2025041710412400006
    needLogin: true, // 需要登录
    serverId: '121',
    get serverUrl() {
      return SERVER_INFO.URL_121;
@@ -51,49 +50,9 @@
  },
  GSCLT: {
    tag: 'test',
    displayName: '甘肃农科院-崔龙天',
    operatorId: '2025041912201400006', // 统一ID用于operator和clientId
    needLogin: false, // 不需要登录
    serverId: '233',
    get serverUrl() {
      return SERVER_INFO.URL_233;
    }
  },
  GSWJ: {
    tag: 'test',
    displayName: '甘肃农科院-王娟',
    operatorId: '2025042115424500006', // 统一ID用于operator和clientId
    needLogin: false, // 不需要登录
    serverId: '233',
    get serverUrl() {
      return SERVER_INFO.URL_233;
    }
  },
  GSCLT2: {
    tag: 'test',
    displayName: '甘肃农科院-晁玉亮',
    operatorId: '2025042115452400006', // 统一ID用于operator和clientId
    needLogin: false, // 不需要登录
    serverId: '233',
    get serverUrl() {
      return SERVER_INFO.URL_233;
    }
  },
  GSCLT3: {
    tag: 'test',
    displayName: '甘肃农科院-黄虎生',
    operatorId: '2025042115454100006', // 统一ID用于operator和clientId
    needLogin: false, // 不需要登录
    serverId: '233',
    get serverUrl() {
      return SERVER_INFO.URL_233;
    }
  },
  GSCLT4: {
    tag: 'test',
    displayName: '甘肃农科院-朱兆宝',
    operatorId: '2025042115455900006', // 统一ID用于operator和clientId
    needLogin: false, // 不需要登录
    displayName: '甘肃农科院',
    operatorId: '', // 统一ID用于operator和clientId
    needLogin: true, // 不需要登录
    serverId: '233',
    get serverUrl() {
      return SERVER_INFO.URL_233;