|
@@ -36,11 +36,11 @@ Page({
|
|
|
isLogin: false,
|
|
|
greeting: "",
|
|
|
bannerList: [{
|
|
|
- "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20241028142233669038262.png"
|
|
|
- },
|
|
|
- {
|
|
|
- "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20240823145816541223911.png"
|
|
|
- }
|
|
|
+ "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20241028142233669038262.png"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20240823145816541223911.png"
|
|
|
+ }
|
|
|
],
|
|
|
autoplay: true,
|
|
|
interval: 3000, // 切换时间间隔
|
|
@@ -74,6 +74,7 @@ Page({
|
|
|
deviceMacId: null,
|
|
|
deviceListSelect: null,
|
|
|
deviceList: [],
|
|
|
+ _willConnectBle: true,
|
|
|
// deviceList: [{
|
|
|
// "connectType": 3,
|
|
|
// "devName": "猫王小王子OTR-X",
|
|
@@ -224,18 +225,23 @@ Page({
|
|
|
let hasBle = that.data.deviceList.find(item => {
|
|
|
return item.connectType == 1;
|
|
|
})
|
|
|
- console.log("hasBle:", hasBle)
|
|
|
if (hasBle) {
|
|
|
///监听蓝牙设备
|
|
|
BtHelper.getInstance().initBluetoothAdapter();
|
|
|
BtHelper.getInstance().getBluetoothDevices();
|
|
|
- BtHelper.getInstance().startScan(null, null, null);
|
|
|
var isFirst = true;
|
|
|
+ console.log("开始监听蓝牙设备");
|
|
|
///再秒再对比一次
|
|
|
that.stopIntervalId1();
|
|
|
+ let count = 0;
|
|
|
that.data.intervalId1 = setInterval(async function () {
|
|
|
isFirst = false;
|
|
|
that.compareList();
|
|
|
+ if (count > 3) {
|
|
|
+ that.stopIntervalId1();
|
|
|
+ } else {
|
|
|
+ count++;
|
|
|
+ }
|
|
|
}, isFirst ? 6 * 1000 : 12 * 1000);
|
|
|
}
|
|
|
|
|
@@ -244,13 +250,53 @@ Page({
|
|
|
/// 对比蓝牙数据
|
|
|
compareList() {
|
|
|
var that = this;
|
|
|
+ if (that.data.deviceList.length == 1) {
|
|
|
+ let device = that.data.deviceList[0];
|
|
|
+ if (device.state === 'online') {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ getApp().getBluetoothStatus();
|
|
|
+ that.data._willConnectBle = true;
|
|
|
+ return;
|
|
|
+ }
|
|
|
lexin_scan.compareList(function (list) {
|
|
|
that.updateDeviceList(list, false, false);
|
|
|
}, function (item) {
|
|
|
that.addBlueDevice(item);
|
|
|
});
|
|
|
},
|
|
|
+ getBluetoothStatusCallck(v) {
|
|
|
+ var that = this;
|
|
|
+ if (!that.data._willConnectBle) {
|
|
|
+ // true 走下面
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (v) {
|
|
|
+ let device = that.data.deviceList[0];
|
|
|
+ console.log("开始连接设备0", device);
|
|
|
+ if (device.state === 'online' || device.connectType != 1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // });
|
|
|
+ BtHelper.getInstance().connect(device, function (isConnected, d) {
|
|
|
+ if (isConnected) {
|
|
|
+ d.connectType = 1;
|
|
|
+ d.state = 'online';
|
|
|
+ d.imageUrl = device.img;
|
|
|
+ that.addBlueDevice(d);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
+ } else {
|
|
|
+ // wx.showModal({
|
|
|
+ // title: '温馨提示',
|
|
|
+ // content: '请检查手机蓝牙是否打开',
|
|
|
+ // showCancel: false,
|
|
|
+ // success: function (res) { }
|
|
|
+ // });
|
|
|
+ }
|
|
|
+ that.data._willConnectBle = false;
|
|
|
+ },
|
|
|
// 回调
|
|
|
mqttCallback(type, option) {
|
|
|
// console.log("gadsfadsfadsfa==888===" + type);
|
|
@@ -265,7 +311,7 @@ Page({
|
|
|
case "connect":
|
|
|
lexin_subscribe.subscribeAllDevice();
|
|
|
break;
|
|
|
- ///再走有在线
|
|
|
+ ///再走有在线
|
|
|
case "message_onoffline":
|
|
|
lexin_connect.searchOnlineDevice(payloads, function (list) {
|
|
|
that.updateDeviceList(list, false, false);
|
|
@@ -460,10 +506,12 @@ Page({
|
|
|
|
|
|
var deviceList = that.getDeviceList();
|
|
|
var deviceListSelect = that.getDeviceListSelect();
|
|
|
- if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
|
|
|
+
|
|
|
+ if (deviceList.length > 1 && (deviceListSelect === null || deviceList.length <= deviceListSelect)) {
|
|
|
+ // 2个设备才判断,1个直接删除
|
|
|
return;
|
|
|
};
|
|
|
-
|
|
|
+ deviceListSelect = deviceListSelect ?? 0
|
|
|
///有设备在线被选中,则让它不被选择
|
|
|
if (deviceList[deviceListSelect].connectType == 3) {
|
|
|
var deviceMacId = that.data.deviceMacId;
|
|
@@ -478,6 +526,16 @@ Page({
|
|
|
indexPage: indexPage == 1 ? 0 : indexPage,
|
|
|
});
|
|
|
};
|
|
|
+ } else {
|
|
|
+ // console.log("退出登录,断开连接", deviceList);
|
|
|
+ // BtHelper.getInstance().disconnect(deviceList[deviceListSelect]);
|
|
|
+ // var indexPage = that.data.indexPage;
|
|
|
+ // that.setData({
|
|
|
+ // deviceMacId: null,
|
|
|
+ // actionIndex: null,
|
|
|
+ // deviceListSelect: null,
|
|
|
+ // indexPage: indexPage == 1 ? 0 : indexPage,
|
|
|
+ // });
|
|
|
}
|
|
|
},
|
|
|
|
|
@@ -509,15 +567,15 @@ Page({
|
|
|
if (index === deviceListSelect) {
|
|
|
route_util.jumpParam('/pages/deviceDetail/detail', JSON.stringify(device))
|
|
|
} else if (device.state === "offline") {
|
|
|
- console.log("去连接蓝牙")
|
|
|
- } else {
|
|
|
- // {"connectType":1,"deviceId":"E4:9F:80:09:40:EC","name":"E4:9F:80:09:40:EC","state":"online","ProdModel":"MW-SR1(4G_WIFI)","devName":"猫王音响x阿基米德 SR1 妙播收音机"}
|
|
|
+ console.log("去连接蓝牙", device)
|
|
|
device.name = device.devName;
|
|
|
BtHelper.getInstance().connect(device, function (isConnected, d) {
|
|
|
if (isConnected) {
|
|
|
that.addBlueDevice(d);
|
|
|
}
|
|
|
});
|
|
|
+ } else {
|
|
|
+ // {"connectType":1,"deviceId":"E4:9F:80:09:40:EC","name":"E4:9F:80:09:40:EC","state":"online","ProdModel":"MW-SR1(4G_WIFI)","devName":"猫王音响x阿基米德 SR1 妙播收音机"}
|
|
|
}
|
|
|
},
|
|
|
|
|
@@ -596,16 +654,17 @@ Page({
|
|
|
if (onlyCancel) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
var deviceList = that.getDeviceList();
|
|
|
var deviceListSelect = that.getDeviceListSelect();
|
|
|
- if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
|
|
|
+
|
|
|
+ if (deviceList.length > 1 && (deviceListSelect === null || deviceList.length <= deviceListSelect)) {
|
|
|
+ // 2个设备才判断,1个直接删除
|
|
|
return;
|
|
|
};
|
|
|
|
|
|
///是否删除的当前播放这个
|
|
|
var isCurrentIndex = false;
|
|
|
- var deviceListSelect = that.getDeviceListSelect();
|
|
|
+ deviceListSelect = deviceListSelect ?? 0;
|
|
|
if (deviceListSelect != null && deviceList.length > deviceListSelect) {
|
|
|
isCurrentIndex = (deviceListSelect == index);
|
|
|
};
|
|
@@ -615,6 +674,9 @@ Page({
|
|
|
deviceList = deviceList.filter((item, i) => {
|
|
|
return deviceId !== item.deviceId;
|
|
|
});
|
|
|
+ console.log("断开蓝牙连接", deviceId)
|
|
|
+
|
|
|
+ BtHelper.getInstance().disconnect({ "deviceId": deviceId });
|
|
|
|
|
|
store.setStore("deviceList", deviceList);
|
|
|
var indexPage = that.data.indexPage;
|