完成7305,添加在详情页去绑定蓝牙设备

This commit is contained in:
liub
2025-09-17 15:21:20 +08:00
parent ed8f02fb39
commit da9a9f4874
19 changed files with 5311 additions and 1523 deletions

View File

@ -55,7 +55,7 @@
</view>
<view class="rightTxt">
<text class="bigTxt">主灯模式</text>
<text class="smallTxt">强光模式</text>
<text class="smallTxt">{{getMode}}</text>
</view>
</view>
<view class="mode marginLeft fleft" v-on:click.stop="ModeSetting('fu')">
@ -158,7 +158,7 @@
var these = null;
var BrighInteval = null;
var recei = null;
export default {
components: {
TextToHexV1
@ -308,6 +308,7 @@
// } else {
// link();
// }
console.log("6155");
ble.addReceiveCallback(these.bleValueNotify);
let eventChannel = this.getOpenerEventChannel();
@ -316,7 +317,7 @@
let device = data.data;
these.device = device;
console.log("收到父页面的参数:" + JSON.stringify(device));
let f = ble.data.LinkedList.find((v) => {
if (v.macAddress == device.deviceMac) {
console.log("找到设备了", v);
@ -328,12 +329,7 @@
if (!f) {
these.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
these.showBleUnConnect();
return;
}
let form = f.formData;
@ -381,6 +377,35 @@
if (this.formData.RSSI < -85 && this.formData.RSSI >= -100) {
remark = '微弱';
}
},
getMode() {
let txt = "关闭";
if (this.Status.BottomMenu.type == 'fu') {
return txt;
}
switch (this.formData.mode) {
case 0:
txt = "强光模式";
break;
case 1:
txt = "弱光模式";
break;
case 2:
txt = "爆闪模式";
break;
case 3:
txt = "关闭";
break;
default:
txt = "关闭";
break;
}
return txt;
}
},
methods: {
@ -394,12 +419,12 @@
return f;
},
bleValueNotify: function(receive, device, path) {
let str = recei.ReceiveData(receive, device, pagePath);
let str = recei.ReceiveData(receive, device, path);
console.log("处理接收到的数据:" + str);
return;
let data = recei.ReceiveData(receive, device, pagePath);
let data = recei.ReceiveData(receive, device, path);
let bytes = receive.bytes;
if (bytes[0] == 0xFB && bytes[1] == 0x64 && bytes.length >= 8) {
@ -504,16 +529,40 @@
}
});
},
showBleUnConnect() {
this.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
buttonText: '去连接',
okCallback: function() {
console.log("1111");
uni.navigateTo({
url: "/pages/common/addBLE/addEquip",
events: {
BindOver: function(data) {
console.log(data)
}
},
success: function(res) {
// 通过eventChannel向被打开页面传送数据
res.eventChannel.emit('detailData', {
data: these.device
})
},
fail(ex) {
console.log("跳转失败", ex);
}
})
}
});
},
checkImgUpload: function() {
let f = these.getDevice();
if (!f) {
these.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
these.showBleUnConnect();
return;
}
@ -595,8 +644,8 @@
these.showPop({
message: "上传成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
borderColor : '#BBE600',
buttonBgColor : '#BBE600'
borderColor: '#BBE600',
buttonBgColor: '#BBE600'
});
resolve();
@ -766,10 +815,10 @@
text: '强光',
icon: '/static/images/6155/DeviceDetail/qiang.png'
},
{
text: '工作光',
icon: '/static/images/6155/DeviceDetail/fan.png'
},
// {
// text: '工作光',
// icon: '/static/images/6155/DeviceDetail/fan.png'
// },
{
text: '弱光',
icon: '/static/images/6155/DeviceDetail/ruo.png'
@ -822,16 +871,11 @@
}
this.closeMenu();
},
setMode(mode, type) {
let dataValue = 0;
this.setBleFormData();
this.currentMode = mode;
switch (mode) {
case 0:
@ -842,25 +886,25 @@
dataValue = 0x01;
} else if (type == 'fu') {
dataValue = 0x0A;
dataValue = 0x04;
}
break;
case 1:
dataValue = 0x04;
break;
case 2:
dataValue = 0x02;
break;
case 3:
// case 2:
// dataValue = 0x02;
// break;
case 2:
dataValue = 0x03;
break;
case 4:
case 3:
dataValue = 0x0B;
break;
}
console.log("dataValue=", dataValue)
// console.log("dataValue=", dataValue)
// 构建数据包
var buffer = new ArrayBuffer(6);
var dataView = new DataView(buffer);
@ -876,12 +920,7 @@
// 发送数据
if (!f) {
these.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
these.showBleUnConnect();
return;
}
@ -890,7 +929,8 @@
});
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30).then(() => {
this.formData.mode = mode;
this.setBleFormData();
}).catch((ex) => {
these.showPop({
message: "发送失败," + ex.msg,
@ -934,38 +974,54 @@
},
HidePop: function() {
console.log("1111");
if (this.Status.Pop.clickEvt == 'SendUsr') {
}
if (this.Status.Pop.okCallback) {
this.Status.Pop.okCallback();
}
this.Status.Pop.showPop = false;
},
showPop: function(option) {
hideLoading(this);
let defaultCfg = {
showHeader: false,
headerTxt: "",
showHeader: false,
showCancel: false,
borderColor: '#BBE600',
buttonBgColor: '#BBE600',
okCallback: null,
cancelCallback: null,
popType: 'custom',
buttonText: '确定',
clickEvt: ''
};
if (!option) {
option = {
a: 1
};
}
let keys = Object.keys(option);
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
these.Status.Pop[key] = option[key];
this.Status.Pop[key] = option[key];
}
if (!option.borderColor) {
option.borderColor = '#BBE600';
option.buttonBgColor = '#BBE600';
keys = Object.keys(defaultCfg);
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
if (key in option) {
continue;
}
this.Status.Pop[key] = defaultCfg[key];
}
these.Status.Pop.showPop = true;
this.Status.Pop.showPop = true;
},
sendUsr() {
let f = this.getDevice();
if (!f) {
these.showPop({
text: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
these.showBleUnConnect()
return;
}
showLoading(these, {
@ -1119,19 +1175,19 @@
console.log("发送成功");
this.showPop({
message: "发送成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
borderColor : '#BBE600',
buttonBgColor : '#BBE600'
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
borderColor: '#BBE600',
buttonBgColor: '#BBE600'
});
let json = {
deviceId: these.device.id,
name: these.formData.textLines[2],
position: these.formData.textLines[0],
unitName: these.formData.textLines[1],
deviceId: these.device.id,
name: these.formData.textLines[1],
position: these.formData.textLines[0],
unitName: these.formData.textLines[2],
code: ""
};
usrApi.sendUsr(json)