// pages/home/home.js const app = getApp(); Page({ /** * 页面的初始数据 */ data: { navBarHeight: app.globalData.navBarHeight, MenuButtonheight: app.globalData.MenuButtonheight, MenuButtonTop: app.globalData.MenuButtonTop, rightId:wx.getStorageSync('rightId') || 0, nvabarData: { nvabarData: { showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示 title: 'Oh Play', //导航栏 中间的标题 callback() { wx.navigateBack({ delta: 1, }) } }, isNotruter: false, deviceList: [], bannerList: [], showLogin: false, selectIndex: -1, } }, changeRole() { app.changeUserRight() }, // 删除设备 deleteDeviceTap: function () { }, // 设备详情页 devieDetailPageTap: function () { }, deviceItemTap: function () { this.setData({ // selectIndex = index }); }, changeDeviceTap: function () { }, login() { wx.login({ success: res => { let phone = undefined; try { var value = wx.getStorageSync('userInfo') if (value) { phone = value.phone || undefined; }; } catch (e) { // Do something when catch error }; // 请求登录 login({code: res.code, phone}).then((res)=> { app.globalData.userInfo = res; wx.setStorage({ key: "userInfo", data: res }); // 需要用授权登录 if((res.isNewUser && res.isNewUser === true) || !phone) { _this.setData({ showLogin: true, }); return; }; // 获取设备本地数据 this.getDeviceData(); _this.setData({ showLogin: false, }); wx.setStorage({ key:"token", data: JSON.stringify({ id: res.userId, token: res.accessToken, }), }); }); }, }) }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { _this = this; // 版本自动更新代码 const updateManager = wx.getUpdateManager(); updateManager.onUpdateReady(function () { _this.setData({ newVersion: true }); }) updateManager.onUpdateFailed(function () { // 新的版本下载失败 wx.showModal({ title: '已有新版本咯', content: '请您删除当前小程序,重新打开呦~', showCancel: false }) }) wx.showLoading({ title: '加载中', }); // 登录 this.login(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: 0 }) } app.eventBus.on('rightChange', data => { if (data !== this.data.rightId) { this.setData({ rightId: data }) } }) this.setData({ deviceList: [ { "devName": "名称1", "state": "online", "pic": "../../img/g.png", "power": 40, }, { "devName": "名称2", "state": "online", "pic": "../../img/g.png", "power": 50, }, { "devName": "名称3", "state": "online", "pic": "../../img/g.png", "power": 60, }, ], selectIndex: 0, isLoginWx: true, bannerList: ["https://img1.baidu.com/it/u=2003442481,2528062378&fm=253&fmt=auto&app=138&f=JPG?w=499&h=182", "https://hbimg.huabanimg.com/0ff93215a6d8d1c5f80117fdbfa24936dbd9097026ad99-CNduY8_fw658", "https://img.zcool.cn/community/0177ed5f365bdaa801215aa0a0c1c3.jpg@1280w_1l_2o_100sh.jpg"], }); }, addDeviceTap() { wx.navigateTo({ url: './../bluConnect/bleconnect', }); }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })