|
@@ -27,6 +27,12 @@ Page({
|
|
|
|
|
|
onLoad(options) {
|
|
|
var that = this;
|
|
|
+ let json = JSON.parse(options.param)
|
|
|
+ console.log("要连接设备:", json)
|
|
|
+ that.setData({
|
|
|
+ connectDevice: json
|
|
|
+ });
|
|
|
+
|
|
|
var b = BtHelper.getInstance();
|
|
|
that.data.btHelper = b;
|
|
|
b.initBluetooth(function (adapterState, hasPermission) {
|
|
@@ -39,9 +45,6 @@ Page({
|
|
|
// console.log('MAC: ' + res.macaddress);
|
|
|
// }
|
|
|
// });
|
|
|
-
|
|
|
- ///搜索中
|
|
|
- that.setStatus(0);
|
|
|
that.startSearch();
|
|
|
} else {
|
|
|
///搜索失败
|
|
@@ -50,11 +53,16 @@ Page({
|
|
|
})
|
|
|
|
|
|
that.findAllDevice()
|
|
|
+ },
|
|
|
|
|
|
- let json = JSON.parse(options.param)
|
|
|
- console.log("要连接设备:", json)
|
|
|
- that.setData({
|
|
|
- connectDevice: json
|
|
|
+ async startSearch() {
|
|
|
+ var that = this;
|
|
|
+ that.setStatus(0)
|
|
|
+ that.data.btHelper.search(async function () {
|
|
|
+ const connectedDevices = await that.getConnectedDevices()
|
|
|
+ if (connectedDevices.length == 0) {
|
|
|
+ that.setStatus(1)
|
|
|
+ }
|
|
|
})
|
|
|
},
|
|
|
|
|
@@ -83,7 +91,6 @@ Page({
|
|
|
subTips = "请检查设备是否被其他手机连接,或在手机蓝牙忽略掉原来的蓝牙连接重新连接。"
|
|
|
buttonTips = "重新搜索"
|
|
|
deviceImg = deviceLinkResp.icon1
|
|
|
-
|
|
|
break;
|
|
|
case 2:
|
|
|
// 搜索到
|
|
@@ -91,7 +98,6 @@ Page({
|
|
|
subTips = ""
|
|
|
buttonTips = "连接"
|
|
|
deviceImg = deviceLinkResp.icon2
|
|
|
-
|
|
|
break;
|
|
|
case 3:
|
|
|
// 连接成功
|
|
@@ -177,17 +183,6 @@ Page({
|
|
|
return connectedDevices;
|
|
|
},
|
|
|
|
|
|
- async startSearch() {
|
|
|
- var that = this;
|
|
|
- that.setStatus(0)
|
|
|
- that.data.btHelper.search(async function () {
|
|
|
- const connectedDevices = await that.getConnectedDevices()
|
|
|
- if (connectedDevices.length == 0) {
|
|
|
- that.setStatus(1)
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
-
|
|
|
findAllDevice() {
|
|
|
var that = this;
|
|
|
that.data.btHelper.findDevices(function (devices) {
|