修改服务协议和隐私政策,添加注销账号功能
This commit is contained in:
@ -36,13 +36,13 @@ class BleHelper {
|
||||
linkedDevices = uni.getStorageSync(this.StorageKey);
|
||||
}
|
||||
if (linkedDevices && linkedDevices.length && linkedDevices.length > 0) {
|
||||
// console.log("111111", linkedDevices);
|
||||
console.log("111111", linkedDevices);
|
||||
linkedDevices = linkedDevices.filter((v) => {
|
||||
if (v) {
|
||||
v.Linked = false;
|
||||
v.notifyState = false;
|
||||
}
|
||||
return v ? true : false;
|
||||
return v.device ? true : false;
|
||||
});
|
||||
}
|
||||
|
||||
@ -51,12 +51,7 @@ class BleHelper {
|
||||
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
this.OpenBlue().then(() => {
|
||||
this.linkAllDevices();
|
||||
});
|
||||
|
||||
}, 10);
|
||||
|
||||
this.data = {
|
||||
isOpenBlue: false, //蓝牙模块是否开启
|
||||
available: false, //蓝牙状态是否可用
|
||||
@ -64,7 +59,8 @@ class BleHelper {
|
||||
searchList: [], //已搜索到的设备列表,
|
||||
isSubscribe: false, //是否开启了订阅
|
||||
LinkedList: linkedDevices, //已连接的设备列表
|
||||
platform: systemInfo.uniPlatform
|
||||
platform: systemInfo.uniPlatform,
|
||||
Disconnect:[]//主动断开的设备
|
||||
}
|
||||
this.cfg = {
|
||||
onDeviceFound: [], //发现新设备的事件
|
||||
@ -77,6 +73,14 @@ class BleHelper {
|
||||
this.addReceiveCallback((receive, f, path, recArr) => {
|
||||
recei.ReceiveData(receive, f, path, recArr);
|
||||
}, "BleReceiveData");
|
||||
|
||||
setTimeout(() => {
|
||||
this.OpenBlue().then(() => {
|
||||
this.linkAllDevices();
|
||||
});
|
||||
|
||||
}, 10);
|
||||
|
||||
this.dic = {
|
||||
errRemarks: [{
|
||||
key: '10000',
|
||||
@ -505,8 +509,7 @@ class BleHelper {
|
||||
console.log("开始订阅各类变化消息");
|
||||
this.data.isSubscribe = true;
|
||||
|
||||
// 保存每个设备的连接状态
|
||||
let bleDeviceStates = {};
|
||||
|
||||
|
||||
|
||||
var bytesToHexString = (bytes) => {
|
||||
@ -514,14 +517,14 @@ class BleHelper {
|
||||
'0'));
|
||||
}
|
||||
let adapterStateTime=null;
|
||||
uni.onBluetoothAdapterStateChange((state) => {
|
||||
uni.onBluetoothAdapterStateChange((state) => {
|
||||
if(this.data.discovering === state.discovering && this.data.available===state.available){
|
||||
console.error("专业给Uniapp填坑,适配器状态重复回调");
|
||||
return;
|
||||
}
|
||||
|
||||
clearTimeout(adapterStateTime);
|
||||
setTimeout(()=>{
|
||||
|
||||
if(this.data.discovering === state.discovering && this.data.available===state.available){
|
||||
console.error("专业给Uniapp填坑,适配器状态错误");
|
||||
return;
|
||||
}
|
||||
setTimeout(()=>{
|
||||
console.log('蓝牙模块状态发生变化:' + JSON.stringify(state));
|
||||
this.data.discovering = state.discovering;
|
||||
|
||||
@ -558,10 +561,7 @@ class BleHelper {
|
||||
|
||||
return true;
|
||||
});
|
||||
// let keys = Object.keys(bleDeviceStates)
|
||||
// keys.filter(v => {
|
||||
// bleDeviceStates[v] = false;
|
||||
// });
|
||||
|
||||
|
||||
this.cfg.stateBreakCallback.forEach(f => {
|
||||
try {
|
||||
@ -585,14 +585,17 @@ class BleHelper {
|
||||
uni.onBLEConnectionStateChange((res) => {
|
||||
console.log("蓝牙连接状态变化了", res);
|
||||
// 检查状态是否真的发生了变化
|
||||
if (bleDeviceStates[res.deviceId] === res.connected) {
|
||||
console.error('专业给Uniapp填坑,连接状态重复回调');
|
||||
return;
|
||||
let ble=this.data.LinkedList.find(dev=>{
|
||||
return res.deviceId===dev.deviceId;
|
||||
});
|
||||
if(ble){
|
||||
if(ble.Linked===res.connected){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 更新状态记录
|
||||
bleDeviceStates[res.deviceId] = res.connected;
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
if (!res.connected) {
|
||||
console.error("蓝牙已断开", res);
|
||||
@ -608,16 +611,23 @@ class BleHelper {
|
||||
});
|
||||
this.updateCache();
|
||||
if (f && f.device && f.device.id && this.data.available) {
|
||||
console.log("蓝牙状态可用,尝试5次恢复连接,", f
|
||||
.deviceId);
|
||||
this.LinkBlue(res.deviceId, f
|
||||
.writeServiceId, f
|
||||
.wirteCharactId, f
|
||||
.notifyCharactId, 5);
|
||||
let fdis=this.data.Disconnect.find(dis=>{
|
||||
return dis===res.deviceId
|
||||
});//用户主动断开的,不再重连
|
||||
if(!fdis){
|
||||
res.device=f.device;
|
||||
console.log("蓝牙状态可用,尝试5次恢复连接,", f
|
||||
.deviceId);
|
||||
this.LinkBlue(res.deviceId, f
|
||||
.writeServiceId, f
|
||||
.wirteCharactId, f
|
||||
.notifyCharactId, 5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (this.cfg.bleDisposeCallback.length >
|
||||
0) {
|
||||
if (this.cfg.bleDisposeCallback.length >0) {
|
||||
|
||||
this.cfg.bleDisposeCallback.forEach(
|
||||
(c) => {
|
||||
try {
|
||||
@ -816,22 +826,24 @@ class BleHelper {
|
||||
str: str,
|
||||
hexs: hexs
|
||||
};
|
||||
console.log("监听到特征值:" + JSON.stringify(recData));
|
||||
// console.log("监听到特征值:" + JSON.stringify(recData));
|
||||
if (this.cfg.receivDataCallback) {
|
||||
|
||||
if (this.cfg.receivDataCallback.length > 0) {
|
||||
|
||||
let path = this.getCurrentPagePath();
|
||||
// console.log("有人订阅消息")
|
||||
// console.log("有人订阅消息")
|
||||
this.cfg.receivDataCallback.forEach((
|
||||
rec) => {
|
||||
// console.log("有人订阅消息111", )
|
||||
// console.log("有人订阅消息111", )
|
||||
if (rec.callback) {
|
||||
try {
|
||||
// console.log("正在处理订阅消息",rec);
|
||||
rec.callback(recData, f,
|
||||
path, this.cfg
|
||||
.receivDataCallback
|
||||
);
|
||||
// console.log("处理订阅消息完毕");
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"订阅消息出现异常",
|
||||
@ -1500,6 +1512,13 @@ class BleHelper {
|
||||
}
|
||||
|
||||
this.updateCache();
|
||||
//主动连接某个设备时,从主动断开中删除
|
||||
this.data.Disconnect.find((c,index)=>{
|
||||
if(c===deviceId){
|
||||
this.data.Disconnect.splice(index,1);
|
||||
return true;
|
||||
}
|
||||
})
|
||||
// console.log("LinkedList=", this.data
|
||||
// .LinkedList);
|
||||
|
||||
@ -1654,6 +1673,7 @@ class BleHelper {
|
||||
success: (res) => {
|
||||
console.log("用户主动断开了蓝牙:" + id);
|
||||
this.subScribe(id, false);
|
||||
this.data.Disconnect.push(id);
|
||||
resolve();
|
||||
},
|
||||
fail: (ex) => {
|
||||
@ -1845,7 +1865,7 @@ class BleHelper {
|
||||
Promise.race([timeOut(ms), promise]).then(resolve).catch((ex) => {
|
||||
// console.error("ex=", ex);
|
||||
if (ex.code == -1) {
|
||||
console.error('专业给Uniapp填坑,发送消息永无回调');
|
||||
// console.error('专业给Uniapp填坑,发送消息永无回调');
|
||||
resolve(ex);
|
||||
} else {
|
||||
reject(ex);
|
||||
|
||||
Reference in New Issue
Block a user