沙盘演示系统应用的微信小程序
zuoxiao
2024-12-27 c768d20f2256ba40ebf6bc1be984c667d6bc7a11
pages/home/home.js
@@ -34,6 +34,7 @@
    showInfoDialog: false,
    showTipDialog: false,
    options: '',
    showUnBind: false
  },
  openValve: function (e) {
@@ -91,7 +92,7 @@
  onLoad(options) {
    //当开阀成功后调用刷新
    console.log("onLoad:" + options.param);
    if (options.param) {
    if (options.param === "1" || options.param === "2") {
      this.setData({
        options: options,
        isLogin: true,
@@ -113,40 +114,51 @@
          isLogin: true
        })
        if (app.globalData.sessionId) {
          this.getOpenList();
          this.getUserDataBySession();
        }
      }).catch((err) => {});
      storage.getItem('clientId').then((data) => {
        app.globalData.clientId = data;
        this.getOpenList();
      }).catch((err) => {});
    } else {
      //本地没有缓存微信登录
      this.wxLogin();
    }
    if (this.data.options.param) {
    if (this.data.options.param === "1") {
      this.setData({
        showTipDialog: true,
        tipData: "开阀命令下发成功,稍后请刷新快速关阀列表查看执行结果。"
        tipData: "开阀命令下发成功,因开阀需要时间,约20-60秒后可刷新快速关阀列表查看执行结果。"
      })
      setTimeout(() => {
        this.getOpenList();
      }, 20000)
    } else if (this.data.options.param === "2") {
      this.setData({
        showTipDialog: true,
        tipData: "预约开阀命令下发成功,当到达预约时间并且成功开阀后快速关阀列表会显示未关阀记录"
      })
      this.getOpenList();
    }
  },
  wxLogin() {
    const that = this;
    wx.login({
      success: function (res) {
        if (res.code) {
          var code = res.code;
          console.log(code);
          // 将code发送到服务器获取openid
          that.codeLogin(code);
        } else {
          console.log('登录失败!' + res.errMsg);
    // if (!this.data.isLogin) {
      const that = this;
      wx.login({
        success: function (res) {
          if (res.code) {
            var code = res.code;
            console.log(code);
            // 将code发送到服务器获取openid
            that.codeLogin(code);
          } else {
            console.log('登录失败!' + res.errMsg);
          }
        }
      }
    });
      });
    // }
  },
  //微信code登录
  codeLogin(codeData) {
@@ -268,7 +280,8 @@
    this.setData({
      showForceConfirm: false,
      showConfirm: false,
      showTipDialog: false
      showTipDialog: false,
      showUnBind: false
    });
  },
  /**
@@ -306,9 +319,11 @@
        this.setData({
          isLogin: true,
          showTipDialog: true,
          tipData: "关阀命令下发成功,稍后请刷新快速关阀列表查看执行结果。"
          tipData: "关阀命令下发成功,约20-60秒后可刷新快速关阀列表查看执行结果。"
        })
        this.getOpenList();
        setTimeout(() => {
          this.getOpenList();
        }, 40000)
      } else {
        wx.showToast({
          title: '命令执行失败',
@@ -337,7 +352,7 @@
      const params = {
        url: 'wx/valve/get',
        data: {
          operator: app.globalData.sessionId
          operator: app.globalData.clientId
        }
      };
      get(params).then(data => {
@@ -552,9 +567,6 @@
      title: '正在强制删除请稍候...', // 加载提示文字
      mask: true // 是否显示透明蒙层,防止触摸穿透,默认为 false
    });
    that.setData({
      lastIntakeName: intakeName
    })
    const data = {
      vcNum: item.vcNum, //取水口ID
      rtuAddr: item.rtuAddr, //阀控器地址
@@ -586,9 +598,22 @@
      } 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
        displayText,
        deleteText,
        time
      }; // 保留所有其他字段,并添加 displayText 字段
    });
    // 更新列表数据
@@ -598,11 +623,14 @@
  },
  //解绑
  unbind() {
    //清空数据
    this.setData({
      userPhone: "未登录",
      userName: "请登录",
      listData: []
      showUnBind: true
    })
  },
  //确认解绑
  unBindPost() {
    this.setData({
      showUnBind: false
    })
    wx.showLoading({
      title: '正在解绑请稍候...', // 加载提示文字
@@ -641,6 +669,11 @@
      wx.hideLoading();
      // 处理错误响应
      console.error('请求失败:', error);
      wx.showToast({
        title: '解绑失败',
        icon: 'error',
        duration: 3000
      })
    });
  },
  //点击提示按钮
@@ -654,5 +687,29 @@
    this.setData({
      showInfoDialog: false
    })
  },
  //处理时间去掉年月日
  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}`;
  },
  onShareAppMessage: function (options) {
    // 设置分享内容
    return {
      title: '大禹灌溉助手', // 分享标题
      path: '/pages/home/home', // 分享路径,该路径需要是当前小程序存在的页面路径
      imageUrl: '/images/logo2.jpg', // 分享图标,可以是网络图片路径或本地图片路径
      success: function (res) {
        // 分享成功的回调函数
      },
      fail: function (res) {
        // 分享失败的回调函数
      }
    };
  }
})