沙盘演示系统应用的微信小程序
zuoxiao
2024-10-28 f66a9a2c565966e98720be5e20604c6f75030f82
pages/home/home.js
@@ -31,6 +31,8 @@
    showForceConfirm: false, //是否强制开阀
    lastIntakeName: "",
    isLogin: false, //是否已经登录
    showInfoDialog: false,
  },
  openValve: function (e) {
@@ -44,7 +46,6 @@
        icon: 'error'
      })
    }
  },
  calculateScrollViewHeight: function () {
    wx.createSelectorQuery().selectAll('.list-item').boundingClientRect((rects) => {
@@ -55,7 +56,7 @@
    }).exec();
  },
  startPullDownRefresh() {
    if(this.data.isLogin){
    if (this.data.isLogin) {
      if (!this.data.isWXRefreshing) {
        var self = this;
        console.log(this.data.isRefreshing);
@@ -64,14 +65,12 @@
        });
        this.getOpenList();
      }
    }else{
    } else {
      wx.showToast({
        title: '请先登录',
        icon: 'error'
      })
    }
  },
  //获取用户数据
  getUserData() {
@@ -115,6 +114,9 @@
      const app = getApp();
      storage.getItem('sessionId').then((data) => {
        app.globalData.sessionId = data;
        this.setData({
          isLogin: true
        })
        if (app.globalData.sessionId) {
          this.getOpenList();
          this.getUserDataBySession();
@@ -324,32 +326,44 @@
   * 获取为关阀记录
   */
  getOpenList() {
    const app = getApp();
    const params = {
      url: 'wx/valve/get',
      data: {
        operator: app.globalData.sessionId
      }
    };
    get(params).then(data => {
      this.setData({
        listData: data.content,
        isRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
        isWXRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
      })
      this.updateDisplayText();
    }).catch(err => {
      // 错误回调
      this.setData({
        isRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
        isWXRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
      })
    if (this.data.isLogin) {
      const app = getApp();
      const params = {
        url: 'wx/valve/get',
        data: {
          operator: app.globalData.sessionId
        }
      };
      get(params).then(data => {
        this.setData({
          listData: data.content,
          isRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
          isWXRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
        })
        this.updateDisplayText();
      }).catch(err => {
        // 错误回调
        this.setData({
          isRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
          isWXRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
        })
        wx.showToast({
          title: err.msg,
          icon: 'error',
          duration: 3000
        })
      });
    } else {
      wx.showToast({
        title: err.msg,
        icon: 'error',
        duration: 3000
        title: '请先登录',
        icon: 'error'
      })
    });
      this.setData({
        isRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
        isWXRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
      })
    }
  },
  /**
   * 确认关闭回调
@@ -403,25 +417,36 @@
   * 扫码开阀
   */
  scenCode() {
    const that = this;
    wx.scanCode({
      success(res) {
        console.log(res.result); // 当且仅当扫码为非微信二维码时,会返回result
        if (res.result.startsWith("content://")) {
          let jsonStr = res.result.replace("content://", "")
          try {
            that.saveData(jsonStr)
          } catch (error) {
            console.error('Error parsing JSON:', error);
    if (this.data.isLogin) {
      const that = this;
      wx.scanCode({
        success(res) {
          console.log(res.result); // 当且仅当扫码为非微信二维码时,会返回result
          if (res.result.startsWith("content://")) {
            let jsonStr = res.result.replace("content://", "")
            try {
              that.saveData(jsonStr)
            } catch (error) {
              console.error('Error parsing JSON:', error);
            }
          } else {
            wx.navigateTo({
              url: '/pages/openCard/openCard?intakeName=' + res.result,
            })
            // that.postOppenValva()
          }
        } else {
          that.postOppenValva(res.result)
        },
        fail(err) {
          console.error(err);
        }
      },
      fail(err) {
        console.error(err);
      }
    })
      })
    } else {
      wx.showToast({
        title: '请先登录',
        icon: 'error'
      })
    }
  },
  confirmForceDialog() {
    console.log("confirmForceDialog");
@@ -594,7 +619,7 @@
        userPhone: "请登录",
        userName: "未登录",
        listData: [],
        isLogin:false
        isLogin: false
      })
      app.globalData.sessionId = "";
      app.globalData.clientId = ""
@@ -611,5 +636,17 @@
      // 处理错误响应
      console.error('请求失败:', error);
    });
  },
  //点击提示按钮
  infoShow() {
    this.setData({
      showInfoDialog: true
    })
  },
  //提示窗确认按钮
  confirmBtnInfoDialog() {
    this.setData({
      showInfoDialog: false
    })
  }
})