|
@@ -1,10 +1,7 @@
|
|
|
-// pages/deviceConnect0/deviceConnect0.ts
|
|
|
const app = getApp();
|
|
|
let xBlufi = require("../../utils/blufi/xBlufi.js");
|
|
|
Page({
|
|
|
- /**
|
|
|
- * 页面的初始数据
|
|
|
- */
|
|
|
+
|
|
|
data: {
|
|
|
nvabarData: {
|
|
|
showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
|
|
@@ -24,39 +21,46 @@ Page({
|
|
|
islanya: false,
|
|
|
isOnBluetooth: false,
|
|
|
},
|
|
|
- onShow() {
|
|
|
- if (!this.data.isOne) {
|
|
|
- this.Search();
|
|
|
- }
|
|
|
- },
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面加载
|
|
|
- */
|
|
|
+
|
|
|
onLoad() {
|
|
|
- const _this = this;
|
|
|
+ const that = this;
|
|
|
const isOne = setTimeout(() => {
|
|
|
clearTimeout(isOne);
|
|
|
- if (_this.data.isOne) {
|
|
|
- _this.setData({
|
|
|
+ if (that.data.isOne) {
|
|
|
+ that.setData({
|
|
|
isOne: false,
|
|
|
});
|
|
|
}
|
|
|
}, 2000);
|
|
|
+
|
|
|
if (app.globalData.oneInitBluetooth) {
|
|
|
app.globalData.oneInitBluetooth = false;
|
|
|
xBlufi.initXBlufi(1);
|
|
|
};
|
|
|
- xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent);
|
|
|
- this.Search();
|
|
|
+
|
|
|
+ xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvent);
|
|
|
+ that.Search();
|
|
|
+ },
|
|
|
+
|
|
|
+ onShow() {
|
|
|
+ var that = this;
|
|
|
+ if (!that.data.isOne) {
|
|
|
+ thithats.Search();
|
|
|
+ }
|
|
|
},
|
|
|
+
|
|
|
+ // {"type":" 41","result":true,"data":{"errno":0,"errCode":0,"isDiscovering":true,"errMsg":"startBluetoothDevicesDiscovery:ok"}}
|
|
|
+ // deviceConnect2.js:50 gadsfasdfqwerqwerqwerqer==={"type":"1","result":true,"data":[{"deviceId":"57:F6:7D:62:D6:C0","name":"","RSSI":-97,"connectable":true,"advertisData":"4c0010072a1fbee24315680100100000000000000000000000000000","advertisServiceUUIDs":[],"localName":"","serviceData":{}}]}
|
|
|
+ // {"type":"1","result":true,"data":[{"deviceId":"57:F6:7D:62:D6:C0","name":"","RSSI":-97,"connectable":true,"advertisData":"4c0010072a1fbee24315680100100000000000000000000000000000","advertisServiceUUIDs":[],"localName":"","serviceData":{}},{"deviceId":"42:E0:22:C2:6E:25","name":"","RSSI":-92,"connectable":true,"advertisData":"4c001007221fa8d7a84ba8","advertisServiceUUIDs":[],"localName":"","serviceData":{}}]}
|
|
|
funListenDeviceMsgEvent: function (options) {
|
|
|
- const _this = this;
|
|
|
+ console.log("gadsfasdfqwerqwerqwerqer===" + JSON.stringify(options));
|
|
|
+ const that = this;
|
|
|
switch (options.type) {
|
|
|
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
|
|
|
// 搜索到蓝牙
|
|
|
if (options.result) {
|
|
|
if (options.data.filter((v) => v.name.indexOf("BLUFI_") !== -1).length > 0) {
|
|
|
- _this.setData({
|
|
|
+ that.setData({
|
|
|
islanya: true,
|
|
|
devicesList: options.data.filter((v) => v.name.indexOf("BLUFI_") !== -1)
|
|
|
});
|
|
@@ -68,14 +72,14 @@ Page({
|
|
|
// console.log("连接回调:" + JSON.stringify(options))
|
|
|
if (options.result) {
|
|
|
wx.hideLoading();
|
|
|
- if (_this.data.isOnBluetooth) {
|
|
|
+ if (that.data.isOnBluetooth) {
|
|
|
return;
|
|
|
};
|
|
|
- _this.setData({
|
|
|
+ that.setData({
|
|
|
isOnBluetooth: true,
|
|
|
});
|
|
|
setTimeout(() => {
|
|
|
- _this.setData({
|
|
|
+ that.setData({
|
|
|
isSubmit: false,
|
|
|
islanya: false,
|
|
|
devicesList: [],
|
|
@@ -105,7 +109,7 @@ Page({
|
|
|
})
|
|
|
} else {
|
|
|
//蓝牙搜索开始
|
|
|
- _this.setData({
|
|
|
+ that.setData({
|
|
|
searching: true
|
|
|
});
|
|
|
}
|
|
@@ -119,13 +123,13 @@ Page({
|
|
|
//蓝牙停止搜索失败
|
|
|
console.log('蓝牙停止搜索失败')
|
|
|
}
|
|
|
- _this.setData({
|
|
|
+ that.setData({
|
|
|
searching: false
|
|
|
});
|
|
|
break;
|
|
|
-
|
|
|
}
|
|
|
},
|
|
|
+
|
|
|
Search: function () {
|
|
|
xBlufi.notifyStartDiscoverBle({
|
|
|
'isStart': true,
|
|
@@ -136,9 +140,9 @@ Page({
|
|
|
// if(!this.data.islanya) {
|
|
|
// return;
|
|
|
// };
|
|
|
-
|
|
|
// [{"deviceId":"7C:DF:A1:FC:BB:26","name":"BLUFI_7cdfa1fcbb24","RSSI":-51,"connectable":true,"advertisData":"","advertisServiceUUIDs":["0000FFFF-0000-1000-8000-00805F9B34FB"],"localName":"BLUFI_7cdfa1fcbb24","serviceData":{}}]
|
|
|
- const deviceIdData = this.data.devicesList;
|
|
|
+ var that = this;
|
|
|
+ const deviceIdData = that.data.devicesList;
|
|
|
if (deviceIdData.length < 1) {
|
|
|
wx.showToast({
|
|
|
title: '请短按设备配对键',
|
|
@@ -148,14 +152,14 @@ Page({
|
|
|
return;
|
|
|
};
|
|
|
|
|
|
- if (this.data.isSubmit) {
|
|
|
+ if (that.data.isSubmit) {
|
|
|
return;
|
|
|
};
|
|
|
- this.setData({
|
|
|
+
|
|
|
+ that.setData({
|
|
|
isSubmit: true
|
|
|
});
|
|
|
|
|
|
- // await getCurrentPages()[0].cancelCurrent();
|
|
|
// 停止搜索
|
|
|
xBlufi.notifyStartDiscoverBle({
|
|
|
'isStart': false,
|
|
@@ -173,7 +177,8 @@ Page({
|
|
|
});
|
|
|
},
|
|
|
onUnload: function () {
|
|
|
- xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent);
|
|
|
+ var that = that
|
|
|
+ xBlufi.listenDeviceMsgEvent(false, that.funListenDeviceMsgEvent);
|
|
|
},
|
|
|
getBluetoothStatus() {
|
|
|
app.getBluetoothStatus();
|