1
0
forked from dyf/APP

修复有时候蓝牙配对成功依然提示未连接的异常

This commit is contained in:
liub
2026-05-20 10:58:55 +08:00
parent 7ed3813e7c
commit 7f56e46ace
19 changed files with 1031 additions and 914 deletions

View File

@ -10,7 +10,7 @@
<view slot="right">
<view class="navbarRight center">
<view class="imgContent" :class="{'visibilityHidden':Status.apiType!=item.apiType}"
@click.stop="handleRightClick(item,index)" v-for="item,index in Status.navbar.icons">
@click.stop="handleRightClick(item,index)" v-for="item,index in Status.navbar.icons">
<image class="img" :src="item.src" mode="aspectFit"></image>
<view class="baber" v-if="item.math">{{item.math>9?'9+':item.math}}</view>
</view>
@ -78,19 +78,19 @@
<view class="modeSetting">
<view class="item" :class="formData.modeCurr=='smalllow'?'active':''"
@click="MainModeSetting('smalllow','staticBattery')">
@click="MainModeSetting('smalllow','staticBattery')">
<view class="p100 center">前置</view>
</view>
<view class="item" :class="formData.modeCurr=='low'?'active':''"
@click="MainModeSetting('low','staticBattery')">
@click="MainModeSetting('low','staticBattery')">
<view class="p100 center">低档</view>
</view>
<view class="item " :class="formData.modeCurr=='center'?'active':''"
@click="MainModeSetting('center','staticBattery')">
@click="MainModeSetting('center','staticBattery')">
<view class="p100 center">中档</view>
</view>
<view class="item " :class="formData.modeCurr=='hight'?'active':''"
@click="MainModeSetting('hight','staticBattery')">
@click="MainModeSetting('hight','staticBattery')">
<view class="p100 center">高档</view>
</view>
@ -113,8 +113,7 @@
</view>
</view>
<view class="mode marginLeft fleft"
v-on:click.stop="ShowUpload()">
<view class="mode marginLeft fleft" v-on:click.stop="ShowUpload()">
<view class="leftImg">
<image class="img" src="/static/images/6155/DeviceDetail/open.png" mode="aspectFit"></image>
</view>
@ -161,11 +160,11 @@
</view>
<ProParams :id="device.id"></ProParams>
<!-- 下方菜单 -->
<BottomSlideMenuPlus :config="Status.BottomMenu" @close="closeMenu" @itemClick="handleItemClick"
@btnClick="btnClick">
@btnClick="btnClick">
</BottomSlideMenuPlus>
<global-loading ref="loading" />
@ -183,20 +182,22 @@
hideLoading,
updateLoading
} from '@/utils/loading.js'
import request, { baseURL } from '@/utils/request.js';
import request, {
baseURL
} from '@/utils/request.js';
import usrApi from '@/api/670/HBY670.js';
import {
MsgSuccess,
MsgError,
MsgClose,
MsgWarning,
showPop,
MsgInfo
} from '@/utils/MsgPops.js'
import {
MsgSuccess,
MsgError,
MsgClose,
MsgWarning,
showPop,
MsgInfo
} from '@/utils/MsgPops.js'
const pagePath = "/pages/650/HBY650";
import SendBatchData from '@/utils/SendBatchData.js';
var batchTool=null;
var batchTool = null;
var ble = null;
var these = null;
var recei = null;
@ -212,20 +213,20 @@ import request, { baseURL } from '@/utils/request.js';
apiType: 'listA'
}],
title: 'HBY650'
},
pageHide: false,
BottomMenu: {
show: false,
showHeader: true,
menuItems: [{
text: '照片',
value:'img'
text: '照片',
value: 'img'
},
{
text: '动画',
value:'flash'
text: '动画',
value: 'flash'
}
],
activeIndex: -1,
@ -296,8 +297,8 @@ import request, { baseURL } from '@/utils/request.js';
},
}
},
created() {
this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 44;
created() {
this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 44;
},
onUnload() {
console.log("页面卸载,释放资源");
@ -334,14 +335,7 @@ created() {
}
});
}
let f = ble.data.LinkedList.find((v) => {
if (v.macAddress == device.deviceMac) {
// console.log("找到设备了", v);
these.formData.deviceId = v.deviceId;
return true;
}
return false;
});
let f = these.getDevice();
if (!f) {
@ -363,13 +357,13 @@ created() {
these.formData.bleStatu = false;
these.formData.deviceId = f.deviceId;
these.formData.bleStatu='connecting';
these.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
these.formData.bleStatu = true;
}).catch(ex => {
these.formData.bleStatu = 'err';
MsgError("连接错误:" + ex.msg, "确定", these);
});;
}).catch(ex => {
these.formData.bleStatu = 'err';
MsgError("连接错误:" + ex.msg, "确定", these);
});;
these.setBleFormData();
console.error("222222");
these.getDetail();
@ -383,64 +377,64 @@ created() {
},
onShow() {
this.Status.pageHide = false;
let f=this.getDevice();
if(f){
these.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
console.log("连接成功")
these.formData.bleStatu = true;
}).catch(ex => {
these.formData.bleStatu = 'err';
MsgError("连接错误:" + ex.msg, "确定", these);
});;
}
let f = this.getDevice();
if (f) {
these.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
console.log("连接成功")
these.formData.bleStatu = true;
}).catch(ex => {
these.formData.bleStatu = 'err';
MsgError("连接错误:" + ex.msg, "确定", these);
});;
}
},
computed: {
getbleStatu(){
if(this.formData.bleStatu===true){
return '已连接';
}
if(this.formData.bleStatu==='connecting'){
return '连接中';
}
if(this.formData.bleStatu==='dicconnect'){
return '正在断开';
}
if(this.formData.bleStatu==='err'){
return '连接异常';
}
return '未连接';
}
getbleStatu() {
if (this.formData.bleStatu === true) {
return '已连接';
}
if (this.formData.bleStatu === 'connecting') {
return '连接中';
}
if (this.formData.bleStatu === 'dicconnect') {
return '正在断开';
}
if (this.formData.bleStatu === 'err') {
return '连接异常';
}
return '未连接';
}
},
methods: {
bleStatuToggle(){
let f=this.getDevice();
if(!f){
this.showBleUnConnect();
return;
}
if(this.formData.bleStatu===true){
this.formData.bleStatu='dicconnect';
ble.disconnectDevice(f.deviceId).finally(r=>{
this.formData.bleStatu=false;
});
return;
}
if(this.formData.bleStatu===false || this.formData.bleStatu==='err'){
this.formData.bleStatu='connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
these.formData.bleStatu = true;
}).catch(ex=>{
these.formData.bleStatu = 'err';
MsgError("连接错误:" + ex.msg, "确定", these);
});
return;
}
},
bleStatuToggle() {
let f = this.getDevice();
if (!f) {
this.showBleUnConnect();
return;
}
if (this.formData.bleStatu === true) {
this.formData.bleStatu = 'dicconnect';
ble.disconnectDevice(f.deviceId).finally(r => {
this.formData.bleStatu = false;
});
return;
}
if (this.formData.bleStatu === false || this.formData.bleStatu === 'err') {
this.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
these.formData.bleStatu = true;
}).catch(ex => {
these.formData.bleStatu = 'err';
MsgError("连接错误:" + ex.msg, "确定", these);
});
return;
}
},
handleRightClick(item, s) {
if (item && item.callback) {
item.callback(item, s);
@ -448,7 +442,7 @@ created() {
uni.showModal({
content: '敬请期待'
})
}
},
navigatorBack() {
@ -477,7 +471,7 @@ created() {
}
if (res.deviceId == these.formData.deviceId) {
this.formData.bleStatu = true;
}
},
@ -486,9 +480,9 @@ created() {
// return;
// }
if (res.deviceId == these.formData.deviceId) {
if(res.device){
if (res.device) {
these.formData.bleStatu = 'connecting';
}else{
} else {
this.formData.bleStatu = false;
}
setTimeout(() => {
@ -523,7 +517,7 @@ created() {
showLoading(this, {
text: "蓝牙恢复可用,正在连接设备"
});
this.formData.bleStatu='connecting';
this.formData.bleStatu = 'connecting';
ble.LinkBlue(these.formData.deviceId).then(() => {
these.formData.bleStatu = true;
updateLoading(these, {
@ -533,7 +527,7 @@ created() {
updateLoading(these, {
text: ex.msg
});
MsgError("连接错误:" + ex.msg, "确定", these);
MsgError("连接错误:" + ex.msg, "确定", these);
}).finally(() => {
setTimeout(() => {
hideLoading(these);
@ -624,7 +618,7 @@ created() {
iconUrl: "/static/images/6155/DeviceDetail/warnning.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
},these);
}, these);
}
these.setBleFormData();
@ -640,12 +634,23 @@ created() {
},
getDevice: function() {
// console.log("LinkedList=", ble.data.LinkedList);
// console.log("formData=", these.formData);
let f = ble.data.LinkedList.find((v) => {
return v.macAddress == these.device.deviceMac;
let flag = v.macAddress == these.device.deviceMac;
if (!flag && v.device) {
flag = v.device.id == these.device.id;
}
if (flag) {
these.formData.deviceId = v.deviceId;
}
return flag;
});
// #ifdef WEB
f = {
deviceId: '123'
}
// #endif
return f;
},
getDetail() {
@ -663,7 +668,7 @@ created() {
return;
}
}
});
},
@ -681,9 +686,9 @@ created() {
uni.setStorageSync(ble.StorageKey, ble.data.LinkedList);
},
MainModeSetting: function(type, byteType) {
if (!this.permissions.includes('41') && this.Status.apiType !== 'listA') {
showPop({
message: '无操作权限',
iconUrl: "/static/images/common/uploadErr.png",
@ -691,10 +696,10 @@ created() {
buttonBgColor: "#E03434",
okCallback: null,
buttonText: "确定"
},these)
}, these)
return;
}
if (this.formData.modeCurr == type) {
type = 'close';
}
@ -769,7 +774,7 @@ created() {
iconUrl: "/static/images/common/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
},these);
}, these);
}).finally(() => {
@ -795,7 +800,7 @@ created() {
borderColor: "#e034344d",
buttonBgColor: "#E03434",
buttonText: '去连接',
buttonTextColor: '#FFFFFFde',
buttonTextColor: '#FFFFFFde',
okCallback: function() {
uni.navigateTo({
@ -817,7 +822,7 @@ created() {
}
})
}
},these);
}, these);
},
LampToggle: function() {
if (!this.permissions.includes('1') && this.Status.apiType !== 'listA') {
@ -829,39 +834,39 @@ created() {
buttonBgColor: "#E03434",
okCallback: null,
buttonText: "确定"
},these)
}, these)
return;
}
this.formData.cMode = !this.formData.cMode;
this.MainModeSetting(this.formData.cMode, "lamp");
},
checkImgUpload: function(type, index) {
let f = these.getDevice();
if(!f){
if (!f) {
this.showBleUnConnect();
return;
}
if(!batchTool){
batchTool=new SendBatchData(these,f,ble);
if (!batchTool) {
batchTool = new SendBatchData(these, f, ble);
}
if (type) {
if (type == 'img') {
// sendImagePackets(index);
batchTool.SendImg();
} else{
} else {
// sendVideoPackets(index);
batchTool.SendVideo(506);
}
}
return;
console.log("123213213213");
// 分包发送图片数据
var sendImagePackets = function(ReSendNo) {
@ -886,7 +891,7 @@ created() {
showPop: true,
message: "上传成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
},these);
}, these);
if (!ReSendNo) {
setTimeout(() => {
these.HoldYouHand("transmit complete", 0, f
@ -928,7 +933,7 @@ created() {
dataView.setUint8(2, currentPacket); // 包序号
dataView.setUint16(3, packetData.length*2,false); // 包t长度
dataView.setUint16(3, packetData.length * 2, false); // 包t长度
// 填充数据每个RGB565值占2字节
for (let i = 0; i < packetData.length; i++) {
@ -971,7 +976,7 @@ created() {
iconUrl: "/static/images/common/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
},these);
}, these);
hideLoading(these);
reject(err);
});
@ -992,7 +997,7 @@ created() {
iconUrl: "/static/images/common/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
},these);
}, these);
hideLoading(these);
reject(err);
});
@ -1068,7 +1073,7 @@ created() {
showPop: true,
message: "上传成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png"
},these);
}, these);
@ -1145,7 +1150,7 @@ created() {
buttonBgColor: "#E03434",
buttonText: "确定",
iconUrl: "/static/images/common/uploadErr.png"
},these);
}, these);
reject(err);
return;
}
@ -1245,7 +1250,7 @@ created() {
iconUrl: "/static/images/common/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
},these);
}, these);
}
}).catch((ex) => {
@ -1256,7 +1261,7 @@ created() {
iconUrl: "/static/images/common/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
},these);
}, these);
})
}
let f = these.getDevice();
@ -1320,9 +1325,9 @@ created() {
},
ShowUpload: function() {
if (!this.permissions.includes('3') && this.Status.apiType !== 'listA') {
showPop({
message: '无操作权限',
iconUrl: "/static/images/common/uploadErr.png",
@ -1330,14 +1335,14 @@ created() {
buttonBgColor: "#E03434",
okCallback: null,
buttonText: "确定"
},these)
}, these)
return;
}
//上传开机画面
this.Status.BottomMenu.title = "上传开机画面";
this.Status.BottomMenu.type = "checkImg";
this.Status.BottomMenu.show = true;
this.Status.BottomMenu.activeIndex=0;
this.Status.BottomMenu.activeIndex = 0;
},
showMenu(flag) {
@ -1348,7 +1353,7 @@ created() {
},
btnClick(item, index) {
this.Status.BottomMenu.show = false;
this.checkImgUpload(item.value,index);
this.checkImgUpload(item.value, index);
},
@ -1360,11 +1365,11 @@ created() {
},
handleItemClick(item, index) {
this.Status.BottomMenu.activeIndex = index;
},
sendUsr: function(ReSendNo) {
if (!this.permissions.includes('4') && this.Status.apiType !== 'listA') {
@ -1376,7 +1381,7 @@ created() {
buttonBgColor: "#E03434",
okCallback: null,
buttonText: "确定"
},these)
}, these)
return;
}
@ -1436,7 +1441,7 @@ created() {
promptTitle: '',
modelValue: '',
visibleClose: true
},these);
}, these);
these.setBleFormData();
@ -1499,7 +1504,7 @@ created() {
iconUrl: "/static/images/common/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
},these);
}, these);
}).finally(() => {
hideLoading(these);
});
@ -1533,7 +1538,7 @@ created() {
iconUrl: "/static/images/common/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
},these);
}, these);
});
}, 0);
@ -1909,7 +1914,7 @@ created() {
text-align: left;
}
.slider-container {
padding: 0px;
@ -2104,27 +2109,27 @@ created() {
.net.active {
background: #FFFFFF !important;
}
.navbarRight {
width: 40px;
height: 100%;
}
.navbarRight .imgContent {
width: 36rpx;
height: 36rpx;
position: relative;
}
.navbarRight .imgContent:first-child {
width: 38rpx !important;
height: 38rpx !important;
margin-top: -2rpx;
}
.navbarRight .imgContent .baber {
position: absolute;
z-index: 100;
@ -2140,33 +2145,33 @@ created() {
font-style: Regular;
font-size: 20rpx;
font-weight: 400;
text-align: center;
overflow: hidden;
white-space: nowrap;
}
.navbarRight .imgContent .img {
width: 100%;
height: 100%;
box-sizing: border-box;
position: relative;
}
.navbarRight .imgContent .img:last-child {
padding: 1rpx;
}
.nvbar {
top: 0px;
}
/deep/ .uni-navbar--fixed {
top: 0px;
}
.uninavebartext {
width: 100%;
font-size: 32rpx;