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>
@ -73,8 +73,8 @@
<view class="slider-container">
<slider min="1" max="100" step="1" :disabled="false" :value="formData.liangDu" activeColor="#bbe600"
backgroundColor="#00000000" block-size="20" block-color="#ffffffde" @change="sliderChange"
@changing="sliderChanging" class="custom-slider" />
backgroundColor="#00000000" block-size="20" block-color="#ffffffde" @change="sliderChange"
@changing="sliderChanging" class="custom-slider" />
</view>
</view>
@ -114,20 +114,23 @@
<view class="btnSend fright" v-on:click.stop="sendUsr">发送</view>
<view class="clear"></view>
<textToDotMatrixFor7305 class="TextToHex" ref="textToHex" :txts="formData.textLines"
:bgColor="'#FFFFFF'" :color="'#000000'" :fontSize="13" />
:bgColor="'#FFFFFF'" :color="'#000000'" :fontSize="13" />
</view>
<view class="item">
<text class="lbl">单位</text>
<input class="value" maxlength="5" v-model="formData.inputLines[0]" placeholder="请输入单位" placeholder-class="usrplace" />
<input class="value" maxlength="5" v-model="formData.inputLines[0]" placeholder="请输入单位"
placeholder-class="usrplace" />
</view>
<view class="item">
<text class="lbl">部门</text>
<input class="value" maxlength="5" v-model="formData.inputLines[1]" placeholder="请输入姓名" placeholder-class="usrplace" />
<input class="value" maxlength="5" v-model="formData.inputLines[1]" placeholder="请输入姓名"
placeholder-class="usrplace" />
</view>
<view class="item">
<text class="lbl">姓名</text>
<input class="value" maxlength="5" v-model="formData.inputLines[2]" placeholder="请输入职位" placeholder-class="usrplace" />
<input class="value" maxlength="5" v-model="formData.inputLines[2]" placeholder="请输入职位"
placeholder-class="usrplace" />
</view>
</view>
@ -135,7 +138,7 @@
<!-- 下方菜单 -->
<BottomSlideMenuPlus :config="Status.BottomMenu" @close="closeMenu" @itemClick="handleItemClick"
@btnClick="btnClick">
@btnClick="btnClick">
<view class="addIco">
<view class="icoContent center" v-on:click.stop="checkImgUpload()">
<image mode="aspectFit" class="img" src="/static/images/6155/DeviceDetail/add.png"></image>
@ -160,14 +163,14 @@
} from '@/utils/loading.js'
import BleReceive from '@/utils/BleReceive';
import Common from '@/utils/Common.js';
import {
MsgSuccess,
MsgError,
MsgClose,
MsgWarning,
showPop,
MsgInfo
} from '@/utils/MsgPops.js'
import {
MsgSuccess,
MsgError,
MsgClose,
MsgWarning,
showPop,
MsgInfo
} from '@/utils/MsgPops.js'
var ble = null;
var these = null;
var BrighInteval = null;
@ -188,7 +191,7 @@
apiType: 'listA'
}],
title: 'BJQ6155',
height:90
height: 90
},
pageHide: false,
@ -260,7 +263,7 @@
textLines: [],
mode: '',
bleStatu: '',
inputLines:[]
inputLines: []
},
inteval: 500,
device: {
@ -287,8 +290,8 @@
}
},
created() {
this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 44;
},
this.Status.navbar.height = uni.getSystemInfoSync().statusBarHeight + 44;
},
onUnload() {
ble.removeAllCallback(pagePath);
},
@ -320,14 +323,7 @@
}
});
}
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) {
these.getDetail();
@ -351,10 +347,10 @@
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);
});;
}).catch(ex => {
these.formData.bleStatu = 'err';
MsgError("连接错误:" + ex.msg, "确定", these);
});;
these.setBleFormData();
these.getDetail();
@ -368,17 +364,17 @@
},
onShow: function() {
this.Status.pageHide = false;
let f=this.getDevice();
if(f){
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);
});;
}).catch(ex => {
these.formData.bleStatu = 'err';
MsgError("连接错误:" + ex.msg, "确定", these);
});;
}
},
computed: {
@ -416,7 +412,7 @@
case 3:
txt = "爆闪模式";
break;
default:
txt = "关闭";
break;
@ -446,7 +442,7 @@
these.formData.bleStatu = true;
}).catch(ex => {
these.formData.bleStatu = 'err';
MsgError("连接错误:" + ex.msg, "确定", these);
MsgError("连接错误:" + ex.msg, "确定", these);
});
return;
}
@ -490,7 +486,7 @@
if (res.deviceId == these.formData.deviceId) {
this.formData.bleStatu = true;
// 重新连接后状态以设备上报为准
}
},
@ -550,7 +546,7 @@
updateLoading(these, {
text: ex.msg
});
these.formData.bleStatu = 'err';
these.formData.bleStatu = 'err';
}).finally(() => {
setTimeout(() => {
hideLoading(these);
@ -568,12 +564,23 @@
})
},
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;
},
bleValueNotify: function(receive, device, path, recArr) {
@ -595,8 +602,8 @@
these.formData[key] = json[key];
}
});
these.formData.mode=parseInt(receive.hexs[2],16);
console.error("mode="+these.formData.mode);
these.formData.mode = parseInt(receive.hexs[2], 16);
console.error("mode=" + these.formData.mode);
if ('statu' in json) {
const chargingVal = json.statu;
const isCharging = chargingVal === 1 || chargingVal === '1' || chargingVal === true ||
@ -618,7 +625,7 @@
},
showBleUnConnect() {
this.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
@ -626,7 +633,7 @@
borderColor: "#e034344d",
buttonBgColor: "#E03434",
buttonText: '去连接',
buttonTextColor: '#FFFFFFde',
buttonTextColor: '#FFFFFFde',
okCallback: function() {
console.log("1111");
uni.navigateTo({
@ -756,7 +763,7 @@
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album','camera'],
sourceType: ['album', 'camera'],
success: function(res) {
uni.navigateTo({
url: "/pages/common/ImgCrop/ImgCrop",
@ -999,16 +1006,16 @@
case 0:
dataValue = 0x01;
dataValue = 0x01;
break;
case 1:
dataValue = 0x02;
break;
case 2:
dataValue = 0x03;
break;
@ -1042,7 +1049,7 @@
});
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 100).then(() => {
this.formData.mode = mode+1;
this.formData.mode = mode + 1;
this.setBleFormData();
}).catch((ex) => {
these.showPop({
@ -1059,8 +1066,8 @@
},
handleItemClick(item, index) {
debugger;
debugger;
this.Status.BottomMenu.activeIndex = index;
},
@ -1143,7 +1150,7 @@ debugger;
option.buttonBgColor = '#BBE600';
}
these.Status.Pop.showPop = true;
showPop(option,this);
showPop(option, this);
},
sendUsr() {
if (!this.permissions.includes('4') && this.Status.apiType !== 'listA') {
@ -1182,16 +1189,18 @@ debugger;
});
return;
}
this.formData.textLines=[this.formData.inputLines[0],this.formData.inputLines[1],this.formData.inputLines[2]];
this.formData.textLines = [this.formData.inputLines[0], this.formData.inputLines[1], this.formData
.inputLines[2]
];
showLoading(these, {
text: "发送中..."
});
this.setBleFormData();
let task = async () => {
var sendTxtPackge = (rgbdata, type, str,index) => {
var sendTxtPackge = (rgbdata, type, str, index) => {
var promise = new Promise((resolve, reject) => {
try {
@ -1234,7 +1243,10 @@ debugger;
.toString(16).padStart(2, '0'));
console.log(`发送数据块 ${chunkIndex + 1}/${numChunks}:`, hexArray
.join(' '));
updateLoading(these,{text:'正在发送'+((index-1)*14+chunkIndex + 1)+'/42'})
updateLoading(these, {
text: '正在发送' + ((index - 1) * 14 + chunkIndex +
1) + '/42'
})
ble.sendData(f.deviceId, chunk, f.writeServiceId, f
.wirteCharactId, 100).then(() => {
chunkIndex++;
@ -1291,7 +1303,7 @@ debugger;
try {
// console.log("1111");
await sendTxtPackge(rgb, h3dic[i], str,i+1);
await sendTxtPackge(rgb, h3dic[i], str, i + 1);
// console.log("222222");
} catch (ex) {
flag = false;
@ -1344,7 +1356,9 @@ debugger;
res = res.data;
let personnelInfo = res.personnelInfo;
if (personnelInfo) {
these.formData.inputLines=[personnelInfo.position,personnelInfo.name,personnelInfo.unitName];
these.formData.inputLines = [personnelInfo.position, personnelInfo.name, personnelInfo
.unitName
];
}
}
});
@ -1358,10 +1372,10 @@ debugger;
});
},
sliderChanging(evt){
sliderChanging(evt) {
this.formData.liangDu = evt.detail.value;
},
sliderChange: function(evt) {
this.formData.liangDu = evt.detail.value;
clearTimeout(BrighInteval)
@ -1820,7 +1834,7 @@ debugger;
text-align: left;
}
.slider-container {
padding: 0px;