|
@@ -26,7 +26,7 @@
|
|
|
<!-- 已链接 -->
|
|
|
<div class="connected_box" v-if="connect_show">
|
|
|
<device_connected @open_choose_toy="open_choose_toy"
|
|
|
- @change_toy_connect_status="change_toy_connect_status"></device_connected>
|
|
|
+ @change_brain_status="change_device_status"></device_connected>
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
@@ -35,7 +35,9 @@
|
|
|
<!-- 玩具连接中-->
|
|
|
<div class="connecting_toy">
|
|
|
<toy_connecting :connect_toy="connect_toy" @open_choose_toy="open_choose_toy"
|
|
|
- @change_toy_connect_status="change_toy_connect_status"></toy_connecting>
|
|
|
+ @change_toy_connect_status="change_toy_connect_status"
|
|
|
+ @change_status="change_device_status"
|
|
|
+ ></toy_connecting>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
@@ -69,7 +71,8 @@
|
|
|
<view class="text-gray toy_action_text padding">选择你最感兴趣的项目,点击“选好了”以后将会自动连接</view>
|
|
|
<button class="cu-btn lg cu-btn-primary text-white text-center padding" @click="choose_ok">选好了</button>
|
|
|
</div>
|
|
|
- </van-popup> <van-toast id="van-toast"/>
|
|
|
+ </van-popup>
|
|
|
+ <van-toast id="van-toast"/>
|
|
|
|
|
|
</div>
|
|
|
</template>
|
|
@@ -88,7 +91,6 @@ import {userDetail} from "../../requests/user";
|
|
|
import Toast from '../../../static/vant/toast/toast';
|
|
|
|
|
|
|
|
|
-
|
|
|
let $this;
|
|
|
export default {
|
|
|
name: "device",
|
|
@@ -102,35 +104,61 @@ export default {
|
|
|
choose_toy_window: {
|
|
|
show: false
|
|
|
},
|
|
|
+ //'水柱音箱', '喷雾恐龙(大)', '喷雾恐龙(小)', '轨道车', '碰碰车', '小车(大)', '小车(中)', '小车(小)', '飞行器(大)', '飞行器(小)', '水母灯'
|
|
|
toy_list: [
|
|
|
{
|
|
|
id: 1,
|
|
|
- name: "智能喷泉",
|
|
|
+ name: "水柱音箱",
|
|
|
img: "https://img.shuimuai.com/web/toy_car.png"
|
|
|
},
|
|
|
{
|
|
|
id: 2,
|
|
|
- name: "智能喷雾恐龙",
|
|
|
+ name: "喷雾恐龙(大)",
|
|
|
img: "https://img.shuimuai.com/web/toy_dinasour.png"
|
|
|
},
|
|
|
{
|
|
|
id: 3,
|
|
|
- name: "智能喷雾恐龙2",
|
|
|
+ name: "喷雾恐龙(小)",
|
|
|
img: "https://img.shuimuai.com/web/toy_dinasour.png"
|
|
|
},
|
|
|
{
|
|
|
id: 4,
|
|
|
- name: "智能轨道车",
|
|
|
+ name: "轨道车",
|
|
|
img: "https://img.shuimuai.com/web/toy_car_roat.png"
|
|
|
},
|
|
|
{
|
|
|
id: 5,
|
|
|
- name: "智能越野车",
|
|
|
+ name: "碰碰车",
|
|
|
img: "https://img.shuimuai.com/web/toy_car.png"
|
|
|
},
|
|
|
{
|
|
|
id: 6,
|
|
|
- name: "智能越野车2",
|
|
|
+ name: "小车(大)",
|
|
|
+ img: "https://img.shuimuai.com/web/toy_car.png"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 7,
|
|
|
+ name: "小车(中)",
|
|
|
+ img: "https://img.shuimuai.com/web/toy_car.png"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 8,
|
|
|
+ name: "小车(小)",
|
|
|
+ img: "https://img.shuimuai.com/web/toy_car.png"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 9,
|
|
|
+ name: "飞行器(大)",
|
|
|
+ img: "https://img.shuimuai.com/web/toy_car.png"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 10,
|
|
|
+ name: "飞行器(小)",
|
|
|
+ img: "https://img.shuimuai.com/web/toy_car.png"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 11,
|
|
|
+ name: "水母灯",
|
|
|
img: "https://img.shuimuai.com/web/toy_car.png"
|
|
|
},
|
|
|
],
|
|
@@ -139,7 +167,13 @@ export default {
|
|
|
//连接玩具 0:未连接 1:连接中 2:已连接 3:连接失败 4:游戏中
|
|
|
connect_toy: 0,
|
|
|
code: "jellyfish1234",
|
|
|
- device: {}
|
|
|
+ device: {},
|
|
|
+ canWrite: false,
|
|
|
+ _deviceId: '',
|
|
|
+ _serviceId: "",
|
|
|
+ _characteristicId: "",
|
|
|
+ chs: [],
|
|
|
+ _device_index: false
|
|
|
}
|
|
|
},
|
|
|
watch: {
|
|
@@ -147,13 +181,8 @@ export default {
|
|
|
//成功连接的方法
|
|
|
if ($new == 2) {
|
|
|
$this.connect_show = true
|
|
|
- }
|
|
|
- },
|
|
|
- connect_toy($new, $old) {
|
|
|
- if ($new == 1) {
|
|
|
- setTimeout(() => {
|
|
|
- $this.connect_toy = 2
|
|
|
- }, 2000)
|
|
|
+ } else if ($new == 0) {
|
|
|
+ $this.connect_show = false
|
|
|
}
|
|
|
}
|
|
|
},
|
|
@@ -209,6 +238,8 @@ export default {
|
|
|
choose_ok() {
|
|
|
$this.on_close()
|
|
|
$this.change_toy_connect_status(1)
|
|
|
+ $this._device_index = $this.toy_action - 1
|
|
|
+ $this.connect_toy = 2
|
|
|
},
|
|
|
//修改玩具连接状态
|
|
|
change_toy_connect_status($status = 0) {
|
|
@@ -216,8 +247,18 @@ export default {
|
|
|
},
|
|
|
// 修改设备连接状态
|
|
|
change_device_status($status = 0) {
|
|
|
- console.log($status)
|
|
|
$this.status = $status
|
|
|
+ //当蓝牙连接已断开
|
|
|
+ if ($status == 0) {
|
|
|
+ $this.connect_toy = $status
|
|
|
+ $this.connect_show = false
|
|
|
+ wx.closeBLEConnection({
|
|
|
+ deviceId: $this._deviceId,
|
|
|
+ success(res) {
|
|
|
+ Toast.success('已成功断开')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
//开始蓝牙被发现
|
|
@@ -228,7 +269,6 @@ export default {
|
|
|
console.log('startBluetoothDevicesDiscovery success', res)
|
|
|
$this.onBluetoothDeviceFound()
|
|
|
$this.change_device_status(1)
|
|
|
-
|
|
|
},
|
|
|
fail(err) {
|
|
|
$this.change_device_status(3)
|
|
@@ -252,9 +292,12 @@ export default {
|
|
|
})
|
|
|
})
|
|
|
setTimeout(() => {
|
|
|
- $this.stopBluetoothDevicesDiscovery()
|
|
|
- $this.status = 0
|
|
|
- Toast.fail('未连接到设备')
|
|
|
+ if (!$this.device.deviceId) {
|
|
|
+ $this.stopBluetoothDevicesDiscovery()
|
|
|
+ $this.status = 0
|
|
|
+ $this.connect_show = false
|
|
|
+ Toast.fail('未连接到设备')
|
|
|
+ }
|
|
|
}, 7000)
|
|
|
|
|
|
},
|
|
@@ -270,15 +313,403 @@ export default {
|
|
|
console.log('成功连接')
|
|
|
//成功连接脑环蓝牙
|
|
|
$this.change_device_status(2)
|
|
|
+ $this.getBLEDeviceServices($this.device.deviceId)
|
|
|
},
|
|
|
fail(err) {
|
|
|
console.log('err', err)
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ //获取蓝牙设备服务
|
|
|
+ getBLEDeviceServices(deviceId) {
|
|
|
+ wx.getBLEDeviceServices({
|
|
|
+ deviceId,
|
|
|
+ success: (res) => {
|
|
|
+ for (let i = 0; i < res.services.length; i++) {
|
|
|
+ if (res.services[i].isPrimary) {
|
|
|
+ this.getBLEDeviceCharacteristics(deviceId, res.services[i].uuid)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ //获取蓝牙设备某个服务中所有特征值
|
|
|
+ getBLEDeviceCharacteristics(deviceId, serviceId) {
|
|
|
+ wx.getBLEDeviceCharacteristics({
|
|
|
+ deviceId,
|
|
|
+ serviceId,
|
|
|
+ success: (res) => {
|
|
|
+ console.log('getBLEDeviceCharacteristics success', res.characteristics)
|
|
|
+ for (let i = 0; i < res.characteristics.length; i++) {
|
|
|
+ let item = res.characteristics[i]
|
|
|
+ if (item.properties.read) {
|
|
|
+ wx.readBLECharacteristicValue({
|
|
|
+ deviceId,
|
|
|
+ serviceId,
|
|
|
+ characteristicId: item.uuid,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (item.properties.write) {
|
|
|
+ $this.canWrite = true
|
|
|
+ $this._deviceId = deviceId
|
|
|
+ $this._serviceId = serviceId
|
|
|
+ $this._characteristicId = item.uuid
|
|
|
+ $this.sendPause()
|
|
|
+ }
|
|
|
+ if (item.properties.notify || item.properties.indicate) {
|
|
|
+ wx.notifyBLECharacteristicValueChange({
|
|
|
+ deviceId,
|
|
|
+ serviceId,
|
|
|
+ characteristicId: item.uuid,
|
|
|
+ state: true,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ console.error('getBLEDeviceCharacteristics', res)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // 操作之前先监听,保证第一时间获取数据
|
|
|
+ wx.onBLECharacteristicValueChange((characteristic) => {
|
|
|
+ console.log("收到" + $this.ab2hex(characteristic.value));
|
|
|
+ let hexStr = $this.ab2hex(characteristic.value)
|
|
|
+
|
|
|
+ if (hexStr.substring(0, 10) == 'aadd0a0000') {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showToast({
|
|
|
+ title: '未找到教具',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 1500
|
|
|
+ })
|
|
|
+ console.log("无连接设备")
|
|
|
+ }
|
|
|
+ if (hexStr.substring(0, 10) == 'aadd0a0001') {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showToast({
|
|
|
+ title: '已连接到水柱音箱',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1500
|
|
|
+ })
|
|
|
+ $this.sendControl()
|
|
|
+ $this.connect_toy = 2
|
|
|
+ console.log("水柱音箱")
|
|
|
+ }
|
|
|
+ if (hexStr.substring(0, 10) == 'aadd0a0002') {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showToast({
|
|
|
+ title: '已连接到喷雾恐龙(大)',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1500
|
|
|
+ })
|
|
|
+ $this.sendControl()
|
|
|
+ $this.connect_toy = 2
|
|
|
+
|
|
|
+ console.log("喷雾恐龙(大)")
|
|
|
+ }
|
|
|
+ if (hexStr.substring(0, 10) == 'aadd0a0003') {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showToast({
|
|
|
+ title: '已连接到喷雾恐龙(小)',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1500
|
|
|
+ })
|
|
|
+ $this.sendControl()
|
|
|
+ $this.connect_toy = 2
|
|
|
+
|
|
|
+ console.log("喷雾恐龙(小)")
|
|
|
+ }
|
|
|
+ if (hexStr.substring(0, 10) == 'aadd0a0004') {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showToast({
|
|
|
+ title: '已连接到轨道车',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1500
|
|
|
+ })
|
|
|
+ $this.sendControl()
|
|
|
+ $this.connect_toy = 2
|
|
|
+
|
|
|
+ console.log("轨道车")
|
|
|
+ }
|
|
|
+ if (hexStr.substring(0, 10) == 'aadd0a0005') {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showToast({
|
|
|
+ title: '已连接到碰碰车',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1500
|
|
|
+ })
|
|
|
+ $this.sendControl()
|
|
|
+ $this.connect_toy = 2
|
|
|
+
|
|
|
+ console.log("碰碰车")
|
|
|
+ }
|
|
|
+ if (hexStr.substring(0, 10) == 'aadd0a0006') {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showToast({
|
|
|
+ title: '已连接到小车(大)',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1500
|
|
|
+ })
|
|
|
+ $this.sendControl()
|
|
|
+ $this.connect_toy = 2
|
|
|
+
|
|
|
+ console.log("小车(大)")
|
|
|
+ }
|
|
|
+ if (hexStr.substring(0, 10) == 'aadd0a0007') {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showToast({
|
|
|
+ title: '已连接到小车(中)',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1500
|
|
|
+ })
|
|
|
+ $this.sendControl()
|
|
|
+ $this.connect_toy = 2
|
|
|
+
|
|
|
+ console.log("小车(中)")
|
|
|
+ }
|
|
|
+ if (hexStr.substring(0, 10) == 'aadd0a0008') {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showToast({
|
|
|
+ title: '已连接到小车(小)',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1500
|
|
|
+ })
|
|
|
+ $this.sendControl()
|
|
|
+ $this.connect_toy = 2
|
|
|
+
|
|
|
+ console.log("小车(小)")
|
|
|
+ }
|
|
|
+ if (hexStr.substring(0, 10) == 'aadd0a0009') {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showToast({
|
|
|
+ title: '已连接到飞行器(大)',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1500
|
|
|
+ })
|
|
|
+ $this.sendControl()
|
|
|
+ $this.connect_toy = 2
|
|
|
+
|
|
|
+ console.log("飞行器(大)")
|
|
|
+ }
|
|
|
+ if (hexStr.substring(0, 10) == 'aadd0a000a') {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showToast({
|
|
|
+ title: '已连接到飞行器(小)',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1500
|
|
|
+ })
|
|
|
+ $this.sendControl()
|
|
|
+ $this.connect_toy = 2
|
|
|
+
|
|
|
+ console.log("飞行器(小)")
|
|
|
+ }
|
|
|
+ if (hexStr.substring(0, 10) == 'aadd0a000b') {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showToast({
|
|
|
+ title: '已连接到水母灯)',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1500
|
|
|
+ })
|
|
|
+ $this.sendControl()
|
|
|
+ $this.connect_toy = 2
|
|
|
+
|
|
|
+ console.log("水母灯")
|
|
|
+ }
|
|
|
+ if (hexStr.substring(0, 10) == 'aadd070000') {
|
|
|
+ $this.sendOpen()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ //面向蓝牙设备成员发送数据包
|
|
|
+ writeBLECharacteristicValue() {
|
|
|
+ // 向蓝牙设备发送一个0x00的16进制数据
|
|
|
+ let buffer = new ArrayBuffer(1)
|
|
|
+ let dataView = new DataView(buffer)
|
|
|
+ dataView.setUint8(0, Math.random() * 255 | 0)
|
|
|
+ wx.writeBLECharacteristicValue({
|
|
|
+ deviceId: this._deviceId,
|
|
|
+ serviceId: this._deviceId,
|
|
|
+ characteristicId: this._characteristicId,
|
|
|
+ value: buffer,
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 发送停止发送脑电数据包指令
|
|
|
+ sendPause() {
|
|
|
+ let that = this
|
|
|
+ // 向蓝牙设备发送一个0x00的16进制数据
|
|
|
+ let buffer = new ArrayBuffer(8)
|
|
|
+ let dataView = new DataView(buffer)
|
|
|
+ dataView.setUint8(0, '0xaa')
|
|
|
+ dataView.setUint8(1, '0xcc')
|
|
|
+ dataView.setUint8(2, '0x03')
|
|
|
+ dataView.setUint8(3, '0x00')
|
|
|
+ dataView.setUint8(4, '0x00')
|
|
|
+ dataView.setUint8(5, '0x00')
|
|
|
+ dataView.setUint8(6, '0x00')
|
|
|
+ dataView.setUint8(7, '0xfc')
|
|
|
+ // 向低功耗蓝牙设备特征值中写入二进制数据
|
|
|
+ console.log(buffer)
|
|
|
+ wx.writeBLECharacteristicValue({
|
|
|
+ deviceId: that._deviceId,
|
|
|
+ serviceId: that._serviceId,
|
|
|
+ characteristicId: that._characteristicId,
|
|
|
+ value: buffer,
|
|
|
+ success: function (res) {
|
|
|
+ console.log('停止数据发送成功')
|
|
|
+ console.log(res)
|
|
|
+ },
|
|
|
+ fail: function (err) {
|
|
|
+ console.log('停止数据发送失败')
|
|
|
+ console.log(err)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 发送开启脑电数据包指令
|
|
|
+ sendOpen() {
|
|
|
+ const that = this
|
|
|
+ // 向蓝牙设备发送一个0x00的16进制数据
|
|
|
+ let buffer = new ArrayBuffer(8)
|
|
|
+ let dataView = new DataView(buffer)
|
|
|
+ dataView.setUint8(0, '0xaa')
|
|
|
+ dataView.setUint8(1, '0xcc')
|
|
|
+ dataView.setUint8(2, '0x03')
|
|
|
+ dataView.setUint8(3, '0x00')
|
|
|
+ dataView.setUint8(4, '0x00')
|
|
|
+ dataView.setUint8(5, '0x00')
|
|
|
+ dataView.setUint8(6, '0xff')
|
|
|
+ dataView.setUint8(7, '0xfd')
|
|
|
+ // 向低功耗蓝牙设备特征值中写入二进制数据
|
|
|
+ console.log(buffer)
|
|
|
+ wx.writeBLECharacteristicValue({
|
|
|
+ deviceId: that._deviceId,
|
|
|
+ serviceId: that._serviceId,
|
|
|
+ characteristicId: that._characteristicId,
|
|
|
+ value: buffer,
|
|
|
+ success: function (res) {
|
|
|
+ console.log('开启脑电数据包成功')
|
|
|
+ console.log(res)
|
|
|
+ },
|
|
|
+ fail: function (err) {
|
|
|
+ console.log('开启脑电数据包失败')
|
|
|
+ console.log(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 发送开启教具脑控指令
|
|
|
+ sendControl() {
|
|
|
+ const that = this
|
|
|
+ // 向蓝牙设备发送一个0x00的16进制数据
|
|
|
+ let buffer = new ArrayBuffer(8)
|
|
|
+ let dataView = new DataView(buffer)
|
|
|
+ dataView.setUint8(0, '0xaa')
|
|
|
+ dataView.setUint8(1, '0xcc')
|
|
|
+ dataView.setUint8(2, '0x03')
|
|
|
+ dataView.setUint8(3, '0x00')
|
|
|
+ dataView.setUint8(4, '0x00')
|
|
|
+ dataView.setUint8(5, '0x00')
|
|
|
+ dataView.setUint8(6, '0x07')
|
|
|
+ dataView.setUint8(7, '0xf5')
|
|
|
+ // 向低功耗蓝牙设备特征值中写入二进制数据
|
|
|
+ console.log(buffer)
|
|
|
+ wx.writeBLECharacteristicValue({
|
|
|
+ deviceId: that._deviceId,
|
|
|
+ serviceId: that._serviceId,
|
|
|
+ characteristicId: that._characteristicId,
|
|
|
+ value: buffer,
|
|
|
+ success: function (res) {
|
|
|
+ console.log('开启教具脑控成功')
|
|
|
+ // that.sendOpen()
|
|
|
+ console.log(res)
|
|
|
+ },
|
|
|
+ fail: function (err) {
|
|
|
+ console.log('开启教具脑控失败')
|
|
|
+ console.log(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 发送连接玩具指令
|
|
|
+ sendConnect(index) {
|
|
|
+ const that = this
|
|
|
+ // 玩具对应指令数组
|
|
|
+ console.log(index)
|
|
|
+ let arr = ['0x01', '0x02', '0x03', '0x04', '0x05', '0x06', '0x07', '0x08', '0x09', '0x0a', '0x0b']
|
|
|
+ let arr1 = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b]
|
|
|
+ let CheckSum = ((0x03 + 0x00 + arr1[index] + 0x00 + 0x0a) ^ 0xFFFFFFFF) & 0xFF
|
|
|
+ // 向蓝牙设备发送指令
|
|
|
+ let buffer = new ArrayBuffer(8)
|
|
|
+ let dataView = new DataView(buffer)
|
|
|
+ dataView.setUint8(0, '0xaa')
|
|
|
+ dataView.setUint8(1, '0xcc')
|
|
|
+ dataView.setUint8(2, '0x03')
|
|
|
+ dataView.setUint8(3, '0x00')
|
|
|
+ dataView.setUint8(4, arr[index])
|
|
|
+ dataView.setUint8(5, '0x00')
|
|
|
+ dataView.setUint8(6, '0x0a')
|
|
|
+ dataView.setUint8(7, '0xf1')
|
|
|
+ // 向低功耗蓝牙设备特征值中写入二进制数据
|
|
|
+ console.log(buffer)
|
|
|
+ wx.writeBLECharacteristicValue({
|
|
|
+ deviceId: that._deviceId,
|
|
|
+ serviceId: that._serviceId,
|
|
|
+ characteristicId: that._characteristicId,
|
|
|
+ value: buffer,
|
|
|
+ success: function (res) {
|
|
|
+ console.log('发送连接玩具指令成功')
|
|
|
+ wx.showLoading({
|
|
|
+ title: '正在创建连接',
|
|
|
+ })
|
|
|
+ console.log(res)
|
|
|
+ },
|
|
|
+ fail: function (err) {
|
|
|
+ console.log('发送连接玩具指令失败')
|
|
|
+ wx.showModal({
|
|
|
+ showCancel: false,
|
|
|
+ title: '提示',
|
|
|
+ content: '指令发送失败',
|
|
|
+ })
|
|
|
+ console.log(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ },
|
|
|
+ inArray(arr, key, val) {
|
|
|
+ for (let i = 0; i < arr.length; i++) {
|
|
|
+ if (arr[i][key] === val) {
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return -1;
|
|
|
+ },
|
|
|
+ // ArrayBuffer转16进度字符串示例
|
|
|
+ ab2hex(buffer) {
|
|
|
+ var hexArr = Array.prototype.map.call(
|
|
|
+ new Uint8Array(buffer),
|
|
|
+ function (bit) {
|
|
|
+ return ('00' + bit.toString(16)).slice(-2)
|
|
|
+ }
|
|
|
+ )
|
|
|
+ return hexArr.join('');
|
|
|
+ }
|
|
|
+
|
|
|
},
|
|
|
created() {
|
|
|
$this = this
|
|
|
+ },
|
|
|
+ onLoad(options) {
|
|
|
+ // 原有的code
|
|
|
+ let $_code = wx.getStorageSync('code')
|
|
|
+ if (options.q) {
|
|
|
+ let url = decodeURIComponent(options.q)
|
|
|
+ let $code = url.match(/\?code=(.*)/)[1];
|
|
|
+ //判断新的code 和 旧的code 是否一致 不一致则重新登录
|
|
|
+ console.log('1---' + $_code, '2---' + $code)
|
|
|
+ if ($_code && $_code != $code) {
|
|
|
+ Toast.fail('该用户已绑定邀请码')
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
</script>
|