hailu
2023-11-21 f3773d4aa18f3b0814d9720e26fa61b762020eb2
GoldC/pages/home/home.js
@@ -8,9 +8,10 @@
   */
  data: {
    manageList: [
      { title: '网关设备', img: '', type: '在线', text: '影子' },
      { title: '网关设备', img: '', type: '在线', text: '影子' },
    ]
      // { title: '网关设备', img: '', type: '在线', text: '影子' },
      // { title: '网关设备', img: '', type: '在线', text: '影子' },
    ],
    statuList: []
  },
@@ -18,7 +19,11 @@
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // var user = wx.getStorageSync('user')
    var user = wx.getStorageSync('user')
    // this.getStatus()
    // this.getProfile()
    // this.getShortList()
  },
  goScanCode() {
@@ -26,10 +31,94 @@
      url: '/pages/scanCode/scanCode',
    })
  },
  goDetails() {
  goDetails(e) {
    var $id = e.currentTarget.dataset.index;
    let params=JSON.stringify(this.data.manageList[$id])
    wx.navigateTo({
      url: '/pages/deviceDetails/deviceDetails',
      url: `/pages/deviceDetails/deviceDetails?params=${params}`,
    })
  },
  getProfile() {
    wx.request({
      url: 'https://puyue.yhupai.com/prod-api/system/user/profile',
      method: "GET",
      header: {
        "Access-Control-Allow-Headers": 'token',
        Authorization: `Bearer ${wx.getStorageSync('token')}`
      },
      success: (res, header) => {
        if (res.data.code != 200) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          });
        } else {
          wx.setStorageSync('userInfo', res.data.data)
        }
      }
    })
  },
  getShortList() {
    // let data = {
    //   status:3
    // }
    wx.request({
      url: 'https://puyue.yhupai.com/prod-api/iot/device/shortList',
      method: "GET",
      header: {
        "Access-Control-Allow-Headers": 'token',
        Authorization: `Bearer ${wx.getStorageSync('token')}`
      },
      // params: data,
      success: (res, header) => {
        if (res.data.code != 200) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          });
        } else {
          console.log(this.data.statuList);
          let arr = res.data.rows
          for (let i = 0; i < arr.length; i++) {
            for (let k = 0; k < this.data.statuList.length; k++) {
              if (arr[i].status == this.data.statuList[k].dictValue) {
                arr[i].dictLabel = this.data.statuList[k].dictLabel
              }
            }
          }
          console.log(arr);
          this.setData({
            manageList: arr
          })
          wx.setStorageSync('deviceList', arr)
        }
      }
    })
  },
  getStatus() {
    wx.request({
      url: 'https://puyue.yhupai.com/prod-api/system/dict/data/type/iot_device_status',
      method: "GET",
      header: {
        "Access-Control-Allow-Headers": 'token',
        Authorization: `Bearer ${wx.getStorageSync('token')}`
      },
      success: (res, header) => {
        if (res.data.code != 200) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          });
        } else {
          // wx.setStorageSync('userInfo', res.data.data)
          this.setData({
            statuList: res.data.data
          })
        }
      }
    })
  },
  /**
@@ -37,13 +126,17 @@
   */
  onReady: function () {
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var user = wx.getStorageSync('user')
    this.getStatus()
    this.getProfile()
    this.getShortList()
    console.log(111);
  },