|
@@ -42,7 +42,7 @@
|
|
|
<div class="connecting_toy">
|
|
|
<toy_connecting
|
|
|
:connect_toy="connect_toy"
|
|
|
- :deviceId="_deviceId"
|
|
|
+ :deviceId="device.deviceId"
|
|
|
:toy_id="toy_action"
|
|
|
:toy="toy_item"
|
|
|
:device_bg="device_bg"
|
|
@@ -117,6 +117,10 @@
|
|
|
<van-toast id="van-toast"/>
|
|
|
<van-dialog id="van-dialog"/>
|
|
|
|
|
|
+ <view style="width: 100%;height: 300px;">
|
|
|
+ <view>脑环Mac:{{ device.deviceId }}</view>
|
|
|
+ <view>教具UUID:{{ toy_UUID }}</view>
|
|
|
+ </view>
|
|
|
<!-- <van-popup-->
|
|
|
<!-- :show="start_show"-->
|
|
|
<!-- :closeable="false"-->
|
|
@@ -181,7 +185,7 @@ export default {
|
|
|
connect_toy: 0,
|
|
|
code: "jellyfish1234",
|
|
|
device: {},
|
|
|
- _deviceId: "",
|
|
|
+ deviceId: "",
|
|
|
_device_index: false,
|
|
|
toy_id: 0,
|
|
|
toy_hex: "",
|
|
@@ -202,7 +206,7 @@ export default {
|
|
|
//当前发送的hex码
|
|
|
current_hex: "",
|
|
|
//判断是否已经连接教具
|
|
|
- toy_connected:false
|
|
|
+ toy_connected: false
|
|
|
};
|
|
|
},
|
|
|
methods: {
|
|
@@ -215,7 +219,6 @@ export default {
|
|
|
},
|
|
|
//扫描连接蓝牙
|
|
|
scan_to_bluetooth() {
|
|
|
- // console.log("在扫码时是否存在deviceId?:", this._deviceId);
|
|
|
wx.scanCode({
|
|
|
onlyFromCamera: true,
|
|
|
success: (res) => {
|
|
@@ -356,14 +359,21 @@ export default {
|
|
|
game_store.setters.clearDeviceToy();
|
|
|
$this.connect_toy = $status;
|
|
|
$this.connect_show = false;
|
|
|
- $this._deviceId = "";
|
|
|
wx.closeBLEConnection({
|
|
|
- deviceId: $this._deviceId,
|
|
|
+ deviceId: $this.device.deviceId,
|
|
|
success(res) {
|
|
|
Toast.success({
|
|
|
message: "已成功断开",
|
|
|
});
|
|
|
},
|
|
|
+ fail(res) {
|
|
|
+ console.log("断开连接error:" + res)
|
|
|
+ },
|
|
|
+ complete(res) {
|
|
|
+ $this.device = {}
|
|
|
+ $this.toy_UUID = "";
|
|
|
+ $this.$forceUpdate();
|
|
|
+ }
|
|
|
});
|
|
|
wx.closeBluetoothAdapter();
|
|
|
} else if ($status == 2) {
|
|
@@ -388,12 +398,10 @@ export default {
|
|
|
// 判断ios 和 安卓
|
|
|
if (res.platform == "ios") {
|
|
|
$this.device.deviceId = $data.ios_device_id;
|
|
|
- $this._deviceId = $data.ios_device_id;
|
|
|
} else {
|
|
|
$this.device.deviceId = $data.device_id;
|
|
|
- $this._deviceId = $data.device_id;
|
|
|
}
|
|
|
- if ($this._deviceId) {
|
|
|
+ if ($this.device.deviceId) {
|
|
|
console.log("finded")
|
|
|
$this.createBLEConnection()
|
|
|
} else {
|
|
@@ -415,16 +423,10 @@ export default {
|
|
|
},
|
|
|
//打开蓝牙搜索
|
|
|
onBluetoothDeviceFound() {
|
|
|
- // console.log(
|
|
|
- // "打开蓝牙搜索 device_status",
|
|
|
- // $this.device_status,
|
|
|
- // "是否有id _deviceId",
|
|
|
- // $this._deviceId
|
|
|
- // );
|
|
|
try {
|
|
|
// 5秒后判断 这5秒在搜索设备,搜索到就赋值给_deviceId
|
|
|
setTimeout(() => {
|
|
|
- if (!$this._deviceId) {
|
|
|
+ if (!$this.device.deviceId) {
|
|
|
wx.stopBluetoothDevicesDiscovery();
|
|
|
$this.change_device_status(0);
|
|
|
Toast.fail("未连接到设备");
|
|
@@ -451,10 +453,9 @@ export default {
|
|
|
$this.stopBluetoothDevicesDiscovery();
|
|
|
$this.device = device;
|
|
|
game_store.setters.setDeviceId(device.deviceId);
|
|
|
- $this._deviceId = device.deviceId;
|
|
|
$this.createBLEConnection();
|
|
|
//录入库
|
|
|
- setDeviceInDb($this.code,device.deviceId)
|
|
|
+ setDeviceInDb($this.code, device.deviceId)
|
|
|
|
|
|
}
|
|
|
});
|
|
@@ -536,6 +537,8 @@ export default {
|
|
|
// //断开蓝牙连接
|
|
|
// $this.change_device_status(0);
|
|
|
// }
|
|
|
+ $this.toy_UUID = "";
|
|
|
+ $this.$forceUpdate();
|
|
|
// 状态为1的时候重置为1 小乌龟
|
|
|
if ($game_close_status == 1) {
|
|
|
// 重置默认条件
|
|
@@ -543,8 +546,9 @@ export default {
|
|
|
$this.connect_show = false;
|
|
|
$this.device_status = 0;
|
|
|
bluetooth.watch_bluetooth_status($this);
|
|
|
- $this._deviceId = "";
|
|
|
-
|
|
|
+ $this.device.deviceId = "";
|
|
|
+ $this.toy_UUID = "";
|
|
|
+ $this.$forceUpdate();
|
|
|
// 清空链接的设备
|
|
|
game_store.setters.clearDeviceToy();
|
|
|
|