|
|
@@ -184,7 +184,7 @@
|
|
|
}
|
|
|
|
|
|
// 获取蓝牙设备,并列表
|
|
|
- this.openBluetoothAdapter();
|
|
|
+ this.openBluetoothAdapter("get_room");
|
|
|
},
|
|
|
onShow() {
|
|
|
// 充值后更新金额
|
|
|
@@ -200,7 +200,7 @@
|
|
|
* 单击连接热水表
|
|
|
*/
|
|
|
clickRoom(e) {
|
|
|
- if (this.judgeBalance() == false) {
|
|
|
+ if (this.judgeBalance('clickRoom') == false) {
|
|
|
return
|
|
|
}
|
|
|
// console.log(e);
|
|
|
@@ -213,10 +213,8 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- this.process_control(0);
|
|
|
-
|
|
|
// 开始连接匹配的蓝牙设备
|
|
|
- this.createBLEConnection()
|
|
|
+ this.openBluetoothAdapter();
|
|
|
},
|
|
|
/**
|
|
|
* 空中连接热水表
|
|
|
@@ -543,7 +541,7 @@
|
|
|
/**
|
|
|
* 判断余额是否充足
|
|
|
*/
|
|
|
- judgeBalance() {
|
|
|
+ judgeBalance(param) {
|
|
|
var limit_amount = parseFloat(this.$store.state.amount)
|
|
|
var amount = parseFloat(this.amount);
|
|
|
// 启动最低金额限制
|
|
|
@@ -557,42 +555,40 @@
|
|
|
if (res.confirm) {
|
|
|
// 跳转充值页面
|
|
|
this.chongzhi_yemian()
|
|
|
- // return false
|
|
|
- // } else if (res.cancel) {
|
|
|
- // return false
|
|
|
+ // return false
|
|
|
+ // } else if (res.cancel) {
|
|
|
+ // return false
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
return false
|
|
|
- } else {
|
|
|
- return true
|
|
|
- }
|
|
|
- },
|
|
|
- /**
|
|
|
- * 111111111111111111111111111111
|
|
|
- * 扫码连接设备
|
|
|
- */
|
|
|
- scan() {
|
|
|
- if (this.judgeBalance() == false) {
|
|
|
- return
|
|
|
}
|
|
|
+
|
|
|
// 已经启动扫描连接设备中
|
|
|
if (this.isScan) {
|
|
|
uni.showToast({
|
|
|
icon: 'none',
|
|
|
title: '正在扫描,请耐心等待',
|
|
|
})
|
|
|
- return
|
|
|
+ return false
|
|
|
}
|
|
|
+
|
|
|
// 已经启动设备,不启动扫描
|
|
|
if (this.isChecked) {
|
|
|
+ let info_str = ''
|
|
|
+ if (param == 'scan') {
|
|
|
+ info_str = '设备已启动,无需重新扫码'
|
|
|
+ } else {
|
|
|
+ info_str = '设备已启动,无需重新启动'
|
|
|
+ }
|
|
|
uni.showToast({
|
|
|
icon: 'none',
|
|
|
- title: '设备已启动,无需重新扫码',
|
|
|
+ title: info_str,
|
|
|
})
|
|
|
- return
|
|
|
+ return false
|
|
|
}
|
|
|
|
|
|
+ // 设备已连接
|
|
|
if (this.deviceId) {
|
|
|
uni.showModal({
|
|
|
title: '提示',
|
|
|
@@ -600,18 +596,33 @@
|
|
|
success: res => {
|
|
|
if (res.confirm) {
|
|
|
this.closeBLEConnection()
|
|
|
-
|
|
|
- this.scan_qr()
|
|
|
- } else if (res.cancel) {
|
|
|
- return
|
|
|
+ if (param == 'scan') {
|
|
|
+ this.scan_qr()
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ icon: 'none',
|
|
|
+ title: '请选择宿舍号重新连接',
|
|
|
+ duration: 3000
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
- } else {
|
|
|
- this.scan_qr()
|
|
|
+ return false
|
|
|
}
|
|
|
},
|
|
|
/**
|
|
|
+ * 111111111111111111111111111111
|
|
|
+ * 扫码连接设备
|
|
|
+ */
|
|
|
+ scan() {
|
|
|
+ if (this.judgeBalance('scan') == false) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ this.scan_qr()
|
|
|
+ },
|
|
|
+ /**
|
|
|
* 启动摄像头,扫描二维码
|
|
|
*/
|
|
|
scan_qr() {
|
|
|
@@ -649,7 +660,7 @@
|
|
|
* 22222222222222222222222222222
|
|
|
* 初始化蓝牙
|
|
|
*/
|
|
|
- openBluetoothAdapter() {
|
|
|
+ openBluetoothAdapter(param) {
|
|
|
uni.openBluetoothAdapter({
|
|
|
success: (res) => { // 已打开
|
|
|
uni.getBluetoothAdapterState({ // 蓝牙的匹配状态
|
|
|
@@ -658,7 +669,7 @@
|
|
|
// 本机设备的蓝牙已打开
|
|
|
// 开始搜索蓝牙设备
|
|
|
if (this.deviceId == '' && this.serviceId == '')
|
|
|
- this.startBluetoothDeviceDiscovery()
|
|
|
+ this.startBluetoothDeviceDiscovery(param)
|
|
|
},
|
|
|
fail: (error) => {
|
|
|
// console.log(error)
|
|
|
@@ -695,7 +706,7 @@
|
|
|
* 333333333333333333333333333
|
|
|
* 开始搜索蓝牙设备
|
|
|
*/
|
|
|
- startBluetoothDeviceDiscovery() {
|
|
|
+ startBluetoothDeviceDiscovery(param) {
|
|
|
uni.startBluetoothDevicesDiscovery({ // 开始搜寻附近的蓝牙外围设备
|
|
|
// services: ['FEE7'], // 要搜索但蓝牙设备主 service 的 uuid 列表
|
|
|
allowDuplicatesKey: true,
|
|
|
@@ -703,7 +714,7 @@
|
|
|
if (this.get_Bluetooth_Bevice == true)
|
|
|
this.process_control(0)
|
|
|
|
|
|
- this.onBluetoothDeviceFound() // 监听搜索到新设备 同时进行
|
|
|
+ this.onBluetoothDeviceFound(param) // 监听搜索到新设备 同时进行
|
|
|
|
|
|
setTimeout(() => {
|
|
|
if (this.isScan) {
|
|
|
@@ -746,7 +757,7 @@
|
|
|
})
|
|
|
},
|
|
|
|
|
|
- stopBluetoothDevicesDiscovery: function() { //停止搜索
|
|
|
+ stopBluetoothDevicesDiscovery(param) { //停止搜索
|
|
|
uni.stopBluetoothDevicesDiscovery({
|
|
|
success: (res) => {
|
|
|
// console.log(res, '停止蓝牙搜索')
|
|
|
@@ -755,17 +766,17 @@
|
|
|
// duration: 2000
|
|
|
// })
|
|
|
if (this.get_Bluetooth_Bevice == true) {
|
|
|
- this.process_control(0);
|
|
|
-
|
|
|
- // 开始连接匹配的蓝牙设备
|
|
|
- this.createBLEConnection()
|
|
|
+ if (param != 'get_room') {
|
|
|
+ // 开始连接匹配的蓝牙设备
|
|
|
+ this.createBLEConnection()
|
|
|
+ }
|
|
|
} else {
|
|
|
- this.get_Bluetooth_Bevice == true
|
|
|
+ this.get_Bluetooth_Bevice = true
|
|
|
+ this.get_room()
|
|
|
}
|
|
|
- this.get_room()
|
|
|
},
|
|
|
- fail: e => {
|
|
|
- // console.log('停止搜索蓝牙设备失败,错误码:' + e.errCode);
|
|
|
+ fail: err => {
|
|
|
+ // console.log('停止搜索蓝牙设备失败,错误码:' + err.errCode);
|
|
|
this.isScan = false
|
|
|
uni.showToast({
|
|
|
title: err.errCode,
|
|
|
@@ -779,7 +790,7 @@
|
|
|
* 444444444444444444444444444444444
|
|
|
* 发现外围设备
|
|
|
*/
|
|
|
- onBluetoothDeviceFound() {
|
|
|
+ onBluetoothDeviceFound(param) {
|
|
|
uni.onBluetoothDeviceFound((res) => {
|
|
|
let dname = ''
|
|
|
let i = 0
|
|
|
@@ -809,14 +820,13 @@
|
|
|
this.deviceId = device.deviceId
|
|
|
|
|
|
// 放此位置,苹果手机兼容
|
|
|
- this.stopBluetoothDevicesDiscovery()
|
|
|
+ this.stopBluetoothDevicesDiscovery(param)
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
setTimeout(() => {
|
|
|
- // 放此位置,苹果手机兼容
|
|
|
- this.stopBluetoothDevicesDiscovery()
|
|
|
+ this.stopBluetoothDevicesDiscovery(param)
|
|
|
}, 2000)
|
|
|
})
|
|
|
});
|
|
|
@@ -897,7 +907,7 @@
|
|
|
this.connect_BLE()
|
|
|
} else {
|
|
|
uni.showToast({
|
|
|
- title: '建立连接失败',
|
|
|
+ title: '未知错误,请重连1次。',
|
|
|
icon: 'none',
|
|
|
duration: 3000,
|
|
|
success: (res1) => {
|
|
|
@@ -913,8 +923,6 @@
|
|
|
if (this.isConnected === false) {
|
|
|
this.isConnected = true
|
|
|
|
|
|
- this.process_control(1);
|
|
|
-
|
|
|
// 获取蓝牙设备所有服务(service)
|
|
|
this.getBLEDeviceServices()
|
|
|
}
|
|
|
@@ -963,8 +971,6 @@
|
|
|
serviceId: this.serviceId,
|
|
|
success: (res) => {
|
|
|
|
|
|
- this.process_control(2);
|
|
|
-
|
|
|
// console.log(res)
|
|
|
this.characteristicIdForWrite = res.characteristics[0].uuid
|
|
|
this.characteristicIdForNotity = res.characteristics[1].uuid
|
|
|
@@ -997,6 +1003,13 @@
|
|
|
characteristicId: this.characteristicIdForNotity,
|
|
|
success: (res) => {
|
|
|
this.process_control(2)
|
|
|
+
|
|
|
+ uni.showToast({
|
|
|
+ icon:'none',
|
|
|
+ title:'需要启动请点【开启设备】开关',
|
|
|
+ duration: 3000
|
|
|
+ })
|
|
|
+
|
|
|
this.isScan = false
|
|
|
// console.log('通知启用(notifyBLECharacteristicValueChange)',res);
|
|
|
this.onBLECharacteristicValueChange()
|
|
|
@@ -1071,7 +1084,6 @@
|
|
|
// icon: 'none'
|
|
|
// })
|
|
|
|
|
|
- this.process_control(3)
|
|
|
this.isChecked = true
|
|
|
|
|
|
break
|
|
|
@@ -1113,14 +1125,15 @@
|
|
|
this.closeBluetoothAdapter()
|
|
|
},
|
|
|
fail: () => {
|
|
|
- uni.showToast({
|
|
|
- icon: 'none',
|
|
|
- title: '蓝牙连接断开失败',
|
|
|
- duration: 3000,
|
|
|
- success: (res1) => {
|
|
|
- this.setInit()
|
|
|
- }
|
|
|
- })
|
|
|
+ this.setInit()
|
|
|
+ // uni.showToast({
|
|
|
+ // icon: 'none',
|
|
|
+ // title: '蓝牙连接断开失败',
|
|
|
+ // duration: 3000,
|
|
|
+ // success: (res1) => {
|
|
|
+ // this.setInit()
|
|
|
+ // }
|
|
|
+ // })
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
@@ -1191,8 +1204,6 @@
|
|
|
if (val == 'start') { // 启动设备
|
|
|
this.isUserClose = false
|
|
|
|
|
|
- this.process_control(3)
|
|
|
- // this.createBLEConnection()
|
|
|
// 发送 17字节 启动代码(会返回 35字节 的数据)
|
|
|
// b58000265243eb3dd4bb3c5a2ab9042efcf0d2a30a000000000000000014392a0103bc
|
|
|
newArr = this.str2StrArray(this.start_code)
|