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", "customPlaygroundType" : "local",
"playground" : "custom", "playground" : "standard",
"type" : "uni-app:app-android" "type" : "uni-app:app-android"
} }
] ]

View File

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

View File

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

View File

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