1
0
forked from dyf/APP

修改蓝牙发现逻辑自动连接过的不再被发现的问题,上架驳回问题处理

This commit is contained in:
liub
2025-09-26 13:50:29 +08:00
parent 21e468c79f
commit 3ac113de3f
6 changed files with 104 additions and 47 deletions

View File

@ -2,7 +2,7 @@
"name" : "星汉物联", "name" : "星汉物联",
"appid" : "__UNI__A21EF43", "appid" : "__UNI__A21EF43",
"description" : "设备管控", "description" : "设备管控",
"versionName" : "1.0.0", "versionName" : "1.0.1",
"versionCode" : "100", "versionCode" : "100",
"transformPx" : false, "transformPx" : false,
/* 5+App */ /* 5+App */
@ -60,11 +60,13 @@
"ios" : { "ios" : {
"dSYMs" : false, "dSYMs" : false,
"privacyDescription" : { "privacyDescription" : {
"NSLocationWhenInUseUsageDescription" : "App需要您的同意,才能在使用期间访问位置", "NSLocationWhenInUseUsageDescription" : "App需要您的同意,访问位置,用于判定装备位置是否异常",
"NSLocationAlwaysUsageDescription" : "App需要您的同意,才能始终访问位置", "NSLocationAlwaysUsageDescription" : "App需要您的同意,访问位置,用于判定装备位置是否异常",
"NSLocationAlwaysAndWhenInUseUsageDescription" : "App需要您的同意,才能始终访问位置", "NSLocationAlwaysAndWhenInUseUsageDescription" : "App需要您的同意,才能始终访问位置",
"NSBluetoothPeripheralUsageDescription" : "需要蓝牙访问权限,用于设备通信", "NSBluetoothPeripheralUsageDescription" : "App需要您的同意访问蓝牙访问权限,用于设备通信与反向控制",
"NSBluetoothAlwaysUsageDescription" : "需要蓝牙访问权限,用于设备通信" "NSBluetoothAlwaysUsageDescription" : "App需要您的同意访问蓝牙访问权限,用于设备通信与反向控制",
"NSPhotoLibraryUsageDescription" : "App需要您的同意访问相册,用于上传头像,设备开机画面",
"NSPhotoLibraryAddUsageDescription" : "App需要您的同意访问相册,用于上传头像,设备开机画面"
}, },
"idfa" : false "idfa" : false
}, },

View File

@ -285,6 +285,7 @@
ble.removeReceiveCallback(pagePath); ble.removeReceiveCallback(pagePath);
clearTimeout(this.Statu.timeInteval); clearTimeout(this.Statu.timeInteval);
this.device.macAddress=null;
this.Statu.timeInteval=null; this.Statu.timeInteval=null;
uni.$emit("refreshDeviceList"); uni.$emit("refreshDeviceList");
setTimeout(() => { setTimeout(() => {

View File

@ -152,11 +152,36 @@
}, },
onLoad() { onLoad() {
these = this; these = this;
this.EquipMents = [];
ble = bleTool.getBleTool(); ble = bleTool.getBleTool();
//已连接过但删除了设备
let delArr = ble.data.deletedEqs.map(v => {
return {
"deviceId": v.deviceId,
"name": v.name,
"RSSI": -99,
"localName": v.name,
}
});
//已连接过但没绑定过的设备
let noDev=ble.data.LinkedList.filter(v=>{
return !(v.device && v.device.id);
}).map(v => {
return {
"deviceId": v.deviceId,
"name": v.name,
"RSSI": -99,
"localName": v.name,
}
});
delArr=delArr.concat(noDev);
console.log("可能搜不到的设备=", delArr);
this.EquipMents = delArr;
ble.addDeviceFound((arr) => { ble.addDeviceFound((arr) => {
// console.log("发现新设备,",arr);
arr = arr.devices; arr = arr.devices;
for (var i = 0; i < arr.length; i++) { for (var i = 0; i < arr.length; i++) {
@ -164,12 +189,16 @@
if (!arr[i].name) { if (!arr[i].name) {
continue; continue;
} }
let f = these.EquipMents.find(function(v) { let f = these.EquipMents.find(function(v) {
return v.deviceId == arr[i].deviceId; return v.deviceId == arr[i].deviceId;
}); });
if (!f) { if (!f) {
if (arr[i].deviceId == '35:06:00:EF:46:51') {
console.log("EquipMents=", these.EquipMents);
console.log("arr[i]=", arr[i]);
}
these.EquipMents.push(arr[i]); these.EquipMents.push(arr[i]);
} else { } else {
@ -207,6 +236,7 @@
// this.EquipMents = []; // this.EquipMents = [];
this.PairEquip = []; this.PairEquip = [];
ble && ble.StartSearch().then(res => { ble && ble.StartSearch().then(res => {
console.log("开始搜索成功", res); console.log("开始搜索成功", res);
@ -216,11 +246,6 @@
these.showOpenSetting(); these.showOpenSetting();
} }
}); });
}, },
methods: { methods: {
isItemLink: function(item, index) { isItemLink: function(item, index) {
@ -260,19 +285,19 @@
} }
return false; return false;
}); });
let removeLink=()=>{ let removeLink = () => {
ble.subScribe(deviceId,false);//取消订阅消息 ble.subScribe(deviceId, false); //取消订阅消息
ble.DropDevice(deviceId);//从缓存中删除该设备 ble.DropDevice(deviceId); //从缓存中删除该设备
ble.disconnectDevice(deviceId);//断开与该设备的连接 ble.disconnectDevice(deviceId); //断开与该设备的连接
these.device.deviceMac="";
let index=this.PairEquip.findIndex(function(v) { let index = this.PairEquip.findIndex(function(v) {
return v.deviceId == deviceId; return v.deviceId == deviceId;
}); });
if(index>-1){ if (index > -1) {
this.PairEquip.splice(index,1); this.PairEquip.splice(index, 1);
} }
} }
console.log("f=", f); console.log("f=", f);
if (f.macAddress) { if (f.macAddress) {
@ -282,7 +307,7 @@
updateLoading(these, { updateLoading(these, {
text: "设备Mac地址错误,请重选设备连接" text: "设备Mac地址错误,请重选设备连接"
}); });
setTimeout(() => { setTimeout(() => {
hideLoading(these); hideLoading(these);
}, 1000) }, 1000)
@ -300,9 +325,9 @@
this.Status.intval = null; this.Status.intval = null;
this.Status.intval = setInterval(() => { this.Status.intval = setInterval(() => {
this.Status.time = this.Status.time-1; this.Status.time = this.Status.time - 1;
if (this.Status.time < 0) { if (this.Status.time < 0) {
clearInterval(this.Status.intval) clearInterval(this.Status.intval)
@ -315,15 +340,15 @@
} }
return false; return false;
}); });
if(!f.macAddress){ if (!f.macAddress) {
removeLink(); removeLink();
updateLoading(these, { updateLoading(these, {
text: "出现错误,未收到设备Mac地址" text: "出现错误,未收到设备Mac地址"
}); });
setTimeout(()=>{ setTimeout(() => {
hideLoading(these) hideLoading(these)
},1000); }, 1000);
} }
return; return;
} }
@ -387,7 +412,7 @@
} }
ble.LinkBlue(item.deviceId).then((res) => { ble.LinkBlue(item.deviceId).then((res) => {
console.log("连接成功"); console.log("连接成功");
ble.StopSearch();
resolve(res); resolve(res);
}).catch((ex) => { }).catch((ex) => {
if (index == total) { if (index == total) {

View File

@ -467,7 +467,8 @@
if (this.$refs.swipeAction) { if (this.$refs.swipeAction) {
this.$refs.swipeAction.closeAll(); this.$refs.swipeAction.closeAll();
} }
console.log("111111",this.deviceId);
console.log("ble==null,",ble)
ble && ble.DropDevice(this.deviceId.id); ble && ble.DropDevice(this.deviceId.id);
} else { } else {
uni.showToast({ uni.showToast({

View File

@ -72,8 +72,8 @@
data() { data() {
return { return {
showView: false, showView: false,
phone: '13800138002', //手机号码 phone: '', //手机号码
code: "123456", //验证码 code: "", //验证码
password: "", password: "",
agreed: false, agreed: false,
isCounting: false, isCounting: false,

View File

@ -17,6 +17,7 @@ const serviceDic = [ //合作供应商的蓝牙主服务
class BleHelper { class BleHelper {
constructor() { constructor() {
this.StorageKey = "linkedDevices"; this.StorageKey = "linkedDevices";
this.dropKey = "DeletedDevices";
recei = receivTool.getBleReceive(); recei = receivTool.getBleReceive();
this.init(); this.init();
@ -24,23 +25,26 @@ class BleHelper {
init() { init() {
let key = this.StorageKey; let key = this.StorageKey;
var store = uni.getStorageInfoSync(); var store = uni.getStorageInfoSync();
var f = store.keys.find(function(v) { var f = store.keys.includes(key);
return v == key;
});
var linkedDevices = []; var linkedDevices = [];
if (f) { if (f) {
linkedDevices = uni.getStorageSync(key); linkedDevices = uni.getStorageSync(key);
} }
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) => {
v.Linked = false; v.Linked = false;
v.notifyState = false; v.notifyState = false;
return true;
return v.device && v.device.id;
}); });
} }
var deletedEqs = [];
f = store.keys.includes(this.dropKey);
if (f) {
deletedEqs = uni.getStorageSync(this.dropKey);
}
setTimeout(() => { setTimeout(() => {
this.OpenBlue().then(() => { this.OpenBlue().then(() => {
this.linkAllDevices(); this.linkAllDevices();
@ -54,6 +58,7 @@ class BleHelper {
searchList: [], //已搜索到的设备列表, searchList: [], //已搜索到的设备列表,
isSubscribe: false, //是否开启了订阅 isSubscribe: false, //是否开启了订阅
LinkedList: linkedDevices, //已连接的设备列表 LinkedList: linkedDevices, //已连接的设备列表
deletedEqs: deletedEqs
} }
this.cfg = { this.cfg = {
onDeviceFound: [], //发现新设备的事件 onDeviceFound: [], //发现新设备的事件
@ -124,25 +129,47 @@ class BleHelper {
} }
//从缓存中删除某个设备bleId蓝牙iddeviceId数据库中的设备id //从缓存中删除某个设备bleId蓝牙iddeviceId数据库中的设备id
DropDevice(bleId, deviceId) { DropDevice(bleId, deviceId) {
let flag = false; let flag = false;
let delItem=null;
if (!this.data.deletedEqs || !this.data.deletedEqs.length) {
this.data.deletedEqs = [];
}
for (var i = 0; i < this.data.LinkedList.length; i++) { for (var i = 0; i < this.data.LinkedList.length; i++) {
let item = this.data.LinkedList[i]; let item = this.data.LinkedList[i];
if (bleId) { if (bleId) {
if (item.deviceId == bleId) { if (item.device.id == bleId) {
console.log("找到要删除的设备", item);
this.data.LinkedList.splice(i, 1); this.data.LinkedList.splice(i, 1);
this.disconnectDevice(item.deviceId);
flag = true; flag = true;
delItem=item;
break; break;
} }
} else { } else {
if (item.device && item.device.id) { if (deviceId && item.deviceId == deviceId) {
console.log("找到要删除的设备1,", item)
this.data.LinkedList.splice(i, 1); this.data.LinkedList.splice(i, 1);
this.disconnectDevice(item.deviceId);
flag = true; flag = true;
delItem=item;
break; break;
} }
} }
} }
if (flag) { if (flag) {
this.data.deletedEqs=this.data.deletedEqs.filter(v => {
return v.deviceId != delItem.deviceId;
});
this.data.deletedEqs.push(delItem);
this.updateCache(); this.updateCache();
} }
@ -152,24 +179,25 @@ class BleHelper {
updateCache() { updateCache() {
// console.log("this.StorageKey=", this.StorageKey) // console.log("this.StorageKey=", this.StorageKey)
uni.setStorageSync(this.StorageKey, this.data.LinkedList); uni.setStorageSync(this.StorageKey, this.data.LinkedList);
uni.setStorageSync(this.dropKey, this.data.deletedEqs);
} }
linkAllDevices() { linkAllDevices() {
// console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList); // console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
if (this.data.LinkedList && this.data.LinkedList.length > 0) { if (this.data.LinkedList && this.data.LinkedList.length > 0) {
let flag=false; let flag = false;
for (var i = 0; i < this.data.LinkedList.length; i++) { for (var i = 0; i < this.data.LinkedList.length; i++) {
let device = this.data.LinkedList[i]; let device = this.data.LinkedList[i];
// console.log("自动连接绑定过的设备:" + device.deviceId); // console.log("自动连接绑定过的设备:" + device.deviceId);
if (device.macAddress && device.device && device.device.id) { if (device.macAddress && device.device && device.device.id) {
this.LinkBlue(device.deviceId, device.writeServiceId, device.wirteCharactId, device this.LinkBlue(device.deviceId, device.writeServiceId, device.wirteCharactId, device
.notifyCharactId); .notifyCharactId);
flag=true; flag = true;
} }
} }
if(!flag){ if (!flag) {
this.updateCache(); this.updateCache();
} }
} else { } else {
@ -449,7 +477,7 @@ class BleHelper {
this.data.discovering = state.discovering; this.data.discovering = state.discovering;
if (this.data.available && this.data if (this.data.available && this.data
.isOpenBlue) { //蓝牙状态再次可用,重连所有设备 .isOpenBlue) { //蓝牙状态再次可用,重连所有设备
this.linkAllDevices(); // this.linkAllDevices();
} }
} }
@ -1346,7 +1374,7 @@ class BleHelper {
uni.closeBLEConnection({ uni.closeBLEConnection({
deviceId: id, deviceId: id,
success: (res) => { success: (res) => {
////console.log("蓝牙连接已断开:" + id); console.log("蓝牙连接已断开:" + id);
this.subScribe(id, false); this.subScribe(id, false);
resolve(); resolve();
}, },