1
0
forked from dyf/APP

修复6155蓝牙上报数据灯光状态不跟随变化的问题。

This commit is contained in:
liub
2025-12-19 13:37:14 +08:00
parent bf615de600
commit 425b7b9cfd
4 changed files with 91 additions and 59 deletions

View File

@ -7,7 +7,7 @@
},
{
"customPlaygroundType" : "local",
"playground" : "custom",
"playground" : "standard",
"type" : "uni-app:app-android"
}
]

View File

@ -2,14 +2,14 @@
"name" : "星汉物联",
"appid" : "__UNI__A21EF43",
"description" : "设备管控",
"versionName" : "1.0.8",
"versionName" : "1.0.7",
"versionCode" : "100",
"transformPx" : false,
/* 5+App */
"app-plus" : {
"compatible":{
"ignoreVersion":true
},
"compatible" : {
"ignoreVersion" : true
},
"usingComponents" : true,
"nvueStyleCompiler" : "uni-app",
"compilerVersion" : 3,

View File

@ -65,7 +65,7 @@
</view>
<view class="rightTxt">
<text class="bigTxt">主灯模式</text>
<text class="smallTxt">{{getMode}}</text>
<text class="smallTxt">{{getMode('main')}}</text>
</view>
</view>
<view class="mode marginLeft fleft" v-on:click.stop="ModeSetting('fu')">
@ -74,7 +74,7 @@
</view>
<view class="rightTxt">
<text class="bigTxt">辅灯模式</text>
<text class="smallTxt">泛光模式</text>
<text class="smallTxt">{{getMode('fu')}}</text>
</view>
</view>
<view class="mode fleft" v-on:click.stop="UploadOpenImg()">
@ -108,15 +108,18 @@
<view class="item">
<text class="lbl">单位</text>
<input class="value" v-model.trim="formData.textLines[0]" placeholder="请输入单位" placeholder-class="usrplace" />
<input class="value" v-model.trim="formData.textLines[0]" placeholder="请输入单位"
placeholder-class="usrplace" />
</view>
<view class="item">
<text class="lbl">部门</text>
<input class="value" v-model.trim="formData.textLines[1]" placeholder="请输入姓名" placeholder-class="usrplace" />
<input class="value" v-model.trim="formData.textLines[1]" placeholder="请输入姓名"
placeholder-class="usrplace" />
</view>
<view class="item">
<text class="lbl">姓名</text>
<input class="value" v-model.trim="formData.textLines[2]" placeholder="请输入职位" placeholder-class="usrplace" />
<input class="value" v-model.trim="formData.textLines[2]" placeholder="请输入职位"
placeholder-class="usrplace" />
</view>
</view>
@ -257,6 +260,7 @@
deviceId: '',
textLines: ['', '', ''],
mode: '',
light:null,
bleStatu: ''
},
inteval: 80,
@ -415,33 +419,48 @@
remark = '微弱';
}
},
getMode() {
},
methods: {
getMode(type) {
let txt = "关闭";
if (this.Status.BottomMenu.type == 'fu') {
return txt;
}
switch (this.formData.mode) {
switch (this.formData.light) {
case 0:
txt = "强光模式";
if (type == 'fu' && this.formData.mode == 'fu') {
txt = '泛光';
} else if (type == 'main' && this.formData.mode == 'main') {
txt = "强光";
}
break;
case 1:
txt = "弱光模式";
if (type == 'fu' && this.formData.mode == 'fu') {
txt = '强+泛光';
} else if (type == 'main' && this.formData.mode == 'main') {
txt = "弱光";
}
break;
case 2:
txt = "爆闪模式";
if (type == 'main' && this.formData.mode == 'main') {
txt = "爆闪";
}
break;
case 3:
if (type == 'main' && this.formData.mode == 'main') {
txt = "关闭";
}
break;
default:
txt = "关闭";
break;
}
return txt;
}
},
methods: {
},
calcTotalPackets(frames) {
if (!Array.isArray(frames) || frames.length === 0) {
return 0;
@ -570,7 +589,8 @@
if (!json) {
return;
}
console.log("收到设备数据:", json);
console.log("收到原始数据:", receive);
console.log("解析设备数据:", json);
let keys = Object.keys(json);
keys.forEach((key) => {
if (key in these.formData) {
@ -579,7 +599,7 @@
these.$set(these.formData, key, json[key]);
} else {
console.log(`字段 ${key} 不在 formData 中,跳过更新`);
}
}
});
// 强制触发视图更新,确保电量显示同步
@ -919,7 +939,7 @@
fail: (ex) => {
updateLoading(these, {
text : '视频文件上传失败了,请检查网络连接'
text: '视频文件上传失败了,请检查网络连接'
});
reject(ex);
@ -942,8 +962,8 @@
resolve(res.data);
return;
}else{
console.log("res.data=",res.data);
} else {
console.log("res.data=", res.data);
}
}
@ -1264,9 +1284,10 @@
},
ModeSetting: function(type) {
this.formData.mode = type;
let items = [];
let title = '';
switch (type) {
case "main":
title = '主灯模式';
@ -1305,12 +1326,16 @@
];
break;
}
this.Status.BottomMenu.menuItems = items;
this.Status.BottomMenu.title = title;
this.Status.BottomMenu.type = type;
this.Status.BottomMenu.show = true;
if(this.formData.mode != type){
this.Status.BottomMenu.activeIndex =null;
}
},
showMenu(flag) {
this.Status.BottomMenu.show = true;
@ -1320,8 +1345,8 @@
},
btnClick(item, index) {
if (this.Status.BottomMenu.activeIndex == -1) {
this.showToast('请选择模式');
if (parseInt(this.Status.BottomMenu.activeIndex) === NaN) {
uni.showToast('请选择模式');
return;
}
//发送指令给设备
@ -1386,7 +1411,8 @@
});
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30).then(() => {
this.formData.mode = mode;
this.formData.light = mode;
this.formData.mode = type
this.setBleFormData();
}).catch((ex) => {
these.showPop({
@ -1404,14 +1430,14 @@
},
handleItemClick(item, index) {
switch (this.Status.BottomMenu.type) {
case "main":
// switch (this.Status.BottomMenu.type) {
// case "main":
break;
case "fu":
// break;
// case "fu":
break;
}
// break;
// }
this.Status.BottomMenu.activeIndex = index;
},
@ -1569,7 +1595,7 @@
logicalDataView.setUint8(logicalPacketSize - 1, 0xFF);
// 4. 将逻辑大包分包发送
const CHUNK_SIZE = 20; // 每个物理包的大小
const CHUNK_SIZE = 500; // 每个物理包的大小
const totalChunks = Math.ceil(logicalPacketSize / CHUNK_SIZE);
updateLoading(these, {

View File

@ -415,37 +415,42 @@ class BleReceive {
if (bytes[0] == 0xFB && bytes[1] == 0x64 && bytes.length >= 8) {
try {
let staticLevelByte = bytes[2];
let getName = function(type) {
let getName = function(type,) {
let name = "";
switch (type) {
case 0x02:
// name = '弱光';
name=1;
break;
case 0x04:
name = '工作光';
break;
case 0x01:
// name = '强光';
name=0;
break;
case 0x03:
// name = '爆闪';
name=2;
case 0x02:
// name = '弱光';
name=1;
break;
case 0x00:
case 0x03:
// name = '爆闪';
name=2;
break;
case 0x04:
name = 0;//泛光
break;
case 0x0A:
name = 1;//强光&泛光
break;
default:
// name = '关闭';
name=3;
name=null;
break;
}
return name;
}
let staticLevelText = getName(staticLevelByte);
let staticLevelText = getName(bytes[2]);
// 解析照明档位
let lightingLevelByte = bytes[3];
let lightingLevelText = getName(lightingLevelByte);
// 解析照明档位
let lightingLevelText = getName(bytes[3]);
// 解析剩余电量
@ -470,8 +475,9 @@ class BleReceive {
let mm = Math.max(0, Math.min(100, bytes[7]));
lightingTime = HH + "小时" + mm + "分钟";
let formData = {};
formData.mode = staticLevelText;
formData.fuMode = lightingLevelText;
formData.mode = (bytes[2]===0x00 || bytes[2]===0x0B)?'fu':'main';
formData.light=formData.mode=='fu'?lightingLevelText:staticLevelText;
formData.battary = batteryLevel;
formData.statu = warn;
formData.xuhang = lightingTime;