|
@@ -49,6 +49,7 @@ Page({
|
|
|
|
|
|
onLoad(options) {
|
|
onLoad(options) {
|
|
var that = this;
|
|
var that = this;
|
|
|
|
+ that.onDeviceLoad();
|
|
that.onUserInfoLoad();
|
|
that.onUserInfoLoad();
|
|
that.onBannerLoad();
|
|
that.onBannerLoad();
|
|
},
|
|
},
|
|
@@ -65,64 +66,65 @@ Page({
|
|
if (!strings.isEmpty(userInfo)) {
|
|
if (!strings.isEmpty(userInfo)) {
|
|
// 获取设备本地数据
|
|
// 获取设备本地数据
|
|
if (app.globalData.newDeviceId) {
|
|
if (app.globalData.newDeviceId) {
|
|
- that.getDeviceData();
|
|
|
|
|
|
+ that.addNewDeviceId();
|
|
}
|
|
}
|
|
// 更新
|
|
// 更新
|
|
else if (that.data.deviceListIndex !== null) {
|
|
else if (that.data.deviceListIndex !== null) {
|
|
that.actionDevice(that.data.deviceListIndex);
|
|
that.actionDevice(that.data.deviceListIndex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- // 取消订阅
|
|
|
|
- else {
|
|
|
|
- if (that.data.thisDeviceMac !== null) {
|
|
|
|
- app.unsubscribe(`/${that.data.thisDeviceMac}/user/pub_response`);
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
},
|
|
},
|
|
|
|
|
|
///开始时home的
|
|
///开始时home的
|
|
- getDeviceData() {
|
|
|
|
|
|
+ onDeviceLoad() {
|
|
var that = this;
|
|
var that = this;
|
|
var devicelist = wx.getStorageSync("devicelist") || "";
|
|
var devicelist = wx.getStorageSync("devicelist") || "";
|
|
if (!strings.isEmpty(devicelist)) {
|
|
if (!strings.isEmpty(devicelist)) {
|
|
- const resData = JSON.parse(devicelist);
|
|
|
|
- that.setData({
|
|
|
|
- deviceList: resData
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- // 连接mqtt
|
|
|
|
- if (app.globalData.client === null) {
|
|
|
|
- app.connect();
|
|
|
|
- } else if (app.globalData.newDeviceId) {
|
|
|
|
- that.setData({
|
|
|
|
- actionIndex: null,
|
|
|
|
- deviceListIndex: null,
|
|
|
|
- });
|
|
|
|
|
|
+ var list = JSON.parse(devicelist);
|
|
|
|
+ that.updateDeviceList(list, true);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
|
|
- // 监听
|
|
|
|
- let topic = `/AIrSMArT_${resData[0].name.split("BLUFI_")[1]}/status/onoffline`;
|
|
|
|
- app.subscribe(topic);
|
|
|
|
- const Timeout = setTimeout(() => {
|
|
|
|
- clearTimeout(Timeout);
|
|
|
|
- that.actionDevice(0);
|
|
|
|
- }, 1000);
|
|
|
|
|
|
+ addNewDeviceId() {
|
|
|
|
+ // 连接mqtt
|
|
|
|
+ var that = this;
|
|
|
|
+ if (app.globalData.client === null) {
|
|
|
|
+ app.connect();
|
|
|
|
+ } else if (app.globalData.newDeviceId) {
|
|
|
|
+ //监听
|
|
|
|
+ var deviceList = that.data.deviceList;
|
|
|
|
+ if (deviceList.length == 0) {
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
- // // 有新设备
|
|
|
|
- // if(app.globalData.newDeviceId) {
|
|
|
|
- // that.setData({
|
|
|
|
- // actionIndex: null,
|
|
|
|
- // deviceListIndex: null,
|
|
|
|
- // });
|
|
|
|
- // let topic = `/AIrSMArT_${resData[0].name.split("BLUFI_")[1]}/status/onoffline`;
|
|
|
|
- // app.subscribe(topic);
|
|
|
|
- // }
|
|
|
|
|
|
+ ///连接新添加的设备
|
|
|
|
+ var deviceListIndex = that.data.deviceListIndex;
|
|
|
|
+ if (deviceListIndex != null) {
|
|
|
|
+ if (deviceList.length > deviceListIndex) {
|
|
|
|
+ if (deviceList[deviceListIndex].deviceId != deviceList[0].deviceId) {
|
|
|
|
+ that.setData({
|
|
|
|
+ actionIndex: null,
|
|
|
|
+ deviceListIndex: null,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ that.setData({
|
|
|
|
+ actionIndex: null,
|
|
|
|
+ deviceListIndex: null,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ var topic = `/AIrSMArT_${deviceList[0].deviceId.split("BLUFI_")[1]}/status/onoffline`;
|
|
|
|
+ app.subscribe(topic);
|
|
|
|
+ const Timeout = setTimeout(() => {
|
|
|
|
+ clearTimeout(Timeout);
|
|
|
|
+ that.actionDevice(0);
|
|
|
|
+ }, 500);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
// 回调
|
|
// 回调
|
|
mqttCallback(type, option) {
|
|
mqttCallback(type, option) {
|
|
- // console.log("gadsfadsfqwerq===" + type + "===" + option);
|
|
|
|
var that = this;
|
|
var that = this;
|
|
let payloads = null;
|
|
let payloads = null;
|
|
if (option) {
|
|
if (option) {
|
|
@@ -130,18 +132,17 @@ Page({
|
|
};
|
|
};
|
|
|
|
|
|
switch (type) {
|
|
switch (type) {
|
|
|
|
+ ///连接成功订阅
|
|
case "connect":
|
|
case "connect":
|
|
- that.connectSuccess();
|
|
|
|
|
|
+ that.subscribeDevicesStatus();
|
|
break;
|
|
break;
|
|
case "message_onoffline":
|
|
case "message_onoffline":
|
|
that.online(payloads);
|
|
that.online(payloads);
|
|
break;
|
|
break;
|
|
-
|
|
|
|
case "message":
|
|
case "message":
|
|
// 接收设备播放信息
|
|
// 接收设备播放信息
|
|
if (payloads.type === "get_position" && payloads.other) {
|
|
if (payloads.type === "get_position" && payloads.other) {
|
|
let actionIndex = null;
|
|
let actionIndex = null;
|
|
-
|
|
|
|
that.data.channelData.map((v, index) => {
|
|
that.data.channelData.map((v, index) => {
|
|
if (v.channelNum === payloads.other.channel) {
|
|
if (v.channelNum === payloads.other.channel) {
|
|
actionIndex = index;
|
|
actionIndex = index;
|
|
@@ -183,8 +184,6 @@ Page({
|
|
// 更新信息
|
|
// 更新信息
|
|
///连上就调用2次
|
|
///连上就调用2次
|
|
that.data.deviceList.map((v, index) => {
|
|
that.data.deviceList.map((v, index) => {
|
|
- // console.log("gadsfadsfadsfa==444===" + payloads.SrcDeviceName);
|
|
|
|
- // console.log("gadsfadsfadsfa==555===" + JSON.stringify(payloads.other));
|
|
|
|
|
|
|
|
// [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online"}]
|
|
// [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online"}]
|
|
/// payloads.other
|
|
/// payloads.other
|
|
@@ -230,12 +229,6 @@ Page({
|
|
return _battery
|
|
return _battery
|
|
},
|
|
},
|
|
|
|
|
|
- connectSuccess() {
|
|
|
|
- // 订阅设备在线信息
|
|
|
|
- var that = this;
|
|
|
|
- that.subscribeDevicesStatus();
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
// [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
|
|
// [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
|
|
|
|
|
|
///连上就调用2次 处理离线在线问题 wifi设备 BLUFI_
|
|
///连上就调用2次 处理离线在线问题 wifi设备 BLUFI_
|
|
@@ -270,10 +263,7 @@ Page({
|
|
|
|
|
|
///数据有更新
|
|
///数据有更新
|
|
if (isUpdate) {
|
|
if (isUpdate) {
|
|
- var finalList = that.updateDeviceList(deviceList);
|
|
|
|
- that.setData({
|
|
|
|
- deviceList: finalList,
|
|
|
|
- });
|
|
|
|
|
|
+ that.updateDeviceList(deviceList, false);
|
|
}
|
|
}
|
|
|
|
|
|
///当前没有连接设备,则去连接第一个wifi设备
|
|
///当前没有连接设备,则去连接第一个wifi设备
|
|
@@ -300,10 +290,15 @@ Page({
|
|
// 订阅设备在线状态
|
|
// 订阅设备在线状态
|
|
subscribeDevicesStatus() {
|
|
subscribeDevicesStatus() {
|
|
var that = this;
|
|
var that = this;
|
|
- that.data.deviceList.forEach((value) => {
|
|
|
|
- let topic = `/AIrSMArT_${value.name.split("BLUFI_")[1]}/status/onoffline`;
|
|
|
|
- app.subscribe(topic);
|
|
|
|
- })
|
|
|
|
|
|
+ var deviceList = that.data.deviceList;
|
|
|
|
+ if (!strings.isEmpty(deviceList)) {
|
|
|
|
+ for (var i = 0; i < deviceList.length; i++) {
|
|
|
|
+ if (deviceList[i].connectType == 3) {
|
|
|
|
+ let topic = `/AIrSMArT_${deviceList[i].deviceId.split("BLUFI_")[1]}/status/onoffline`;
|
|
|
|
+ app.subscribe(topic);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
},
|
|
},
|
|
|
|
|
|
subscribeCurrDevice() {
|
|
subscribeCurrDevice() {
|
|
@@ -399,24 +394,6 @@ Page({
|
|
if (app.globalData.newDeviceId) {
|
|
if (app.globalData.newDeviceId) {
|
|
app.globalData.newDeviceId = null;
|
|
app.globalData.newDeviceId = null;
|
|
return;
|
|
return;
|
|
- // 去掉此功能,先留着吧
|
|
|
|
- // const other= {
|
|
|
|
- // "url": "",
|
|
|
|
- // "media_data": "",
|
|
|
|
- // "user_id": `${app.globalData.userInfo.deviceUid}`,
|
|
|
|
- // "timestamp": `${Math.round(new Date() / 1000)}`,
|
|
|
|
- // "channel_id": `${res[1].channelNum}`,
|
|
|
|
- // "order": "",
|
|
|
|
- // "resource_from": "",
|
|
|
|
- // "songAlbumID":"",
|
|
|
|
- // "version":3,
|
|
|
|
- // "is_debug": app.globalData.is_debug
|
|
|
|
- // };
|
|
|
|
- // app.PubMsg({
|
|
|
|
- // type: "play",
|
|
|
|
- // DstDeviceName: that.getThisDeviceID(),
|
|
|
|
- // other
|
|
|
|
- // });
|
|
|
|
}
|
|
}
|
|
})
|
|
})
|
|
},
|
|
},
|
|
@@ -524,27 +501,33 @@ Page({
|
|
///点击item
|
|
///点击item
|
|
// [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
|
|
// [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
|
|
onTapItem(e) {
|
|
onTapItem(e) {
|
|
|
|
+ if (!that.data.isLogin) {
|
|
|
|
+ wx.navigateTo({
|
|
|
|
+ url: './../login/login'
|
|
|
|
+ });
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
var that = this;
|
|
var that = this;
|
|
var item = e.currentTarget.dataset.item;
|
|
var item = e.currentTarget.dataset.item;
|
|
var connectType = item.connectType;
|
|
var connectType = item.connectType;
|
|
|
|
+ console.log("gadfadfqwwerq===00===" + connectType);
|
|
if (connectType == 3) {
|
|
if (connectType == 3) {
|
|
|
|
+ console.log("gadfadfqwwerq===11===" + connectType);
|
|
if (e.currentTarget.dataset.index === that.data.deviceListIndex) {
|
|
if (e.currentTarget.dataset.index === that.data.deviceListIndex) {
|
|
|
|
+ console.log("gadfadfqwwerq===22===" + connectType);
|
|
that.goWake();
|
|
that.goWake();
|
|
} else {
|
|
} else {
|
|
|
|
+ console.log("gadfadfqwwerq===33===" + connectType);
|
|
that.actionDevice(e.currentTarget.dataset.index)
|
|
that.actionDevice(e.currentTarget.dataset.index)
|
|
}
|
|
}
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- console.log(e)
|
|
|
|
|
|
|
|
///去蓝牙连接处理
|
|
///去蓝牙连接处理
|
|
- // if (e.currentTarget.dataset.index === that.data.deviceListIndex) {
|
|
|
|
- // that.goWake();
|
|
|
|
- // } else {
|
|
|
|
- // that.actionDevice(e.currentTarget.dataset.index)
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
- if (item.state !== "online") {
|
|
|
|
|
|
+ if (e.currentTarget.dataset.index === that.data.deviceListIndex) {
|
|
|
|
+ route_util.jumpParam('/pages/deviceDetail/detail', JSON.stringify(item))
|
|
|
|
+ } else {
|
|
that.addConnectBlueDevice({
|
|
that.addConnectBlueDevice({
|
|
deviceId: item.deviceId,
|
|
deviceId: item.deviceId,
|
|
name: item.devName,
|
|
name: item.devName,
|
|
@@ -552,8 +535,6 @@ Page({
|
|
clientType: item.ProdModel,
|
|
clientType: item.ProdModel,
|
|
mac: item.mac,
|
|
mac: item.mac,
|
|
});
|
|
});
|
|
- } else {
|
|
|
|
- route_util.jumpParam('/pages/deviceDetail/detail', JSON.stringify(item))
|
|
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
@@ -711,18 +692,16 @@ Page({
|
|
});
|
|
});
|
|
|
|
|
|
///在线排序前面,wifi设备排序前面
|
|
///在线排序前面,wifi设备排序前面
|
|
- var finalList = that.updateDeviceList(deviceList);
|
|
|
|
|
|
+ that.updateDeviceList(deviceList, false);
|
|
var indexPage = that.data.indexPage;
|
|
var indexPage = that.data.indexPage;
|
|
if (indexPage != 0) {
|
|
if (indexPage != 0) {
|
|
that.setData({
|
|
that.setData({
|
|
indexPage: 0,
|
|
indexPage: 0,
|
|
deviceListIndex: 0,
|
|
deviceListIndex: 0,
|
|
- deviceList: finalList,
|
|
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
that.setData({
|
|
that.setData({
|
|
deviceListIndex: 0,
|
|
deviceListIndex: 0,
|
|
- deviceList: finalList,
|
|
|
|
});
|
|
});
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -730,26 +709,25 @@ Page({
|
|
addConnectWifiDevice(deviceList) {
|
|
addConnectWifiDevice(deviceList) {
|
|
var that = this;
|
|
var that = this;
|
|
///在线排序前面,wifi设备排序前面
|
|
///在线排序前面,wifi设备排序前面
|
|
- var finalList = that.updateDeviceList(deviceList);
|
|
|
|
|
|
+ that.updateDeviceList(deviceList, false);
|
|
var indexPage = that.data.indexPage;
|
|
var indexPage = that.data.indexPage;
|
|
if (indexPage != 0) {
|
|
if (indexPage != 0) {
|
|
that.setData({
|
|
that.setData({
|
|
indexPage: 0,
|
|
indexPage: 0,
|
|
deviceListIndex: 0,
|
|
deviceListIndex: 0,
|
|
- deviceList: finalList,
|
|
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
that.setData({
|
|
that.setData({
|
|
deviceListIndex: 0,
|
|
deviceListIndex: 0,
|
|
- deviceList: finalList,
|
|
|
|
});
|
|
});
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
///更新列表排序
|
|
///更新列表排序
|
|
- updateDeviceList(deviceList) {
|
|
|
|
|
|
+ updateDeviceList(deviceList, isInit) {
|
|
if (deviceList.length == 0) return [];
|
|
if (deviceList.length == 0) return [];
|
|
|
|
|
|
|
|
+ var that = this;
|
|
var finalList = [];
|
|
var finalList = [];
|
|
finalList.push(deviceList[0]);
|
|
finalList.push(deviceList[0]);
|
|
|
|
|
|
@@ -758,11 +736,15 @@ Page({
|
|
|
|
|
|
///区分在线和离线
|
|
///区分在线和离线
|
|
for (var i = 0; i < deviceList.length; i++) {
|
|
for (var i = 0; i < deviceList.length; i++) {
|
|
- if (i > 0) {
|
|
|
|
- if (deviceList[i].state == "online") {
|
|
|
|
- onLineList.push(deviceList[i])
|
|
|
|
- } else {
|
|
|
|
- onNoLineList.push(deviceList[i])
|
|
|
|
|
|
+ if (isInit) {
|
|
|
|
+ deviceList[i].state = "offline";
|
|
|
|
+ } else {
|
|
|
|
+ if (i > 0) {
|
|
|
|
+ if (deviceList[i].state == "online") {
|
|
|
|
+ onLineList.push(deviceList[i])
|
|
|
|
+ } else {
|
|
|
|
+ onNoLineList.push(deviceList[i])
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -794,7 +776,10 @@ Page({
|
|
finalList = finalList.concat(onNoLineNoWifiList);
|
|
finalList = finalList.concat(onNoLineNoWifiList);
|
|
// 更新缓存
|
|
// 更新缓存
|
|
wx.setStorageSync("devicelist", JSON.stringify(finalList));
|
|
wx.setStorageSync("devicelist", JSON.stringify(finalList));
|
|
- return finalList;
|
|
|
|
|
|
+
|
|
|
|
+ that.setData({
|
|
|
|
+ deviceList: finalList
|
|
|
|
+ });
|
|
},
|
|
},
|
|
|
|
|
|
///******************************* 可折叠 ********************************************///
|
|
///******************************* 可折叠 ********************************************///
|
|
@@ -827,7 +812,6 @@ Page({
|
|
isLogin: true,
|
|
isLogin: true,
|
|
});
|
|
});
|
|
}
|
|
}
|
|
- that.getDeviceData();
|
|
|
|
} else {
|
|
} else {
|
|
var greeting = that.getGreetBuNickName("");
|
|
var greeting = that.getGreetBuNickName("");
|
|
that.setData({
|
|
that.setData({
|
|
@@ -863,4 +847,23 @@ Page({
|
|
wx.setStorageSync("homeBanner", res);
|
|
wx.setStorageSync("homeBanner", res);
|
|
})
|
|
})
|
|
},
|
|
},
|
|
-})
|
|
|
|
|
|
+})
|
|
|
|
+
|
|
|
|
+// 去掉此功能,先留着吧
|
|
|
|
+// const other= {
|
|
|
|
+// "url": "",
|
|
|
|
+// "media_data": "",
|
|
|
|
+// "user_id": `${app.globalData.userInfo.deviceUid}`,
|
|
|
|
+// "timestamp": `${Math.round(new Date() / 1000)}`,
|
|
|
|
+// "channel_id": `${res[1].channelNum}`,
|
|
|
|
+// "order": "",
|
|
|
|
+// "resource_from": "",
|
|
|
|
+// "songAlbumID":"",
|
|
|
|
+// "version":3,
|
|
|
|
+// "is_debug": app.globalData.is_debug
|
|
|
|
+// };
|
|
|
|
+// app.PubMsg({
|
|
|
|
+// type: "play",
|
|
|
|
+// DstDeviceName: that.getThisDeviceID(),
|
|
|
|
+// other
|
|
|
|
+// });
|