|
@@ -1,5 +1,7 @@
|
|
|
// pages/home/home.js
|
|
|
const app = getApp();
|
|
|
+const { login } = require('./../../utils/api.js');
|
|
|
+const { selectIndex, eventOn } = require('./../../custom-tab-bar/tabbar.js');
|
|
|
|
|
|
Page({
|
|
|
|
|
@@ -10,7 +12,7 @@ Page({
|
|
|
navBarHeight: app.globalData.navBarHeight,
|
|
|
MenuButtonheight: app.globalData.MenuButtonheight,
|
|
|
MenuButtonTop: app.globalData.MenuButtonTop,
|
|
|
- rightId:wx.getStorageSync('rightId') || 0,
|
|
|
+ rightId: wx.getStorageSync('rightId') || 0,
|
|
|
nvabarData: {
|
|
|
nvabarData: {
|
|
|
showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
|
|
@@ -22,11 +24,12 @@ Page({
|
|
|
}
|
|
|
},
|
|
|
isNotruter: false,
|
|
|
- deviceList: [],
|
|
|
- bannerList: [],
|
|
|
- showLogin: false,
|
|
|
- selectIndex: -1,
|
|
|
- }
|
|
|
+
|
|
|
+ },
|
|
|
+ deviceList: [],
|
|
|
+ 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"],
|
|
|
+ selectIndex: 0,
|
|
|
+ isLoginWx: true,
|
|
|
},
|
|
|
changeRole() {
|
|
|
app.changeUserRight()
|
|
@@ -48,6 +51,7 @@ Page({
|
|
|
changeDeviceTap: function () {
|
|
|
},
|
|
|
login() {
|
|
|
+ var _this = this;
|
|
|
wx.login({
|
|
|
success: res => {
|
|
|
let phone = undefined;
|
|
@@ -60,7 +64,7 @@ Page({
|
|
|
// Do something when catch error
|
|
|
};
|
|
|
// 请求登录
|
|
|
- login({code: res.code, phone}).then((res)=> {
|
|
|
+ login({ code: res.code, phone }).then((res) => {
|
|
|
|
|
|
app.globalData.userInfo = res;
|
|
|
wx.setStorage({
|
|
@@ -68,9 +72,9 @@ Page({
|
|
|
data: res
|
|
|
});
|
|
|
// 需要用授权登录
|
|
|
- if((res.isNewUser && res.isNewUser === true) || !phone) {
|
|
|
+ if ((res.isNewUser && res.isNewUser === true) || !phone) {
|
|
|
_this.setData({
|
|
|
- showLogin: true,
|
|
|
+ isLoginWx: true,
|
|
|
});
|
|
|
return;
|
|
|
};
|
|
@@ -78,10 +82,10 @@ Page({
|
|
|
this.getDeviceData();
|
|
|
|
|
|
_this.setData({
|
|
|
- showLogin: false,
|
|
|
+ isLoginWx: false,
|
|
|
});
|
|
|
wx.setStorage({
|
|
|
- key:"token",
|
|
|
+ key: "token",
|
|
|
data: JSON.stringify({
|
|
|
id: res.userId,
|
|
|
token: res.accessToken,
|
|
@@ -96,7 +100,8 @@ Page({
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad(options) {
|
|
|
- _this = this;
|
|
|
+ var _this = this;
|
|
|
+ eventOn(_this);
|
|
|
// 版本自动更新代码
|
|
|
const updateManager = wx.getUpdateManager();
|
|
|
updateManager.onUpdateReady(function () {
|
|
@@ -116,8 +121,8 @@ Page({
|
|
|
wx.showLoading({
|
|
|
title: '加载中',
|
|
|
});
|
|
|
- // 登录
|
|
|
- this.login();
|
|
|
+ // 登录
|
|
|
+ _this.login();
|
|
|
|
|
|
},
|
|
|
|
|
@@ -131,37 +136,39 @@ Page({
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
- onShow() {
|
|
|
- if (typeof this.getTabBar === 'function' &&
|
|
|
- this.getTabBar()) {
|
|
|
- this.getTabBar().setData({
|
|
|
- selected: 0
|
|
|
- })
|
|
|
+ onShow(options) {
|
|
|
+ selectIndex( 0);
|
|
|
+
|
|
|
+ // 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
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+
|
|
|
+ if (this.data.isLoginWx) {
|
|
|
+ var key = 'home_device_list' + wx.getUserInfo().userId;
|
|
|
+ var saveStr = wx.getStorageSync(key) ?? "[]";
|
|
|
+ var devList = JSON.parse(saveStr);
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ deviceList: devList
|
|
|
+ });
|
|
|
}
|
|
|
- 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',
|
|
|
});
|
|
|
- },
|
|
|
+ },
|
|
|
/**
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
*/
|