// pages/powerstation/index.js const api = require('../../api/index.js'); Page({ /** * 页面的初始数据 */ data: { infolist:{}, options:{}, msg:'' }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { console.log(options); this.setData({ options:options }) this.getinfo() }, getinfo(){ let _this =this api.request(`/station/${this.data.options.id}/info`, 'POST') .then((res) => { wx.showToast({ title: res.msg, icon: 'none', }); this.setData({ msg:res.msg, infolist:res.data }) if (res.msg =='成功') { api.request('/station/list/stationName', 'POST') .then((ress) => { for (let index = 0; index < ress.data.length; index++) { if (_this.data.options.id == ress.data[index].id) { wx.setStorage({ key: 'station', // 本地缓存中指定的 key data: ress.data[index], success: function () { } }); } } }) } }) .catch((err) => { console.error('请求失败:', err); // 在这里处理请求失败的情况 }); }, // 绑定 signout(){ let data ={ deviceId:this.data.options.id, UnbindStart:1 } api.request('/system/tenantpower/APP/bind', 'POST',data ) .then((res) => { wx.showToast({ title: res.msg, icon: 'none', }); this.getinfo() }) .catch((err) => { console.error('请求失败:', err); // 在这里处理请求失败的情况 }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })