管灌系统农户端微信小程序(嘉峪关应用)
pages/home/home.js
@@ -61,7 +61,7 @@
          icon: 'error',
          duration: 2000
        });
        // 获取项目配置
        const projectConfig = PROJECT_CONFIG[currentProject];
        if (projectConfig) {
@@ -82,7 +82,7 @@
        return;
      }
    }
    // 已登录或不需要登录的项目,执行开阀操作
    wx.navigateTo({
      url: '/pages/waterIntake/waterIntake',
@@ -226,7 +226,7 @@
          const projectConfig = PROJECT_CONFIG[project];
          if (projectConfig) {
            getApp().globalData.tag = projectConfig.tag;
            // 根据项目是否需要登录,设置不同的userName
            if (projectConfig.needLogin === false) {
              // 不需要登录的项目,显示项目名称
@@ -359,7 +359,7 @@
            this.setData({
              isFromLogin: true
            });
            // 登录成功后刷新数据
            console.log('登录成功后刷新数据');
            this.initData();
@@ -373,7 +373,7 @@
    // 初始化处理
    if (fromLogin || this.data.isFromLogin) {
      console.log('onShow: 从登录页返回,不进行登录检查');
      // 如果是从登录页返回,重新加载数据
      this.initData();
    } else {
@@ -463,7 +463,7 @@
          icon: 'error',
          duration: 2000
        });
        // 获取项目配置
        const projectConfig = PROJECT_CONFIG[currentProject];
        if (projectConfig) {
@@ -484,7 +484,7 @@
        return;
      }
    }
    // 已登录或不需要登录的项目,执行查看记录操作
    wx.navigateTo({
      url: '/pages/valveList/valveList',
@@ -494,6 +494,63 @@
    wx.showToast({
      title: '暂未开放',
      icon: 'none'
    })
  },
  // 综合站监测
  monitor() {
    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) {
                // 用户点击确认,直接调用wxLogin方法
                this.wxLogin();
              }
            }
          });
        }
        return;
      } else if (!PROJECT_CONFIG[currentProject].monitor) {
        // 未登录,显示提示并阻止操作
        wx.showToast({
          title: '当前项目不可用',
          icon: 'error',
          duration: 2000
        });
        return;
      }
    } else if (!PROJECT_CONFIG[currentProject].monitor) {
      // 未登录,显示提示并阻止操作
      wx.showToast({
        title: '当前项目不可用',
        icon: 'error',
        duration: 2000
      });
      return;
    }
    // 已登录或不需要登录的项目,跳转到综合站监测页面
    wx.navigateTo({
      url: '/pages/stationMonitor/stationMonitor',
    })
  },
  //解绑用户
@@ -555,7 +612,7 @@
          icon: 'error',
          duration: 2000
        });
        // 获取项目配置
        const projectConfig = PROJECT_CONFIG[currentProject];
        if (projectConfig) {
@@ -576,10 +633,67 @@
        return;
      }
    }
    // 已登录或不需要登录的项目,执行轮灌操作
    wx.navigateTo({
      url: '/pages/irrigation/irrigation',
    })
  },
  //跳转模型计算
  modeCompute(){
    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) {
                // 用户点击确认,直接调用wxLogin方法
                this.wxLogin();
              }
            }
          });
        }
        return;
      } else if (!PROJECT_CONFIG[currentProject].monitor) {
        // 未登录,显示提示并阻止操作
        wx.showToast({
          title: '当前项目不可用',
          icon: 'error',
          duration: 2000
        });
        return;
      }
    } else if (!PROJECT_CONFIG[currentProject].monitor) {
      // 未登录,显示提示并阻止操作
      wx.showToast({
        title: '当前项目不可用',
        icon: 'error',
        duration: 2000
      });
      return;
    }
    // 已登录或不需要登录的项目,执行轮灌操作
    wx.navigateTo({
      url: '/pages/modeCompute/modeCompute',
    })
  },
  handleChange(e) {
@@ -841,7 +955,7 @@
          icon: 'error',
          duration: 2000
        });
        // 获取项目配置
        const projectConfig = PROJECT_CONFIG[currentProject];
        if (projectConfig) {
@@ -862,7 +976,7 @@
        return;
      }
    }
    // 已登录或不需要登录的项目,执行扫码操作
    const that = this;
    wx.scanCode({
@@ -986,7 +1100,7 @@
            app.globalData.clientId = jsonObj.clientId || clientId;
            app.globalData.tag = jsonObj.tag;
            app.globalData.isLoggedIn = true;
            // 直接从userData设置用户信息
            if (jsonObj.clientName && jsonObj.phone) {
              this.setData({
@@ -997,7 +1111,7 @@
              // 如果userData中没有用户信息,调用接口获取
              this.getUserDataBySession();
            }
            console.log("userData已加载:", userData);
          } catch (e) {
            console.error('userData解析失败:', e);
@@ -1015,14 +1129,14 @@
          app.globalData.isLoggedIn = true;
          this.getUserDataBySession();
        }
        // 无论如何都尝试获取开阀列表
        this.getOpenList();
      }).catch(err => {
        console.error('恢复登录状态失败:', err);
        this.getOpenList();
      });
      return;
    }
@@ -1485,7 +1599,7 @@
          // 此处不做跳转,注释掉原有代码
          // const projectInfo = PROJECT_CONFIG[currentProject];
          // const loginType = projectInfo?.loginType || 'code'; // 默认使用验证码登录
          // if (loginType === 'account') {
          //   // 账号密码登录
          //   wx.navigateTo({
@@ -1527,7 +1641,7 @@
        // 此处不做跳转,注释掉原有代码
        // const projectInfo = PROJECT_CONFIG[currentProject];
        // const loginType = projectInfo?.loginType || 'code'; // 默认使用验证码登录
        // if (loginType === 'account') {
        //   // 账号密码登录
        //   wx.navigateTo({
@@ -1619,7 +1733,7 @@
    const currentProject = getApp().globalData.selectedProject;
    if (currentProject && PROJECT_CONFIG[currentProject]) {
      const projectConfig = PROJECT_CONFIG[currentProject];
      if (!projectConfig.needLogin) {
        console.log('wxLogin: 当前项目不需要登录:', currentProject);
        // 不需要登录的项目,显示项目名称
@@ -1652,7 +1766,7 @@
                  // 未绑定账号,根据项目配置的loginType跳转到相应的登录页面
                  const projectInfo = PROJECT_CONFIG[this.data.selectedProject];
                  const loginType = projectInfo?.loginType || 'code'; // 默认使用验证码登录
                  if (loginType === 'account') {
                    // 账号密码登录
                    wx.navigateTo({
@@ -1712,7 +1826,7 @@
                // 未绑定账号,根据项目配置的loginType跳转到相应的登录页面
                const projectInfo = PROJECT_CONFIG[this.data.selectedProject];
                const loginType = projectInfo?.loginType || 'code'; // 默认使用验证码登录
                if (loginType === 'account') {
                  // 账号密码登录
                  wx.navigateTo({
@@ -1734,11 +1848,11 @@
            }).catch(error => {
              wx.hideLoading();
              console.error('登录请求失败:', error);
              if(error.code==="1003"){
              if (error.code === "1003") {
                // 未绑定账号,根据项目配置的loginType跳转到相应的登录页面
                const projectInfo = PROJECT_CONFIG[this.data.selectedProject];
                const loginType = projectInfo?.loginType || 'code'; // 默认使用验证码登录
                if (loginType === 'account') {
                  // 账号密码登录
                  wx.navigateTo({
@@ -1750,7 +1864,7 @@
                    url: `/pages/login/login?project=${this.data.selectedProject}&projectName=${projectInfo.displayName}`
                  });
                }
              }else{
              } else {
                wx.showToast({
                  title: '登录失败,请重试',
                  icon: 'none'
@@ -2022,7 +2136,7 @@
    const currentProject = app.globalData.selectedProject;
    if (currentProject && PROJECT_CONFIG[currentProject]) {
      const projectConfig = PROJECT_CONFIG[currentProject];
      if (!projectConfig.needLogin) {
        console.log('handleUserTap: 当前项目不需要登录:', currentProject);
        // 不需要登录的项目,显示项目名称
@@ -2031,10 +2145,10 @@
        });
        return;
      }
      // 根据项目配置的loginType决定跳转到哪个登录页面
      const loginType = projectConfig.loginType || 'code'; // 默认使用验证码登录
      if (loginType === 'account') {
        // 账号密码登录
        wx.navigateTo({