018A初步完成
This commit is contained in:
@ -23,10 +23,11 @@
|
||||
<view class="p100">
|
||||
|
||||
<view class="lblTitle">配对设备</view>
|
||||
|
||||
|
||||
<view class="list" style="margin-bottom: 30rpx;">
|
||||
|
||||
<view class="item " @click.stop="disConnect(item,index)" v-for="item, index in PairEquip" v-show="PairEquip.length>0">
|
||||
<view class="item " @click.stop="disConnect(item,index)" v-for="item, index in PairEquip"
|
||||
v-show="PairEquip.length>0">
|
||||
<view class="leftImg ">
|
||||
<image src="/static/images/common/bluetooth.png" class="titleIco filterNone"
|
||||
mode="heightFix">
|
||||
@ -34,7 +35,7 @@
|
||||
</view>
|
||||
<view class="centertxt ">
|
||||
<view class="name" v-text="item.name"></view>
|
||||
|
||||
|
||||
</view>
|
||||
<view class="rightIco center">
|
||||
<image src="/static/images/BLEAdd/linked.png" class="img" mode="aspectFit">
|
||||
@ -50,10 +51,8 @@
|
||||
<text>发现设备:{{deviceCnt}}</text>
|
||||
<view @click="refreshBleList()">刷新</view>
|
||||
</view>
|
||||
<view class="lblTitle">
|
||||
<input class="uni-input" v-model="search" placeholder="名称筛选" />
|
||||
<!-- <uni-easyinput :styles="{color:'#ffffffde',borderColor:'#cbcbcba8'}" :clearable="true" class="uni-mt-5" :trim="'both'"
|
||||
prefixIcon="search" v-model="search" placeholder="名称筛选"></uni-easyinput> -->
|
||||
<view class="">
|
||||
<input class="uni-input" v-model="search" placeholder="名称筛选" />
|
||||
</view>
|
||||
<view class="list searchList">
|
||||
<view class="item" v-on:click="Link(item,index)" v-for="item, index in EquipMents"
|
||||
@ -165,7 +164,7 @@
|
||||
},
|
||||
search: '', //筛选
|
||||
PairEquip: [], //已配对设备
|
||||
tmpLink:[],//本次已配对
|
||||
tmpLink: [], //本次已配对
|
||||
EquipMents: [], //搜索出来的设备
|
||||
device: null,
|
||||
item: {
|
||||
@ -224,8 +223,8 @@
|
||||
|
||||
const systemInfo = uni.getSystemInfoSync();
|
||||
|
||||
// Ensure ble is initialized
|
||||
|
||||
// Ensure ble is initialized
|
||||
|
||||
if (systemInfo.uniPlatform == 'web') {
|
||||
|
||||
|
||||
@ -253,15 +252,15 @@
|
||||
];
|
||||
|
||||
console.error("1111111111")
|
||||
this.PairEquip=[this.EquipMents[0]];
|
||||
|
||||
this.PairEquip = [this.EquipMents[0]];
|
||||
|
||||
return;
|
||||
}
|
||||
ble = bleTool.getBleTool();
|
||||
this.refreshLinked();
|
||||
|
||||
this.refreshLinked();
|
||||
|
||||
let StartSubsrib = () => {
|
||||
|
||||
|
||||
these.EquipMents = [];
|
||||
if (!ble) {
|
||||
ble = bleTool.getBleTool();
|
||||
@ -366,31 +365,31 @@
|
||||
these.EquipMents.sort((a, b) => b.RSSI - a.RSSI); //信号好的排前面,一般信号好的是目标设备
|
||||
}
|
||||
}, pagePath);
|
||||
|
||||
|
||||
//蓝牙连接已恢复的回调
|
||||
ble.addRecoveryCallback(res => {
|
||||
if (these.Status.isPageHidden) {
|
||||
return;
|
||||
}
|
||||
these.refreshLinked();
|
||||
|
||||
|
||||
// hideLoading(these);
|
||||
|
||||
if (!these.device) {
|
||||
|
||||
if (!these.device) {
|
||||
hideLoading(these);
|
||||
}else{
|
||||
} else {
|
||||
clearInterval(this.Status.intval);
|
||||
these.DeviceVerdict(res.deviceId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}, pagePath);
|
||||
}
|
||||
|
||||
let startValidDevice = () => {
|
||||
if (these.device) {
|
||||
console.log("进入配对模式,启用连接恢复和验证逻辑。");
|
||||
|
||||
|
||||
|
||||
//收到设备的消息回调
|
||||
ble.addReceiveCallback((receivData, f, path, arr) => {
|
||||
@ -412,7 +411,7 @@
|
||||
showLoading(these, {
|
||||
text: '正在验证设备'
|
||||
});
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
these.DeviceVerdict(f.deviceId);
|
||||
}, 0);
|
||||
@ -424,7 +423,7 @@
|
||||
|
||||
StartSubsrib();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
},
|
||||
@ -437,19 +436,19 @@
|
||||
this.refreshLinked();
|
||||
},
|
||||
methods: {
|
||||
refreshLinked(){
|
||||
|
||||
|
||||
|
||||
if(ble){
|
||||
let arr=[];
|
||||
arr=ble.data.LinkedList.filter(v=>{
|
||||
refreshLinked() {
|
||||
|
||||
|
||||
|
||||
if (ble) {
|
||||
let arr = [];
|
||||
arr = ble.data.LinkedList.filter(v => {
|
||||
return v.Linked;
|
||||
});
|
||||
this.PairEquip=arr;
|
||||
this.PairEquip = arr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
},
|
||||
checkAndRequestLocationPermission() {
|
||||
return new Promise((resolve) => {
|
||||
@ -500,7 +499,8 @@
|
||||
}
|
||||
const hasPermission = await this.checkAndRequestLocationPermission();
|
||||
if (!hasPermission) {
|
||||
console.log("缺少定位权限,已中止蓝牙扫描。");
|
||||
|
||||
MsgError('缺少定位权限,已中止蓝牙扫描', '', this);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -524,19 +524,19 @@
|
||||
|
||||
time = setTimeout(() => {
|
||||
these.EquipMents = [];
|
||||
|
||||
|
||||
|
||||
ble.StartSearch().then(result => {
|
||||
// console.log("开始搜索成功", result);
|
||||
these.Status.BottomMenu.show=false;
|
||||
these.Status.BottomMenu.show = false;
|
||||
}).catch(err => {
|
||||
console.error("开始搜索失败:", err);
|
||||
if (err.code === 10001) {
|
||||
these.showOpenSetting();
|
||||
} else {
|
||||
|
||||
MsgClear(these);
|
||||
MsgError('出现错误:' + err.msg, '确定', these);
|
||||
MsgError('出现错误:' + err.msg, '确定', these, () => {
|
||||
MsgClear(these);
|
||||
});
|
||||
|
||||
}
|
||||
}).finally(() => {
|
||||
@ -580,9 +580,9 @@
|
||||
ble.showBlueSetting(false);
|
||||
},
|
||||
DeviceVerdict(deviceId) { //判断是否是目标设备
|
||||
if (these.Status.isPageHidden) {
|
||||
return;
|
||||
}
|
||||
if (these.Status.isPageHidden) {
|
||||
return;
|
||||
}
|
||||
console.log("deviceid=", deviceId);
|
||||
console.log("these.device=", these.device)
|
||||
if (these.device) { //从设备详情过来的,回设备详情去
|
||||
@ -681,7 +681,7 @@
|
||||
|
||||
text: "等待设备上报Mac地址," + these.Status.time + 's'
|
||||
});
|
||||
|
||||
|
||||
clearInterval(this.Status.intval);
|
||||
this.Status.intval = null;
|
||||
|
||||
@ -708,7 +708,7 @@
|
||||
}
|
||||
|
||||
updateLoading(these, {
|
||||
|
||||
|
||||
text: "等待设备上报Mac地址," + these.Status.time + 's'
|
||||
});
|
||||
|
||||
@ -729,7 +729,7 @@
|
||||
let index = 1;
|
||||
let total = 5;
|
||||
|
||||
let linkCallback = (res) => {
|
||||
let linkCallback = (res) => {
|
||||
console.log("连接成功", these.device);
|
||||
if (!these.device) {
|
||||
console.log("跳转到绑定")
|
||||
@ -746,12 +746,12 @@
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
let execLink = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
|
||||
|
||||
if (index > total) {
|
||||
reject({
|
||||
msg: "连接超时"
|
||||
@ -759,7 +759,7 @@
|
||||
return;
|
||||
}
|
||||
ble.LinkBlue(item.deviceId).then((res) => {
|
||||
this.tmpLink=[item];
|
||||
this.tmpLink = [item];
|
||||
console.log("连接成功");
|
||||
ble.StopSearch();
|
||||
resolve(res);
|
||||
@ -767,9 +767,9 @@
|
||||
if (index == total) {
|
||||
console.log("连接了N次都没连上");
|
||||
reject(ex);
|
||||
updateLoading(this, {
|
||||
text: ex.msg
|
||||
})
|
||||
updateLoading(this, {
|
||||
text: ex.msg
|
||||
})
|
||||
return;
|
||||
}
|
||||
index++;
|
||||
@ -786,7 +786,7 @@
|
||||
|
||||
execLink().then((res) => {
|
||||
console.log("res=", res);
|
||||
if(this.Status.isPageHidden){
|
||||
if (this.Status.isPageHidden) {
|
||||
return;
|
||||
}
|
||||
linkCallback(res);
|
||||
@ -802,21 +802,21 @@
|
||||
|
||||
|
||||
},
|
||||
disConnect:function(item,index){
|
||||
disConnect: function(item, index) {
|
||||
// #ifdef H5|WEB
|
||||
|
||||
this.PairEquip.splice(index,1);
|
||||
|
||||
|
||||
this.PairEquip.splice(index, 1);
|
||||
|
||||
// #endif
|
||||
// #ifdef APP|APP-PLUS
|
||||
if(ble){
|
||||
ble.disconnectDevice(item.deviceId).catch(ex=>{
|
||||
console.error("无法断开连接",ex);
|
||||
if (ble) {
|
||||
ble.disconnectDevice(item.deviceId).catch(ex => {
|
||||
console.error("无法断开连接", ex);
|
||||
});
|
||||
}
|
||||
// #endif
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user