// pages/home/home.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { manageList: [ // { title: '网关设备', img: '', type: '在线', text: '影子' }, // { title: '网关设备', img: '', type: '在线', text: '影子' }, ], statuList: [] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // var user = wx.getStorageSync('user') var user = wx.getStorageSync('user') // this.getStatus() // this.getProfile() // this.getShortList() }, goScanCode() { wx.navigateTo({ url: '/pages/scanCode/scanCode', }) }, goDetails(e) { var $id = e.currentTarget.dataset.index; let params=JSON.stringify(this.data.manageList[$id]) wx.navigateTo({ 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() { this.setData({ manageList:[] }) // let data = { // repairFlag: 0 // } 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')}` }, // data: 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 }) } } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.getStatus() this.getProfile() this.getShortList() console.log(111); }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })