|
@@ -73,79 +73,65 @@ Page({
|
|
onHomeShow() {
|
|
onHomeShow() {
|
|
var that = this;
|
|
var that = this;
|
|
if ((!that.data.isOneLoading)) {
|
|
if ((!that.data.isOneLoading)) {
|
|
- wx.getStorage({
|
|
|
|
- key: 'userInfo',
|
|
|
|
- fail(res) {
|
|
|
|
- // 取消订阅
|
|
|
|
- if (that.data.thisDeviceMac !== null) {
|
|
|
|
- app.unsubscribe(`/${that.data.thisDeviceMac}/user/pub_response`);
|
|
|
|
- };
|
|
|
|
- },
|
|
|
|
- success() {
|
|
|
|
- if (app.globalData.newDeviceId) {
|
|
|
|
- // 获取设备本地数据
|
|
|
|
- that.getDeviceData();
|
|
|
|
- } else if (that.data.deviceListIndex !== null) {
|
|
|
|
- // 更新
|
|
|
|
- that.actionDevice(that.data.deviceListIndex);
|
|
|
|
- }
|
|
|
|
|
|
+ var userInfo = wx.getStorageSync("userInfo") || "";
|
|
|
|
+ if (!strings.isEmpty(userInfo)) {
|
|
|
|
+ // 获取设备本地数据
|
|
|
|
+ if (app.globalData.newDeviceId) {
|
|
|
|
+ that.getDeviceData();
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
+ // 更新
|
|
|
|
+ else if (that.data.deviceListIndex !== null) {
|
|
|
|
+ that.actionDevice(that.data.deviceListIndex);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 取消订阅
|
|
|
|
+ else {
|
|
|
|
+ if (that.data.thisDeviceMac !== null) {
|
|
|
|
+ app.unsubscribe(`/${that.data.thisDeviceMac}/user/pub_response`);
|
|
|
|
+ };
|
|
|
|
+ }
|
|
};
|
|
};
|
|
},
|
|
},
|
|
|
|
|
|
- ////登录界面登录成功回调用
|
|
|
|
- loginSucceed() {
|
|
|
|
-
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
///开始时home的
|
|
///开始时home的
|
|
getDeviceData() {
|
|
getDeviceData() {
|
|
var that = this;
|
|
var that = this;
|
|
- // 获取设备数据
|
|
|
|
- wx.getStorage({
|
|
|
|
- key: 'devicelist',
|
|
|
|
- success(res) {
|
|
|
|
- // wx.hideLoading();
|
|
|
|
- if (res.data) {
|
|
|
|
- const resData = JSON.parse(res.data);
|
|
|
|
- console.log("gadsfadsfadsfa==333===" + JSON.stringify(resData));
|
|
|
|
- that.setData({
|
|
|
|
- deviceList: resData
|
|
|
|
- });
|
|
|
|
- // 连接mqtt
|
|
|
|
- if (app.globalData.client === null) {
|
|
|
|
- app.connect();
|
|
|
|
- } else if (app.globalData.newDeviceId) {
|
|
|
|
- that.setData({
|
|
|
|
- actionIndex: null,
|
|
|
|
- deviceListIndex: null,
|
|
|
|
- });
|
|
|
|
|
|
+ var devicelist = wx.getStorageSync("devicelist") || "";
|
|
|
|
+ if (!strings.isEmpty(devicelist)) {
|
|
|
|
+ const resData = JSON.parse(devicelist);
|
|
|
|
+ that.setData({
|
|
|
|
+ deviceList: resData
|
|
|
|
+ });
|
|
|
|
|
|
- // 监听
|
|
|
|
- let topic = `/AIrSMArT_${resData[0].name.split("BLUFI_")[1]}/status/onoffline`;
|
|
|
|
- app.subscribe(topic);
|
|
|
|
- const Timeout = setTimeout(() => {
|
|
|
|
- clearTimeout(Timeout);
|
|
|
|
- that.actionDevice(0);
|
|
|
|
- }, 1000);
|
|
|
|
- }
|
|
|
|
|
|
+ // 连接mqtt
|
|
|
|
+ if (app.globalData.client === null) {
|
|
|
|
+ app.connect();
|
|
|
|
+ } else if (app.globalData.newDeviceId) {
|
|
|
|
+ that.setData({
|
|
|
|
+ actionIndex: null,
|
|
|
|
+ deviceListIndex: null,
|
|
|
|
+ });
|
|
|
|
|
|
- // // 有新设备
|
|
|
|
- // if(app.globalData.newDeviceId) {
|
|
|
|
- // that.setData({
|
|
|
|
- // actionIndex: null,
|
|
|
|
- // deviceListIndex: null,
|
|
|
|
- // });
|
|
|
|
- // let topic = `/AIrSMArT_${resData[0].name.split("BLUFI_")[1]}/status/onoffline`;
|
|
|
|
- // app.subscribe(topic);
|
|
|
|
- // }
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- fail(e) {
|
|
|
|
- // wx.hideLoading();
|
|
|
|
|
|
+ // 监听
|
|
|
|
+ let topic = `/AIrSMArT_${resData[0].name.split("BLUFI_")[1]}/status/onoffline`;
|
|
|
|
+ app.subscribe(topic);
|
|
|
|
+ const Timeout = setTimeout(() => {
|
|
|
|
+ clearTimeout(Timeout);
|
|
|
|
+ that.actionDevice(0);
|
|
|
|
+ }, 1000);
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
+
|
|
|
|
+ // // 有新设备
|
|
|
|
+ // if(app.globalData.newDeviceId) {
|
|
|
|
+ // that.setData({
|
|
|
|
+ // actionIndex: null,
|
|
|
|
+ // deviceListIndex: null,
|
|
|
|
+ // });
|
|
|
|
+ // let topic = `/AIrSMArT_${resData[0].name.split("BLUFI_")[1]}/status/onoffline`;
|
|
|
|
+ // app.subscribe(topic);
|
|
|
|
+ // }
|
|
|
|
+ }
|
|
|
|
+
|
|
},
|
|
},
|
|
|
|
|
|
// 回调
|
|
// 回调
|