new-20250827 #39
8
App.vue
8
App.vue
@ -27,7 +27,7 @@
|
|||||||
// uni.removeStorageSync(val);
|
// uni.removeStorageSync(val);
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
uni.clearStorageSync();
|
// uni.clearStorageSync();
|
||||||
//以上代码仅在开发时使用,否则会出现不可预知的问题。
|
//以上代码仅在开发时使用,否则会出现不可预知的问题。
|
||||||
|
|
||||||
// #ifdef APP|APP-PLUS
|
// #ifdef APP|APP-PLUS
|
||||||
@ -93,8 +93,10 @@
|
|||||||
// #ifdef APP|APP-PLUS
|
// #ifdef APP|APP-PLUS
|
||||||
let ble = bleTool.getBleTool();
|
let ble = bleTool.getBleTool();
|
||||||
if (ble) {
|
if (ble) {
|
||||||
console.log("断开所有蓝牙设备");
|
console.log("App隐藏了,断开所有蓝牙设备,停止搜索");
|
||||||
ble.disconnectDevice();
|
ble.StopSearch().catch(ex=>{});
|
||||||
|
ble.disconnectDevice().catch(ex=>{});
|
||||||
|
|
||||||
}
|
}
|
||||||
// #endif
|
// #endif
|
||||||
},
|
},
|
||||||
|
|||||||
@ -385,7 +385,7 @@
|
|||||||
}
|
}
|
||||||
let f = ble.data.LinkedList.find((v) => {
|
let f = ble.data.LinkedList.find((v) => {
|
||||||
if (v.macAddress == device.deviceMac) {
|
if (v.macAddress == device.deviceMac) {
|
||||||
console.log("找到设备了", v);
|
// console.log("找到设备了", v);
|
||||||
these.formData.deviceId = v.deviceId;
|
these.formData.deviceId = v.deviceId;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,7 +53,9 @@
|
|||||||
Statu: {
|
Statu: {
|
||||||
bound: null,
|
bound: null,
|
||||||
timeInteval: null,
|
timeInteval: null,
|
||||||
isSearch: false
|
isSearch: false,
|
||||||
|
pageHide:false,
|
||||||
|
isBind:false
|
||||||
},
|
},
|
||||||
device: {
|
device: {
|
||||||
"deviceId": "",
|
"deviceId": "",
|
||||||
@ -115,17 +117,32 @@
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onShow() {
|
||||||
|
this.Statu.pageHide=false;
|
||||||
|
},
|
||||||
|
onHide() {
|
||||||
|
this.Statu.pageHide=true;
|
||||||
|
},
|
||||||
onUnload() {
|
onUnload() {
|
||||||
console.log("返回取消订阅");
|
console.log("返回取消订阅");
|
||||||
clearInterval(inteval);
|
clearInterval(inteval);
|
||||||
ble.removeAllCallback(pagePath);
|
ble.removeAllCallback(pagePath);
|
||||||
|
|
||||||
|
if(!this.Statu.isBind && these.device.deviceId){
|
||||||
|
ble.disconnectDevice(these.device.deviceId).catch(ex=>{
|
||||||
|
console.error("无法断开蓝牙连接");
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onLoad(option) {
|
onLoad(option) {
|
||||||
these = this;
|
these = this;
|
||||||
ble = bleTool.getBleTool();
|
ble = bleTool.getBleTool();
|
||||||
|
|
||||||
ble.addStateBreakCallback(res => {
|
ble.addStateBreakCallback(res => {
|
||||||
|
if(this.Statu.pageHide){
|
||||||
|
return;
|
||||||
|
}
|
||||||
these.device.linkStatu = false;
|
these.device.linkStatu = false;
|
||||||
hideLoading(these);
|
hideLoading(these);
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@ -135,6 +152,9 @@
|
|||||||
},pagePath);
|
},pagePath);
|
||||||
|
|
||||||
ble.addStateRecoveryCallback(res => {
|
ble.addStateRecoveryCallback(res => {
|
||||||
|
if(this.Statu.pageHide){
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (these.device.deviceId) {
|
if (these.device.deviceId) {
|
||||||
showLoading(these, {
|
showLoading(these, {
|
||||||
text: '蓝牙已恢复正在连接设备'
|
text: '蓝牙已恢复正在连接设备'
|
||||||
@ -144,6 +164,9 @@
|
|||||||
}
|
}
|
||||||
},pagePath);
|
},pagePath);
|
||||||
ble.addDisposeCallback(res => {
|
ble.addDisposeCallback(res => {
|
||||||
|
if(this.Statu.pageHide){
|
||||||
|
return;
|
||||||
|
}
|
||||||
console.log("处理蓝牙断开连接");
|
console.log("处理蓝牙断开连接");
|
||||||
these.device.linkStatu = false;
|
these.device.linkStatu = false;
|
||||||
if (these.device.deviceId == res.deviceId) {
|
if (these.device.deviceId == res.deviceId) {
|
||||||
@ -156,6 +179,9 @@
|
|||||||
},pagePath);
|
},pagePath);
|
||||||
|
|
||||||
ble.addReceiveCallback((receive, f, path) => {
|
ble.addReceiveCallback((receive, f, path) => {
|
||||||
|
if(this.Statu.pageHide){
|
||||||
|
return;
|
||||||
|
}
|
||||||
console.log("收到设备消息,", receive);
|
console.log("收到设备消息,", receive);
|
||||||
if (these.device.deviceId == receive.deviceId) {
|
if (these.device.deviceId == receive.deviceId) {
|
||||||
console.log("11111:", receive);
|
console.log("11111:", receive);
|
||||||
@ -372,6 +398,7 @@
|
|||||||
clearTimeout(this.Statu.timeInteval);
|
clearTimeout(this.Statu.timeInteval);
|
||||||
this.device.macAddress = null;
|
this.device.macAddress = null;
|
||||||
this.Statu.timeInteval = null;
|
this.Statu.timeInteval = null;
|
||||||
|
this.Statu.isBind=true;
|
||||||
uni.$emit("refreshDeviceList");
|
uni.$emit("refreshDeviceList");
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
uni.switchTab({
|
uni.switchTab({
|
||||||
|
|||||||
@ -23,6 +23,7 @@
|
|||||||
<view class="p100">
|
<view class="p100">
|
||||||
|
|
||||||
<view class="lblTitle">配对设备</view>
|
<view class="lblTitle">配对设备</view>
|
||||||
|
|
||||||
<view class="list" style="margin-bottom: 30rpx;">
|
<view class="list" style="margin-bottom: 30rpx;">
|
||||||
|
|
||||||
<view class="item " v-for="item, index in PairEquip" v-show="PairEquip.length>0">
|
<view class="item " v-for="item, index in PairEquip" v-show="PairEquip.length>0">
|
||||||
@ -33,9 +34,7 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="centertxt ">
|
<view class="centertxt ">
|
||||||
<view class="name" v-text="item.name"></view>
|
<view class="name" v-text="item.name"></view>
|
||||||
<view class="id">
|
|
||||||
<text>信号:{{item.RSSI}}dBm</text>
|
|
||||||
</view>
|
|
||||||
</view>
|
</view>
|
||||||
<view class="rightIco center">
|
<view class="rightIco center">
|
||||||
<image src="/static/images/BLEAdd/linked.png" class="img" mode="aspectFit">
|
<image src="/static/images/BLEAdd/linked.png" class="img" mode="aspectFit">
|
||||||
@ -134,6 +133,7 @@
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
Status: {
|
Status: {
|
||||||
|
navigateTO: false,
|
||||||
isPageHidden: false,
|
isPageHidden: false,
|
||||||
intval: null,
|
intval: null,
|
||||||
time: null,
|
time: null,
|
||||||
@ -164,12 +164,14 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
search: '', //筛选
|
search: '', //筛选
|
||||||
PairEquip: [], //已配对设备
|
PairEquip: [], //本次已配对设备
|
||||||
EquipMents: [], //搜索出来的设备
|
EquipMents: [], //搜索出来的设备
|
||||||
device: null,
|
device: null,
|
||||||
item: {
|
item: {
|
||||||
deviceId: ''
|
deviceId: ''
|
||||||
}
|
},
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -189,9 +191,20 @@
|
|||||||
if (ble) {
|
if (ble) {
|
||||||
ble.StopSearch();
|
ble.StopSearch();
|
||||||
ble.removeAllCallback(pagePath);
|
ble.removeAllCallback(pagePath);
|
||||||
|
if (!this.device && !this.Status.navigateTO) {
|
||||||
|
if (this.PairEquip && this.PairEquip.length && this.PairEquip.length > 0) {
|
||||||
|
console.error("页面卸载时,断开所有连接")
|
||||||
|
let f = this.PairEquip.forEach((v) => {
|
||||||
|
ble.disconnectDevice(v.deviceId).catch(ex => {
|
||||||
|
console.error("无法断开设备连接", ex);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad(option) {
|
onLoad(option) {
|
||||||
|
debugger;
|
||||||
eventChannel = this.getOpenerEventChannel();
|
eventChannel = this.getOpenerEventChannel();
|
||||||
|
|
||||||
eventChannel.on('detailData', function(rec) {
|
eventChannel.on('detailData', function(rec) {
|
||||||
@ -211,8 +224,8 @@
|
|||||||
|
|
||||||
const systemInfo = uni.getSystemInfoSync();
|
const systemInfo = uni.getSystemInfoSync();
|
||||||
|
|
||||||
ble = bleTool.getBleTool(); // Ensure ble is initialized
|
// Ensure ble is initialized
|
||||||
|
|
||||||
if (systemInfo.uniPlatform == 'web') {
|
if (systemInfo.uniPlatform == 'web') {
|
||||||
|
|
||||||
|
|
||||||
@ -236,86 +249,19 @@
|
|||||||
"name": "EF4651",
|
"name": "EF4651",
|
||||||
"linkStatu": false,
|
"linkStatu": false,
|
||||||
"isTarget": true
|
"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": [
|
|
||||||
"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
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
console.error("1111111111")
|
||||||
these.PairEquip = [this.EquipMents[0]];
|
this.PairEquip=[this.EquipMents[0]];
|
||||||
this.$forceUpdate();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ble = bleTool.getBleTool();
|
||||||
|
this.refreshLinked();
|
||||||
|
|
||||||
let StartSubsrib = () => {
|
let StartSubsrib = () => {
|
||||||
|
|
||||||
these.EquipMents = [];
|
these.EquipMents = [];
|
||||||
if (!ble) {
|
if (!ble) {
|
||||||
ble = bleTool.getBleTool();
|
ble = bleTool.getBleTool();
|
||||||
@ -327,6 +273,7 @@
|
|||||||
}
|
}
|
||||||
console.log("处理蓝牙不可用");
|
console.log("处理蓝牙不可用");
|
||||||
hideLoading(these);
|
hideLoading(these);
|
||||||
|
console.error("1111111111")
|
||||||
these.PairEquip = [];
|
these.PairEquip = [];
|
||||||
these.EquipMents = [];
|
these.EquipMents = [];
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@ -336,13 +283,14 @@
|
|||||||
these.showOpenSetting();
|
these.showOpenSetting();
|
||||||
|
|
||||||
}, pagePath);
|
}, pagePath);
|
||||||
|
|
||||||
//蓝牙恢复可用的回调
|
//蓝牙恢复可用的回调
|
||||||
ble.addStateRecoveryCallback(res=>{
|
ble.addStateRecoveryCallback(res => {
|
||||||
if (these.Status.isPageHidden) {
|
if (these.Status.isPageHidden) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
these.Status.BottomMenu.show = false;
|
these.Status.BottomMenu.show = false;
|
||||||
|
console.error("1111111111")
|
||||||
these.PairEquip = [];
|
these.PairEquip = [];
|
||||||
these.EquipMents = [];
|
these.EquipMents = [];
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@ -350,7 +298,7 @@
|
|||||||
title: '蓝牙恢复可用'
|
title: '蓝牙恢复可用'
|
||||||
});
|
});
|
||||||
these.refreshBleList();
|
these.refreshBleList();
|
||||||
}),pagePath;
|
}), pagePath;
|
||||||
|
|
||||||
//蓝牙断开连接的回调
|
//蓝牙断开连接的回调
|
||||||
ble.addDisposeCallback(res => {
|
ble.addDisposeCallback(res => {
|
||||||
@ -360,10 +308,7 @@
|
|||||||
// console.log("处理蓝牙断开连接");
|
// console.log("处理蓝牙断开连接");
|
||||||
|
|
||||||
|
|
||||||
these.PairEquip.find(function(v, ind) {
|
these.refreshLinked();
|
||||||
these.PairEquip.splice(ind, 1);
|
|
||||||
return v.deviceId == res.deviceId;
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
hideLoading(these);
|
hideLoading(these);
|
||||||
@ -422,39 +367,37 @@
|
|||||||
these.EquipMents.sort((a, b) => b.RSSI - a.RSSI); //信号好的排前面,一般信号好的是目标设备
|
these.EquipMents.sort((a, b) => b.RSSI - a.RSSI); //信号好的排前面,一般信号好的是目标设备
|
||||||
}
|
}
|
||||||
}, pagePath);
|
}, pagePath);
|
||||||
|
|
||||||
|
//蓝牙连接已恢复的回调
|
||||||
|
ble.addRecoveryCallback(res => {
|
||||||
|
if (these.Status.isPageHidden) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
these.refreshLinked();
|
||||||
|
|
||||||
|
// hideLoading(these);
|
||||||
|
|
||||||
|
if (these.device) {
|
||||||
|
clearInterval(this.Status.intval);
|
||||||
|
showLoading(these, {
|
||||||
|
text: '蓝牙连接已恢复,正在验证设备'
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
these.DeviceVerdict(res.deviceId);
|
||||||
|
}, 0);
|
||||||
|
} else {
|
||||||
|
hideLoading(these);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}, pagePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
let startValidDevice = () => {
|
let startValidDevice = () => {
|
||||||
if (these.device) {
|
if (these.device) {
|
||||||
console.log("进入配对模式,启用连接恢复和验证逻辑。");
|
console.log("进入配对模式,启用连接恢复和验证逻辑。");
|
||||||
//蓝牙连接已恢复的回调
|
|
||||||
ble.addRecoveryCallback(res => {
|
|
||||||
if (these.Status.isPageHidden) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// hideLoading(these);
|
|
||||||
these.EquipMents.find(function(v, ind) {
|
|
||||||
if (v.deviceId == res.deviceId) {
|
|
||||||
these.PairEquip.push(v);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
if (these.device) {
|
|
||||||
clearInterval(this.Status.intval);
|
|
||||||
showLoading(these, {
|
|
||||||
text: '蓝牙连接已恢复,正在验证设备'
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
these.DeviceVerdict(res.deviceId);
|
|
||||||
}, 0);
|
|
||||||
} else {
|
|
||||||
hideLoading(these);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}, pagePath);
|
|
||||||
|
|
||||||
//收到设备的消息回调
|
//收到设备的消息回调
|
||||||
ble.addReceiveCallback((receivData, f, path, arr) => {
|
ble.addReceiveCallback((receivData, f, path, arr) => {
|
||||||
@ -488,15 +431,33 @@
|
|||||||
|
|
||||||
StartSubsrib();
|
StartSubsrib();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onShow: function() {
|
onShow: function() {
|
||||||
|
debugger;
|
||||||
this.Status.isPageHidden = false;
|
this.Status.isPageHidden = false;
|
||||||
|
this.Status.navigateTO = false;
|
||||||
this.refreshBleList();
|
this.refreshBleList();
|
||||||
|
this.refreshLinked();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
refreshLinked(){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(ble){
|
||||||
|
let arr=[];
|
||||||
|
arr=ble.data.LinkedList.filter(v=>{
|
||||||
|
return v.Linked;
|
||||||
|
});
|
||||||
|
this.PairEquip=arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
checkAndRequestLocationPermission() {
|
checkAndRequestLocationPermission() {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
|
||||||
@ -515,16 +476,21 @@
|
|||||||
resolve(true);
|
resolve(true);
|
||||||
} else {
|
} else {
|
||||||
// console.warn('定位权限被拒绝');
|
// console.warn('定位权限被拒绝');
|
||||||
|
|
||||||
MsgClear(these);
|
MsgClear(these);
|
||||||
showPop({headerTxt:'权限提醒',message:'扫描蓝牙设备,需要您开启定位权限',buttonText:'去开启',okCallback:uni.openSetting},these,true);
|
showPop({
|
||||||
|
headerTxt: '权限提醒',
|
||||||
|
message: '扫描蓝牙设备,需要您开启定位权限',
|
||||||
|
buttonText: '去开启',
|
||||||
|
okCallback: uni.openSetting
|
||||||
|
}, these, true);
|
||||||
|
|
||||||
resolve(false);
|
resolve(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
|
|
||||||
MsgError('请求定位权限失败:'+error.code,'确定',these);
|
MsgError('请求定位权限失败:' + error.code, '确定', these);
|
||||||
resolve(false);
|
resolve(false);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -565,19 +531,20 @@
|
|||||||
|
|
||||||
time = setTimeout(() => {
|
time = setTimeout(() => {
|
||||||
these.EquipMents = [];
|
these.EquipMents = [];
|
||||||
|
console.error("1111111111")
|
||||||
these.PairEquip = [];
|
these.PairEquip = [];
|
||||||
|
|
||||||
ble.StartSearch().then(result => {
|
ble.StartSearch().then(result => {
|
||||||
console.log("开始搜索成功", result);
|
// console.log("开始搜索成功", result);
|
||||||
|
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error("开始搜索失败:", err);
|
console.error("开始搜索失败:", err);
|
||||||
if (err.code === 10001) {
|
if (err.code === 10001) {
|
||||||
these.showOpenSetting();
|
these.showOpenSetting();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
MsgClear(these);
|
MsgClear(these);
|
||||||
MsgError('出现错误:' + err.msg,'确定',these);
|
MsgError('出现错误:' + err.msg, '确定', these);
|
||||||
|
|
||||||
}
|
}
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
@ -587,8 +554,8 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ble.StopSearch().catch(err=>{
|
ble.StopSearch().catch(err => {
|
||||||
console.error("err=",err);
|
console.error("err=", err);
|
||||||
}).finally(startSearch);
|
}).finally(startSearch);
|
||||||
|
|
||||||
|
|
||||||
@ -741,10 +708,10 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateLoading(these, {
|
hideLoading(these);
|
||||||
text: "等待设备上报Mac地址," + these.Status.time + 's'
|
|
||||||
});
|
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -760,14 +727,7 @@
|
|||||||
let index = 1;
|
let index = 1;
|
||||||
let total = 5;
|
let total = 5;
|
||||||
|
|
||||||
let linkCallback = (res) => {
|
let linkCallback = (res) => {
|
||||||
let c = these.PairEquip.find(function(v) {
|
|
||||||
return v.deviceId == item.deviceId;
|
|
||||||
});
|
|
||||||
if (!c) {
|
|
||||||
|
|
||||||
these.PairEquip.push(item);
|
|
||||||
}
|
|
||||||
console.log("连接成功", these.device);
|
console.log("连接成功", these.device);
|
||||||
if (!these.device) {
|
if (!these.device) {
|
||||||
console.log("跳转到绑定")
|
console.log("跳转到绑定")
|
||||||
@ -778,7 +738,7 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
success(res) {
|
success(res) {
|
||||||
|
these.Status.navigateTO = true;
|
||||||
res.eventChannel.emit('LinkItem', item);
|
res.eventChannel.emit('LinkItem', item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -825,8 +785,8 @@
|
|||||||
}).catch(ex => {
|
}).catch(ex => {
|
||||||
console.error("ex=", ex)
|
console.error("ex=", ex)
|
||||||
MsgClear(these);
|
MsgClear(these);
|
||||||
|
|
||||||
MsgError("连接失败:" + ex.msg,'确定',these);
|
MsgError("连接失败:" + ex.msg, '确定', these);
|
||||||
hideLoading(these);
|
hideLoading(these);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -304,14 +304,14 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
bleBreak(res) {
|
bleBreak(res) {
|
||||||
console.error("蓝牙断开连接", res);
|
// console.error("蓝牙断开连接", res);
|
||||||
if (res.deviceId) {
|
if (res.deviceId) {
|
||||||
this.updateBleStatu(res.deviceId);
|
this.updateBleStatu(res.deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
bleRecovery(res) {
|
bleRecovery(res) {
|
||||||
console.log("蓝牙连接成功", res);
|
// console.log("蓝牙连接成功", res);
|
||||||
if (res.deviceId) {
|
if (res.deviceId) {
|
||||||
this.updateBleStatu(res.deviceId);
|
this.updateBleStatu(res.deviceId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,7 +36,7 @@ class BleHelper {
|
|||||||
linkedDevices = uni.getStorageSync(this.StorageKey);
|
linkedDevices = uni.getStorageSync(this.StorageKey);
|
||||||
}
|
}
|
||||||
if (linkedDevices && linkedDevices.length && linkedDevices.length > 0) {
|
if (linkedDevices && linkedDevices.length && linkedDevices.length > 0) {
|
||||||
console.log("111111", linkedDevices);
|
// console.log("111111", linkedDevices);
|
||||||
linkedDevices = linkedDevices.filter((v) => {
|
linkedDevices = linkedDevices.filter((v) => {
|
||||||
if (v) {
|
if (v) {
|
||||||
v.Linked = false;
|
v.Linked = false;
|
||||||
@ -613,13 +613,13 @@ class BleHelper {
|
|||||||
if (this.data.isSubscribe) { //整个App生命周期,只订阅一次
|
if (this.data.isSubscribe) { //整个App生命周期,只订阅一次
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.error("开始订阅各类变化消息");
|
// console.error("开始订阅各类变化消息");
|
||||||
this.data.isSubscribe = true;
|
this.data.isSubscribe = true;
|
||||||
this.BleStateChange(); //蓝牙适配器变化
|
this.BleStateChange(); //蓝牙适配器变化
|
||||||
this.BleConnChange(); //蓝牙连接变化
|
this.BleConnChange(); //蓝牙连接变化
|
||||||
this.BleDeviceFound(); //发现新设备
|
this.BleDeviceFound(); //发现新设备
|
||||||
this.BleReceive(); //收到消息
|
this.BleReceive(); //收到消息
|
||||||
console.error("订阅各类变化消息完成");
|
// console.error("订阅各类变化消息完成");
|
||||||
},
|
},
|
||||||
fail: (ex2) => {
|
fail: (ex2) => {
|
||||||
console.error("蓝牙模块启动失败", ex2);
|
console.error("蓝牙模块启动失败", ex2);
|
||||||
@ -962,7 +962,7 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log("蓝牙连接已恢复", res);
|
// console.log("蓝牙连接已恢复", res);
|
||||||
// 系统级连接恢复:更新 LinkedList 并通知业务层,避免 sendData 误判未连接而重复 createBLEConnection
|
// 系统级连接恢复:更新 LinkedList 并通知业务层,避免 sendData 误判未连接而重复 createBLEConnection
|
||||||
let f = this.data.LinkedList.find(v => v.deviceId == res.deviceId);
|
let f = this.data.LinkedList.find(v => v.deviceId == res.deviceId);
|
||||||
if (f) {
|
if (f) {
|
||||||
@ -1098,7 +1098,7 @@ class BleHelper {
|
|||||||
services: [],
|
services: [],
|
||||||
allowDuplicatesKey: true,
|
allowDuplicatesKey: true,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log('开始搜索蓝牙设备成功');
|
// console.log('开始搜索蓝牙设备成功');
|
||||||
resolve(res);
|
resolve(res);
|
||||||
|
|
||||||
},
|
},
|
||||||
@ -1237,11 +1237,11 @@ class BleHelper {
|
|||||||
characteristicId: characteristicId,
|
characteristicId: characteristicId,
|
||||||
state: state,
|
state: state,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
if (state) {
|
// if (state) {
|
||||||
console.log("订阅消息成功", res);
|
// console.log("订阅消息成功", res);
|
||||||
} else {
|
// } else {
|
||||||
console.log("取消订阅成功", res);
|
// console.log("取消订阅成功", res);
|
||||||
}
|
// }
|
||||||
|
|
||||||
this.data.LinkedList.find((v) => {
|
this.data.LinkedList.find((v) => {
|
||||||
if (v.deviceId == deviceId) {
|
if (v.deviceId == deviceId) {
|
||||||
@ -1311,13 +1311,13 @@ class BleHelper {
|
|||||||
|
|
||||||
results.forEach((result, index) => {
|
results.forEach((result, index) => {
|
||||||
if (result.status === "fulfilled") {
|
if (result.status === "fulfilled") {
|
||||||
console.log(`订阅消息操作${index + 1}成功:`, result.value);
|
// console.log(`订阅消息操作${index + 1}成功:`, result.value);
|
||||||
} else {
|
} else {
|
||||||
console.error(`订阅消息操作${index + 1}失败:`, result
|
console.error(`订阅消息操作${index + 1}失败:`, result
|
||||||
.reason);
|
.reason);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log("订阅消息完成,deviceId:", deviceId);
|
// console.log("订阅消息完成,deviceId:", deviceId);
|
||||||
resolve();
|
resolve();
|
||||||
}).catch((ex) => {
|
}).catch((ex) => {
|
||||||
console.error("异常,ex=", ex);
|
console.error("异常,ex=", ex);
|
||||||
|
|||||||
@ -14,8 +14,7 @@ class BleReceive {
|
|||||||
'/pages/100/HBY100': this.Receive_100.bind(this),
|
'/pages/100/HBY100': this.Receive_100.bind(this),
|
||||||
'/pages/102/HBY102': this.Receive_102.bind(this),
|
'/pages/102/HBY102': this.Receive_102.bind(this),
|
||||||
'/pages/6170/deviceControl/index':this.Receive_6170.bind(this),
|
'/pages/6170/deviceControl/index':this.Receive_6170.bind(this),
|
||||||
'/pages/100J/HBY100-J': this.Receive_100J.bind(this),
|
'/pages/100J/HBY100-J': this.Receive_100J.bind(this)
|
||||||
'/pages/102/HBY102': this.Receive_102.bind(this)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user