|
@@ -40,6 +40,7 @@
|
|
|
:deviceId="_deviceId"
|
|
|
:toy_id="toy_action"
|
|
|
:toy="toy_list[toy_action - 1]"
|
|
|
+ :device_bg="device_bg"
|
|
|
@open_choose_toy="open_choose_toy"
|
|
|
@change_toy_connect_status="change_toy_connect_status"
|
|
|
@change_status="change_device_status"
|
|
@@ -134,6 +135,8 @@ export default {
|
|
|
//设备状态 0为未连接,1:连接中,2:已连接 3:连接失败
|
|
|
device_status: 0,
|
|
|
connect_show: false,
|
|
|
+ //设置图标的颜色
|
|
|
+ device_bg: true,
|
|
|
|
|
|
choose_toy_window: {
|
|
|
show: false,
|
|
@@ -199,7 +202,7 @@ export default {
|
|
|
},
|
|
|
});
|
|
|
}
|
|
|
- },
|
|
|
+ }
|
|
|
});
|
|
|
},
|
|
|
//关闭窗口的方法
|
|
@@ -265,13 +268,12 @@ export default {
|
|
|
wx.closeBLEConnection({
|
|
|
deviceId: $this._deviceId,
|
|
|
success(res) {
|
|
|
- wx.closeBluetoothAdapter()
|
|
|
-
|
|
|
Toast.success({
|
|
|
message: "已成功断开"
|
|
|
});
|
|
|
},
|
|
|
});
|
|
|
+ wx.closeBluetoothAdapter()
|
|
|
}
|
|
|
},
|
|
|
|
|
@@ -290,28 +292,33 @@ export default {
|
|
|
},
|
|
|
//打开蓝牙搜索
|
|
|
onBluetoothDeviceFound() {
|
|
|
- wx.onBluetoothDeviceFound((res) => {
|
|
|
- res.devices.forEach((device) => {
|
|
|
- if (!device.name && !device.localName) {
|
|
|
- $this.stopBluetoothDevicesDiscovery();
|
|
|
- $this.device_status = 0;
|
|
|
- $this.connect_show = false;
|
|
|
- Toast.fail("未连接到设备");
|
|
|
- return;
|
|
|
- }
|
|
|
- if (device.localName && (device.localName != '')) {
|
|
|
- device.name = device.localName
|
|
|
- }
|
|
|
- console.log(device["name"].toUpperCase());
|
|
|
- if (device["name"].toUpperCase() == $this.code) {
|
|
|
- $this.stopBluetoothDevicesDiscovery();
|
|
|
- $this.device = device;
|
|
|
- game_store.setters.setDeviceId(device.deviceId)
|
|
|
- $this._deviceId = device.deviceId;
|
|
|
- $this.createBLEConnection();
|
|
|
- }
|
|
|
+ console.log("打开蓝牙搜索")
|
|
|
+ try {
|
|
|
+
|
|
|
+ wx.onBluetoothDeviceFound((res) => {
|
|
|
+ console.log(res)
|
|
|
+ res.devices.forEach((device) => {
|
|
|
+ console.log(device)
|
|
|
+ if (!device.name && !device.localName) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (device.localName && (device.localName != '')) {
|
|
|
+ device.name = device.localName
|
|
|
+ }
|
|
|
+ console.log(device["name"].toUpperCase());
|
|
|
+ if (device["name"].toUpperCase() == $this.code) {
|
|
|
+ $this.stopBluetoothDevicesDiscovery();
|
|
|
+ $this.device = device;
|
|
|
+ game_store.setters.setDeviceId(device.deviceId)
|
|
|
+ $this._deviceId = device.deviceId;
|
|
|
+
|
|
|
+ $this.createBLEConnection();
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
- });
|
|
|
+ } catch (e) {
|
|
|
+ console.log('打开蓝牙error', e)
|
|
|
+ }
|
|
|
setTimeout(() => {
|
|
|
if (!$this.device.deviceId) {
|
|
|
$this.stopBluetoothDevicesDiscovery();
|
|
@@ -576,9 +583,9 @@ export default {
|
|
|
.device_bg {
|
|
|
width: 90px;
|
|
|
height: 100px;
|
|
|
- background-image: url("https://img.shuimuai.com/web/device_bg.png");
|
|
|
background-position: center;
|
|
|
background-size: 100% 100%;
|
|
|
+ background-image: url("https://img.shuimuai.com/web/device_bg.png");
|
|
|
}
|
|
|
|
|
|
.left {
|