沙盘演示系统应用的微信小程序
zuoxiao
2024-11-01 ddbd8c7ea87b66d5a9c4362ce284d12a4ae970d1
pages/home/home.js
@@ -31,6 +31,9 @@
    showForceConfirm: false, //是否强制开阀
    lastIntakeName: "",
    isLogin: false, //是否已经登录
    showInfoDialog: false,
    showTipDialog: false,
    options: '',
  },
  openValve: function (e) {
@@ -44,7 +47,6 @@
        icon: 'error'
      })
    }
  },
  calculateScrollViewHeight: function () {
    wx.createSelectorQuery().selectAll('.list-item').boundingClientRect((rects) => {
@@ -55,7 +57,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 +66,12 @@
        });
        this.getOpenList();
      }
    }else{
    } else {
      wx.showToast({
        title: '请先登录',
        icon: 'error'
      })
    }
  },
  //获取用户数据
  getUserData() {
@@ -89,19 +89,13 @@
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // 使用 wx.nextTick 等待页面渲染完成
    wx.nextTick(() => {
      this.calculateScrollViewHeight();
    });
    //当开阀成功后调用刷新
    console.log("onLoad:" + options.param);
    if (options.param) {
      wx.showToast({
        title: '开阀成功',
        icon: 'success',
        duration: 3000
      this.setData({
        options: options,
        isLogin: true,
      })
      this.getOpenList();
    }
  },
@@ -115,6 +109,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();
@@ -126,6 +123,14 @@
    } else {
      //本地没有缓存微信登录
      this.wxLogin();
    }
    if (this.data.options.param) {
      this.setData({
        showTipDialog: true,
        tipData: "开阀命令下发成功,稍后请刷新快速关阀列表查看执行结果。"
      })
      this.getOpenList();
    }
  },
  wxLogin() {
@@ -255,13 +260,15 @@
    this.setData({
      showConfirm: false,
      showErrorDialog: false,
      showForceConfirm: false
      showForceConfirm: false,
      showTipDialog: false
    });
  },
  cancelDialog() {
    this.setData({
      showForceConfirm: false,
      showConfirm: false
      showConfirm: false,
      showTipDialog: false
    });
  },
  /**
@@ -296,14 +303,15 @@
      wx.hideLoading();
      this.getOpenList();
      if (response.content.data.success) {
        wx.showToast({
          title: '关阀成功',
          icon: 'success',
          duration: 3000
        this.setData({
          isLogin: true,
          showTipDialog: true,
          tipData: "关阀命令下发成功,稍后请刷新快速关阀列表查看执行结果。"
        })
        this.getOpenList();
      } else {
        wx.showToast({
          title: '关阀失败',
          title: '命令执行失败',
          icon: 'error',
          duration: 3000
        })
@@ -324,32 +332,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 +423,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");
@@ -569,8 +600,8 @@
  unbind() {
    //清空数据
    this.setData({
      userPhone: "请登录",
      userName: "未登录",
      userPhone: "未登录",
      userName: "请登录",
      listData: []
    })
    wx.showLoading({
@@ -594,7 +625,7 @@
        userPhone: "请登录",
        userName: "未登录",
        listData: [],
        isLogin:false
        isLogin: false
      })
      app.globalData.sessionId = "";
      app.globalData.clientId = ""
@@ -611,5 +642,17 @@
      // 处理错误响应
      console.error('请求失败:', error);
    });
  },
  //点击提示按钮
  infoShow() {
    this.setData({
      showInfoDialog: true
    })
  },
  //提示窗确认按钮
  confirmBtnInfoDialog() {
    this.setData({
      showInfoDialog: false
    })
  }
})