6155添加分享
This commit is contained in:
@ -120,7 +120,7 @@
|
||||
var ble = null;
|
||||
var these = null;
|
||||
var eventChannel = null;
|
||||
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@ -164,9 +164,9 @@
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
deviceCnt:function(){
|
||||
let arr=this.EquipMents.filter(item=>{
|
||||
return item.name.toLowerCase().indexOf(this.search.toLowerCase())>-1;
|
||||
deviceCnt: function() {
|
||||
let arr = this.EquipMents.filter(item => {
|
||||
return item.name.toLowerCase().indexOf(this.search.toLowerCase()) > -1;
|
||||
});
|
||||
return arr.length;
|
||||
}
|
||||
@ -226,36 +226,36 @@
|
||||
"linkStatu": false
|
||||
},
|
||||
{
|
||||
"RSSI": -55,
|
||||
"advertisData": "",
|
||||
"advertisServiceUUIDs": [
|
||||
"0000FFE0-0000-1000-8000-00805F9B34FB"
|
||||
],
|
||||
"deviceId": "EBDA4E6F-3A28-FF65-A845-AE8CC7B78375",
|
||||
"name": "HBY670-BF74EA",
|
||||
"linkStatu": false
|
||||
},
|
||||
{
|
||||
"RSSI": -61,
|
||||
"advertisData": "",
|
||||
"advertisServiceUUIDs": [
|
||||
"0000FFE0-0000-1000-8000-00805F9B34FB"
|
||||
],
|
||||
"deviceId": "469FB381-B47E-1E40-8073-EF50B5704AAB",
|
||||
"name": "EF4651",
|
||||
"linkStatu": false,
|
||||
"isTarget": true
|
||||
},
|
||||
{
|
||||
"RSSI": -69,
|
||||
"advertisData": "",
|
||||
"advertisServiceUUIDs": [
|
||||
"0000FFE0-0000-1000-8000-00805F9B34FB"
|
||||
],
|
||||
"deviceId": "4F0DAC91-4391-CB07-905E-72D7F03EFCD3",
|
||||
"name": "4877-BF743D",
|
||||
"linkStatu": false
|
||||
},{
|
||||
"RSSI": -55,
|
||||
"advertisData": "",
|
||||
"advertisServiceUUIDs": [
|
||||
"0000FFE0-0000-1000-8000-00805F9B34FB"
|
||||
],
|
||||
"deviceId": "EBDA4E6F-3A28-FF65-A845-AE8CC7B78375",
|
||||
"name": "HBY670-BF74EA",
|
||||
"linkStatu": false
|
||||
},
|
||||
{
|
||||
"RSSI": -61,
|
||||
"advertisData": "",
|
||||
"advertisServiceUUIDs": [
|
||||
"0000FFE0-0000-1000-8000-00805F9B34FB"
|
||||
],
|
||||
"deviceId": "469FB381-B47E-1E40-8073-EF50B5704AAB",
|
||||
"name": "EF4651",
|
||||
"linkStatu": false,
|
||||
"isTarget": true
|
||||
},
|
||||
{
|
||||
"RSSI": -69,
|
||||
"advertisData": "",
|
||||
"advertisServiceUUIDs": [
|
||||
"0000FFE0-0000-1000-8000-00805F9B34FB"
|
||||
],
|
||||
"deviceId": "4F0DAC91-4391-CB07-905E-72D7F03EFCD3",
|
||||
"name": "4877-BF743D",
|
||||
"linkStatu": false
|
||||
}, {
|
||||
"RSSI": -55,
|
||||
"advertisData": "",
|
||||
"advertisServiceUUIDs": [
|
||||
@ -320,14 +320,17 @@
|
||||
if (these.Status.isPageHidden) {
|
||||
return;
|
||||
}
|
||||
console.log("处理蓝牙断开连接");
|
||||
hideLoading(these);
|
||||
// console.log("处理蓝牙断开连接");
|
||||
|
||||
|
||||
these.PairEquip.find(function(v, ind) {
|
||||
these.PairEquip.splice(ind, 1);
|
||||
return v.deviceId == res.deviceId;
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
hideLoading(these);
|
||||
}, 1500);
|
||||
|
||||
}, pagePath);
|
||||
|
||||
@ -378,8 +381,8 @@
|
||||
}
|
||||
these.EquipMents.push(device);
|
||||
}
|
||||
|
||||
these.EquipMents.sort((a, b) => b.RSSI - a.RSSI);//信号好的排前面,一般信号好的是目标设备
|
||||
|
||||
these.EquipMents.sort((a, b) => b.RSSI - a.RSSI); //信号好的排前面,一般信号好的是目标设备
|
||||
}
|
||||
}, pagePath);
|
||||
}
|
||||
@ -418,19 +421,17 @@
|
||||
|
||||
//收到设备的消息回调
|
||||
ble.addReceiveCallback((receivData, f, path, arr) => {
|
||||
console.log("000000",receivData);
|
||||
console.log("000000", receivData);
|
||||
if (these.Status.isPageHidden) {
|
||||
return;
|
||||
}
|
||||
if(receivData.bytes[0]===0xFC && receivData.hexs.length>=7){
|
||||
console.log("22222222");
|
||||
}
|
||||
if(receivData.str.indexOf('mac address:')>-1 || receivData.str.indexOf('sta_address')>-1
|
||||
|| (receivData.bytes[0]===0xFC && receivData.bytes.length>=7))
|
||||
{
|
||||
console.log("1111111");
|
||||
|
||||
if (receivData.str.indexOf('mac address:') > -1 || receivData.str.indexOf(
|
||||
'sta_address') > -1 ||
|
||||
(receivData.bytes[0] === 0xFC && receivData.bytes.length >= 7)) {
|
||||
|
||||
if (f.macAddress && these.device) {
|
||||
console.log("222222");
|
||||
|
||||
clearInterval(this.Status.intval);
|
||||
this.Status.intval = null;
|
||||
this.Status.time = null;
|
||||
@ -454,11 +455,11 @@
|
||||
console.log("接收到父页面的参数:", rec);
|
||||
these.device = rec.data;
|
||||
if (rec.data.bluetoothName) {
|
||||
these.search = rec.data.bluetoothName.replace('JQZM-', '');
|
||||
these.search = rec.data.bluetoothName;
|
||||
}
|
||||
|
||||
startValidDevice();
|
||||
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
@ -508,8 +509,8 @@
|
||||
});
|
||||
},
|
||||
async refreshBleList() {
|
||||
|
||||
|
||||
|
||||
|
||||
const systemInfo = uni.getSystemInfoSync();
|
||||
if (systemInfo.uniPlatform == 'web') {
|
||||
return;
|
||||
@ -528,42 +529,42 @@
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
ble.StopSearch().finally(() => {
|
||||
|
||||
let disconnectPromises = [];
|
||||
if (ble.data && ble.data.LinkedList) {
|
||||
ble.data.LinkedList.forEach(device => {
|
||||
console.log(`Requesting disconnect for ${device.deviceId}`);
|
||||
disconnectPromises.push(ble.disconnectDevice(device.deviceId));
|
||||
});
|
||||
}
|
||||
|
||||
Promise.allSettled(disconnectPromises).finally(() => {
|
||||
|
||||
these.EquipMents = [];
|
||||
these.PairEquip = [];
|
||||
|
||||
ble.StartSearch().then(result => {
|
||||
console.log("Fresh scan started successfully.");
|
||||
}).catch(err => {
|
||||
console.error("Failed to start fresh scan:", err);
|
||||
if (err.code === 10001) {
|
||||
these.showOpenSetting();
|
||||
} else {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '开始搜索失败:' + err.msg
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
ble.StopSearch().finally(() => {
|
||||
|
||||
let disconnectPromises = [];
|
||||
if (ble.data && ble.data.LinkedList) {
|
||||
ble.data.LinkedList.forEach(device => {
|
||||
console.log(`Requesting disconnect for ${device.deviceId}`);
|
||||
disconnectPromises.push(ble.disconnectDevice(device.deviceId));
|
||||
});
|
||||
}
|
||||
|
||||
Promise.allSettled(disconnectPromises).finally(() => {
|
||||
|
||||
these.EquipMents = [];
|
||||
these.PairEquip = [];
|
||||
|
||||
ble.StartSearch().then(result => {
|
||||
console.log("Fresh scan started successfully.");
|
||||
}).catch(err => {
|
||||
console.error("Failed to start fresh scan:", err);
|
||||
if (err.code === 10001) {
|
||||
these.showOpenSetting();
|
||||
} else {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '开始搜索失败:' + err.msg
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
},
|
||||
isItemLink: function(item, index) {
|
||||
let src = '/static/images/BLEAdd/noLink.png';
|
||||
@ -614,28 +615,71 @@
|
||||
}
|
||||
}
|
||||
|
||||
console.log("f=", f);
|
||||
if (f && f.macAddress) {
|
||||
|
||||
|
||||
if (f.macAddress != these.device.deviceMac) {
|
||||
removeLink();
|
||||
updateLoading(these, {
|
||||
text: "设备Mac地址错误,请重选设备连接"
|
||||
});
|
||||
setTimeout(() => {
|
||||
hideLoading(these);
|
||||
}, 1000)
|
||||
return;
|
||||
} else {
|
||||
|
||||
}
|
||||
//不是目标设备的处理方法
|
||||
let deviceInvalid = () => {
|
||||
console.error("连接的设备不是目标设备");
|
||||
removeLink();
|
||||
updateLoading(these, {
|
||||
text: "设备Mac地址错误,请重选设备连接"
|
||||
});
|
||||
setTimeout(() => {
|
||||
hideLoading(these);
|
||||
}, 1500)
|
||||
return;
|
||||
}
|
||||
//找到目标设备的处理方法
|
||||
let deviceOK = () => {
|
||||
hideLoading(these);
|
||||
|
||||
eventChannel.emit('BindOver', these.device);
|
||||
|
||||
ble.updateCache();
|
||||
uni.navigateBack();
|
||||
}
|
||||
|
||||
|
||||
if (f && f.macAddress) {
|
||||
|
||||
if (!this.device.deviceMac) { //走服务端验证
|
||||
console.error("走服务端验证")
|
||||
request({
|
||||
url: '/app/device/getDeviceInfoByDeviceMac',
|
||||
method: 'GET',
|
||||
data: {
|
||||
deviceMac: f.macAddress
|
||||
}
|
||||
}).then(res => {
|
||||
|
||||
|
||||
if (res && res.code == 200) {
|
||||
|
||||
let data = res.data;
|
||||
//服务端验证要验证id而不是mac地址了
|
||||
if (data.id != these.device.id) {
|
||||
deviceInvalid();
|
||||
return;
|
||||
} else {
|
||||
deviceOK();
|
||||
}
|
||||
} else {
|
||||
this.serverDevice = null;
|
||||
deviceInvalid();
|
||||
}
|
||||
|
||||
}).catch((ex) => {
|
||||
deviceInvalid();
|
||||
});
|
||||
return;
|
||||
} else if (f.macAddress != these.device.deviceMac) { //直接验证上层传过来的数据
|
||||
console.log("客户端验证失败");
|
||||
deviceInvalid();
|
||||
return;
|
||||
}
|
||||
else if (f.macAddress == these.device.deviceMac){
|
||||
console.log("客户端验证成功");
|
||||
deviceOK();
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@ -664,14 +708,8 @@
|
||||
return false;
|
||||
});
|
||||
if (!(f && f.macAddress)) {
|
||||
removeLink();
|
||||
updateLoading(these, {
|
||||
text: "出现错误,未收到设备Mac地址"
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
hideLoading(these)
|
||||
}, 1500);
|
||||
deviceInvalid()
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -1113,20 +1151,20 @@
|
||||
-webkit-filter: none !important;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.uni-input{
|
||||
|
||||
|
||||
.uni-input {
|
||||
background-color: #121212;
|
||||
width:100%;
|
||||
width: 100%;
|
||||
height: 60rpx;
|
||||
color: #ffffffde;
|
||||
border:1rpx solid #cbcbcbde;
|
||||
border: 1rpx solid #cbcbcbde;
|
||||
border-radius: 8rpx;
|
||||
font-size: 26rpx;
|
||||
text-indent: 8rpx;
|
||||
font-family: "PingFang SC";
|
||||
line-height: 60rpx;
|
||||
caret-color:#BBE600;
|
||||
caret-color: #BBE600;
|
||||
font-weight: 200;
|
||||
}
|
||||
</style>
|
||||
@ -783,31 +783,31 @@ import BleReceive from '@/utils/BleReceive';
|
||||
recei = BleReceive.getBleReceive();
|
||||
//蓝牙连接成功的回调
|
||||
ble.addRecoveryCallback((res) => {
|
||||
console.log("蓝牙连接成功的回调");
|
||||
// console.log("蓝牙连接成功的回调");
|
||||
this.bleRecovery(res);
|
||||
}, pagePath);
|
||||
|
||||
//蓝牙断开连接的回调
|
||||
ble.addDisposeCallback((res) => {
|
||||
console.log("蓝牙断开连接的回调");
|
||||
// console.log("蓝牙断开连接的回调");
|
||||
this.bleBreak(res);
|
||||
}, pagePath);
|
||||
|
||||
//蓝牙适配器恢复可用的回调,一般是重连设备
|
||||
ble.addStateRecoveryCallback(res => {
|
||||
console.log("蓝牙适配器恢复可用的回调");
|
||||
// console.log("蓝牙适配器恢复可用的回调");
|
||||
this.bleStateRecovery();
|
||||
}, pagePath);
|
||||
|
||||
//蓝牙适配器不可用的回调
|
||||
ble.addStateBreakCallback(res => {
|
||||
console.error("蓝牙适配器不可用的回调");
|
||||
// console.error("蓝牙适配器不可用的回调");
|
||||
this.bleStateBreak();
|
||||
}, pagePath);
|
||||
|
||||
//接收到消息的回调
|
||||
ble.addReceiveCallback((receive, device, path, recArr) => {
|
||||
console.error("首页收到消息了");
|
||||
// console.error("首页收到消息了");
|
||||
recei.ReceiveData(receive, device, path, recArr);
|
||||
this.updateBleStatu();
|
||||
}, pagePath);
|
||||
|
||||
Reference in New Issue
Block a user