1
0
forked from dyf/APP
Files
APP/pages/6155/deviceDetail.vue

1463 lines
33 KiB
Vue
Raw Normal View History

2025-07-11 16:08:17 +08:00
<template>
<view class="content contentBg">
<view class="eq">
<view class="leftImg">
<image class="img" :src="formData.img" mode="aspectFit"></image>
</view>
<view class="rightTxt">
<view class="row">
<image class="img" src="/static/images/6155/DeviceDetail/battry.png" mode="aspectFit"></image>
<view class="txt">
<view class="bigTxt">{{formData.battary}}%</view>
<view class="smallTxt">电量</view>
</view>
</view>
<view class="row">
<image class="img" src="/static/images/6155/DeviceDetail/time.png" mode="aspectFit"></image>
<view class="txt">
<view class="bigTxt">{{formData.xuhang}}</view>
<view class="smallTxt">续航时间</view>
</view>
</view>
</view>
</view>
<view class="eqinfo">
<view class="item">
<text class="lbl">蓝牙名称</text>
2025-08-15 16:39:00 +08:00
<text class="value">{{formData.blename}}</text>
2025-07-11 16:08:17 +08:00
</view>
<view class="item">
2025-08-15 16:39:00 +08:00
<text class="lbl">设备名称</text>
<text class="value">{{formData.deviceName}}</text>
2025-07-11 16:08:17 +08:00
</view>
<view class="item">
<text class="lbl">设备状态</text>
<text class="value">{{formData.statu}}</text>
</view>
</view>
<view class="lamp">
<view class="title">
<text>灯光亮度</text>
<text>{{formData.liangDu}}%</text>
</view>
<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="sliderChange" class="custom-slider" />
</view>
</view>
<view class="lampMode">
<view class="mode fleft" v-on:click.stop="ModeSetting('main')">
<view class="leftImg">
<image class="img" src="/static/images/6155/DeviceDetail/mainLamp.png" mode="aspectFit"></image>
</view>
<view class="rightTxt">
<text class="bigTxt">主灯模式</text>
<text class="smallTxt">强光模式</text>
</view>
</view>
<view class="mode marginLeft fleft" v-on:click.stop="ModeSetting('fu')">
<view class="leftImg">
<image class="img" src="/static/images/6155/DeviceDetail/fuLamp.png" mode="aspectFit"></image>
</view>
<view class="rightTxt">
<text class="bigTxt">辅灯模式</text>
<text class="smallTxt">泛光模式</text>
</view>
</view>
<view class="mode fleft" v-on:click.stop="UploadOpenImg()">
<view class="leftImg">
<image class="img" src="/static/images/6155/DeviceDetail/open.png" mode="aspectFit"></image>
</view>
<view class="rightTxt">
<text class="bigTxt">开机画面</text>
<text class="smallTxt">上传</text>
</view>
</view>
<view class="clear"></view>
</view>
<view class="usrinfo">
<view>
<text class="usrtitle fleft">人员信息登记</text>
<view class="btnSend fright" v-on:click.stop="sendUsr">发送</view>
<view class="clear"></view>
2025-08-15 16:39:00 +08:00
<TextToHex class="TextToHex" ref="textToHex" :txts="formData.textLines" :bgColor="'#000000'"
:color="'#FFFFFF'" :fontSize="16" />
2025-07-11 16:08:17 +08:00
</view>
<view class="item">
<text class="lbl">单位</text>
2025-08-15 16:39:00 +08:00
<input class="value" v-model="formData.textLines[0]" placeholder="请输入单位" placeholder-class="usrplace" />
2025-07-11 16:08:17 +08:00
</view>
<view class="item">
2025-08-15 16:39:00 +08:00
<text class="lbl">部门</text>
<input class="value" v-model="formData.textLines[1]" placeholder="请输入姓名" placeholder-class="usrplace" />
2025-07-11 16:08:17 +08:00
</view>
<view class="item">
2025-08-15 16:39:00 +08:00
<text class="lbl">姓名</text>
<input class="value" v-model="formData.textLines[2]" placeholder="请输入职位" placeholder-class="usrplace" />
2025-07-11 16:08:17 +08:00
</view>
2025-08-15 16:39:00 +08:00
2025-07-11 16:08:17 +08:00
</view>
<view class="proinfo lamp">
<text class="title">产品信息</text>
<view class="itemcontent">
<view class="item" @click="proParam()">
<image class="img" src="/static/images/6155/DeviceDetail/param.png" mode="aspectFit"></image>
<text class="txt">产品参数</text>
</view>
<view class="item" @click="handRemark()">
<image class="img" src="/static/images/6155/DeviceDetail/remark.png" mode="aspectFit"></image>
<text class="txt">操作说明</text>
</view>
<view class="item" @click="handVideo()">
<image class="img" src="/static/images/6155/DeviceDetail/video.png" mode="aspectFit"></image>
<text class="txt">操作视频</text>
</view>
</view>
</view>
<!-- 弹窗通知 -->
<MessagePopup :visible="Status.Pop.showPop" :type="Status.Pop.popType" :bgColor="Status.Pop.bgColor"
:borderColor="Status.Pop.borderColor" :textColor="Status.Pop.textColor"
:buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor"
:iconUrl="Status.Pop.iconUrl" :message="Status.Pop.message" :buttonText="Status.Pop.buttonText"
@buttonClick="HidePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle"
v-model="Status.Pop.modelValue" />
<!-- 下方菜单 -->
<BottomSlideMenuPlus :config="Status.BottomMenu" @close="closeMenu" @itemClick="handleItemClick"
@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>
</view>
</view>
</BottomSlideMenuPlus>
2025-08-15 16:39:00 +08:00
<global-loading ref="loading" />
2025-07-11 16:08:17 +08:00
</view>
</template>
<script>
2025-08-07 08:48:02 +08:00
import TextToHexVue from '@/components/TextToHex/TextToHex.vue';
import bleTool from '@/utils/BleHelper.js';
2025-08-15 16:39:00 +08:00
import {
showLoading,
hideLoading,
updateLoading
} from '@/utils/loading.js'
2025-08-07 08:48:02 +08:00
var ble = null;
2025-08-15 16:39:00 +08:00
var these = null;
2025-07-11 16:08:17 +08:00
export default {
data() {
return {
Status: {
Pop: {
showPop: false, //是否显示弹窗
popType: 'custom',
2025-08-15 16:39:00 +08:00
textColor: '#ffffffde',
2025-07-11 16:08:17 +08:00
bgColor: '#383934bd',
borderColor: '#BBE600',
buttonBgColor: '#BBE600',
buttonTextColor: '#232323DE',
iconUrl: '',
message: '您确定要这样做吗?',
buttonText: '确定',
clickEvt: '',
visiblePrompt: false,
promptTitle: '设备名称',
modelValue: '',
visibleClose: false
},
BottomMenu: {
show: false,
showHeader: true,
menuItems: [{
text: '强光',
icon: '/static/images/6155/DeviceDetail/qiang.png'
},
{
text: '弱光',
icon: '/static/images/6155/DeviceDetail/ruo.png'
},
{
text: '爆闪',
icon: '/static/images/6155/DeviceDetail/shan.png'
}
],
activeIndex: -1,
bgColor: '#2a2a2a',
itemBgColor: '#3a3a3a',
textColor: '#ffffffde',
textAlign: 'flex-start',
title: '主灯模式',
showDivider: false,
dividerColor: '#00000000',
dividerThickness: '0rpx',
dividerMargin: '10rpx',
itemHeight: '80rpx',
type: '',
showBtn: true,
btnBgColor: "#bbe600",
btnText: "确定",
btnTextColor: "#232323de",
showMask: true,
maskBgColor: '#00000066',
showClose: false
}
},
formData: {
2025-08-15 16:39:00 +08:00
img: '',
battary: '',
xuhang: '',
deviceName: '',
RSSI: '',
statu: '正常',
liangDu: '100',
id: '',
deviceId: '',
textLines: ['我爱你', '中国', '五星红旗'],
2025-07-11 16:08:17 +08:00
mode: ''
},
2025-08-15 16:39:00 +08:00
2025-07-11 16:08:17 +08:00
}
},
2025-08-14 17:25:53 +08:00
onUnload() {
ble.removeReceiveCallback(this);
},
2025-07-11 16:08:17 +08:00
onLoad: function() {
2025-08-15 16:39:00 +08:00
these = this;
ble = bleTool.getBleTool();
ble.addReceiveCallback(these.bleValueNotify);
2025-07-11 16:08:17 +08:00
let eventChannel = this.getOpenerEventChannel();
2025-08-15 16:39:00 +08:00
eventChannel.on('detailData', function(data) {
2025-07-29 09:34:15 +08:00
2025-08-15 16:39:00 +08:00
let device = data.data;
console.log("收到父页面的参数:" + JSON.stringify(device));
let f = ble.data.LinkedList.find((v) => {
if (v.macAddress == device.deviceMac) {
console.log("找到设备了", v);
these.formData.deviceId = v.deviceId;
return true;
2025-08-07 08:48:02 +08:00
}
2025-08-15 16:39:00 +08:00
return false;
});
if (!f) {
2025-07-29 09:34:15 +08:00
2025-08-15 16:39:00 +08:00
these.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
2025-08-07 08:48:02 +08:00
});
2025-08-15 16:39:00 +08:00
return;
}
let form = f.formData;
if (form) {
let keys = Object.keys(form);
for (var i = keys.length; i >= 0; i--) {
let key = keys[i];
these.formData[key] = form[key];
2025-08-07 08:48:02 +08:00
}
}
2025-08-15 16:39:00 +08:00
these.formData.blename = f.name ? f.name : "Unname";
these.formData.deviceName = device.deviceName;
these.formData.img = device.devicePic;
these.formData.id = device.id;
these.formData.deviceId = f.deviceId;
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
these.setBleFormData();
});
2025-07-29 09:34:15 +08:00
2025-07-11 16:08:17 +08:00
},
onHide: function() {
},
onBackPress(e) {
2025-08-15 16:39:00 +08:00
ble.removeReceiveCallback();
2025-07-11 16:08:17 +08:00
},
computed: {
RSSIRemark: function() {
let remark = '极弱';
if (this.formData.RSSI <= 0 && this.formData.RSSI >= -30) {
remark = '强';
}
if (this.formData.RSSI < -30 && this.formData.RSSI >= -60) {
remark = '一般';
}
if (this.formData.RSSI < -60 && this.formData.RSSI >= -85) {
remark = '弱';
}
if (this.formData.RSSI < -85 && this.formData.RSSI >= -100) {
remark = '微弱';
}
}
},
methods: {
2025-07-29 09:34:15 +08:00
getDevice: function() {
2025-08-15 16:39:00 +08:00
console.log("LinkedList=", ble.data.LinkedList);
2025-08-18 16:33:06 +08:00
console.log("formData=", these.formData);
2025-08-07 08:48:02 +08:00
let f = ble.data.LinkedList.find((v) => {
2025-08-15 16:39:00 +08:00
return v.deviceId == these.formData.deviceId;
2025-07-29 09:34:15 +08:00
});
return f;
},
2025-08-15 16:39:00 +08:00
bleValueNotify: function(receive) {
console.log("处理接收到的数据:" + receive);
let bytes = receive.bytes;
if (bytes[0] == 0xFB && bytes[1] == 0x64 && bytes.length >= 8) {
try {
let staticLevelByte = bytes[2];
let getName = function(type) {
let name = "";
switch (type) {
case 0x02:
name = '弱光';
break;
case 0x04:
name = '工作光';
break;
case 0x01:
name = '强光';
break;
case 0x03:
name = '爆闪';
break;
case 0x00:
name = '关闭';
break;
}
return name;
}
let staticLevelText = getName(staticLevelByte);
// 解析照明档位
let lightingLevelByte = bytes[3];
let lightingLevelText = getName(lightingLevelByte);
// 解析剩余电量
let batteryLevelByte = bytes[4];
// 电量百分比范围检查
let batteryLevel = Math.max(0, Math.min(100, batteryLevelByte));
//充电状态
let warn = bytes[5];
if (warn == 0x00) {
warn = '未充电';
} else if (warn == 0x01) {
warn = '充电中';
}
// 解析剩余照明时间(第三和第四字节,小端序)
let lightingTime = "";
let HH = Math.max(0, Math.min(100, bytes[6]));
let mm = Math.max(0, Math.min(100, bytes[7]));
lightingTime = HH + "小时" + mm + "分钟";
this.formData.mode = staticLevelText;
this.formData.fuMode = lightingLevelText;
this.formData.battary = batteryLevel;
this.formData.statu = warn;
this.formData.xuhang = lightingTime;
this.setBleFormData();
} catch (error) {
console.log('数据解析错误:', error);
}
}
2025-07-11 16:08:17 +08:00
},
proParam: function() {
2025-07-29 09:34:15 +08:00
2025-08-15 16:39:00 +08:00
uni.navigateTo({
url: '/pages/common/productDes/index?id=' + this.formData.id,
success(ev) {
}
});
2025-07-11 16:08:17 +08:00
},
handRemark: function() {
2025-08-15 16:39:00 +08:00
uni.navigateTo({
url: '/pages/common/operatingInstruct/index?id=' + this.formData.id,
success(ev) {
}
});
2025-07-11 16:08:17 +08:00
},
handVideo: function() {
2025-08-15 16:39:00 +08:00
uni.navigateTo({
url: '/pages/common/operationVideo/index?id=' + this.formData.id,
success(ev) {
}
});
2025-07-11 16:08:17 +08:00
},
checkImgUpload: function() {
2025-08-15 16:39:00 +08:00
let f = these.getDevice();
if (!f) {
these.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
return;
}
2025-07-11 16:08:17 +08:00
// 处理像素数据并发送
var processAndSendImageData = function(pixels) {
return new Promise((resolve, reject) => {
// 创建RGB565格式的像素数据
2025-08-07 08:48:02 +08:00
const rgb565Data = ble.convertToRGB565(pixels);
2025-07-11 16:08:17 +08:00
// 分包发送
sendImagePackets(rgb565Data).then(resolve).catch(reject);
});
}
2025-08-15 16:39:00 +08:00
2025-07-11 16:08:17 +08:00
// 分包发送图片数据
var sendImagePackets = function(imageData) {
return new Promise((resolve, reject) => {
// 总数据包数
const totalPackets = 52;
let currentPacket = 1;
2025-08-15 16:39:00 +08:00
// 发送单个数据包
const sendNextPacket = () => {
if (currentPacket > totalPackets) {
hideLoading(these);
these.Status.BottomMenu.show = false;
2025-07-29 09:34:15 +08:00
2025-08-15 16:39:00 +08:00
these.showPop({
message: "上传成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png"
});
2025-07-29 09:34:15 +08:00
2025-08-15 16:39:00 +08:00
resolve();
return;
2025-07-11 16:08:17 +08:00
}
2025-07-29 09:34:15 +08:00
2025-08-15 16:39:00 +08:00
// 计算当前包的数据
let packetSize = 250;
if (currentPacket <= 51) {
packetSize = 250; // 前51个包每个500字节
} else {
packetSize = 50; // 最后一个包100字节
}
2025-07-29 09:34:15 +08:00
2025-08-15 16:39:00 +08:00
// 创建数据包
const startIndex = (currentPacket - 1) * packetSize;
const endIndex = Math.min(startIndex + packetSize, imageData
.length);
if (startIndex > endIndex) {
return;
}
const packetData = imageData.slice(startIndex,
endIndex); // imageData.subarray(startIndex, endIndex);
console.log("imageData.length=" + imageData.length +
",startIndex=" +
startIndex +
",endIndex=" + endIndex + ",数据包长度" + (endIndex -
startIndex) +
',packetData.length=' + packetData.length);
// 构建数据包
const bufferSize = 5 + packetData.length * 2; // 头部5字节 + 数据部分
const buffer = new ArrayBuffer(bufferSize);
const dataView = new DataView(buffer);
// 填充头部
dataView.setUint8(0, 0x55); // 帧头
dataView.setUint8(1, 0x02); // 帧类型:开机画面
dataView.setUint8(2, '0x' + currentPacket.toString(16).padStart(2,
'0')); // 包序号
// if(packetData.length==250)
// {
// dataView.setUint8(3, 0x01);
// dataView.setUint8(4, 0xFF);
// }
if (packetData.length == 250) {
dataView.setUint8(3, 0x01);
dataView.setUint8(4, 0xF4);
} else {
dataView.setUint8(3, 0x00);
dataView.setUint8(4, 0x64);
}
2025-07-29 09:34:15 +08:00
2025-08-15 16:39:00 +08:00
// 填充数据每个RGB565值占2字节
for (let i = 0; i < packetData.length; i++) {
dataView.setUint16(5 + i * 2, packetData[i], false); // 大端字节序
}
2025-07-11 16:08:17 +08:00
2025-08-15 16:39:00 +08:00
//发送数据包
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
30)
.then(() => {
console.log("发送一个包完成了");
2025-07-11 16:08:17 +08:00
2025-08-15 16:39:00 +08:00
updateLoading(these, {
text: "正在发送" + currentPacket + "/" +
totalPackets
})
currentPacket++;
2025-07-11 16:08:17 +08:00
2025-08-15 16:39:00 +08:00
setTimeout(sendNextPacket, 100);
}).catch(err => {
console.log("发送数据包失败了", err);
2025-07-11 16:08:17 +08:00
2025-08-15 16:39:00 +08:00
these.Status.BottomMenu.show = false;
these.showPop({
message: "发送数据包失败了" + err.msg,
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
2025-07-11 16:08:17 +08:00
2025-08-15 16:39:00 +08:00
hideLoading(these);
reject(err);
});
}
// 开始发送数据
sendNextPacket();
2025-07-29 09:34:15 +08:00
2025-07-11 16:08:17 +08:00
});
}
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album'],
success: function(res) {
uni.navigateTo({
url: "/pages/6155/ImgCrop",
events: {
ImgCutOver: function(data) {
2025-08-15 16:39:00 +08:00
showLoading(these, {
text: "正在发送0/52"
2025-07-11 16:08:17 +08:00
});
2025-08-15 16:39:00 +08:00
2025-07-11 16:08:17 +08:00
these.Status.BottomMenu.show = false;
setTimeout(function() {
2025-08-27 09:08:59 +08:00
processAndSendImageData(data.piexls).catch((ex) => {
2025-08-15 16:39:00 +08:00
console.log("出现异常", ex);
2025-07-11 16:08:17 +08:00
});
}, 0)
}
},
success(ev) {
ev.eventChannel.emit('checkImg', {
data: res.tempFiles[0].path
})
},
fail(ex) {
2025-07-29 09:34:15 +08:00
console.log("跳转页面失败" + JSON.stringify(ex));
2025-07-11 16:08:17 +08:00
}
});
}
});
},
UploadOpenImg: function() {
//上传开机画面
this.Status.BottomMenu.menuItems = [];
this.Status.BottomMenu.title = "上传开机画面";
this.Status.BottomMenu.type = "checkImg";
this.Status.BottomMenu.show = true;
},
ModeSetting: function(type) {
2025-08-15 16:39:00 +08:00
this.formData.mode = type;
2025-07-11 16:08:17 +08:00
let items = [];
let title = '';
switch (type) {
case "main":
title = '主灯模式';
2025-07-29 09:34:15 +08:00
items = [{
2025-07-11 16:08:17 +08:00
text: '强光',
icon: '/static/images/6155/DeviceDetail/qiang.png'
},
2025-08-15 16:39:00 +08:00
{
text: '工作光',
icon: '/static/images/6155/DeviceDetail/fan.png'
},
2025-07-11 16:08:17 +08:00
{
text: '弱光',
icon: '/static/images/6155/DeviceDetail/ruo.png'
},
{
text: '爆闪',
icon: '/static/images/6155/DeviceDetail/shan.png'
2025-08-15 16:39:00 +08:00
},
{
text: '关闭',
icon: '/static/images/6155/DeviceDetail/close.png'
2025-07-11 16:08:17 +08:00
}
];
break;
case "fu":
title = '辅灯模式';
items = [{
text: '泛光',
icon: '/static/images/6155/DeviceDetail/fan.png'
}];
break;
}
this.Status.BottomMenu.menuItems = items;
this.Status.BottomMenu.title = title;
this.Status.BottomMenu.type = type;
this.Status.BottomMenu.show = true;
},
showMenu(flag) {
this.Status.BottomMenu.show = true;
},
closeMenu() {
this.Status.BottomMenu.show = false;
},
btnClick(item, index) {
if (this.Status.BottomMenu.activeIndex == -1) {
this.showToast('请选择模式');
return;
}
//发送指令给设备
switch (this.Status.BottomMenu.type) {
case "main":
2025-08-15 16:39:00 +08:00
this.setMode(this.Status.BottomMenu.activeIndex, this.Status.BottomMenu.type);
2025-07-11 16:08:17 +08:00
break;
case "fu":
2025-08-15 16:39:00 +08:00
this.setMode(this.Status.BottomMenu.activeIndex, this.Status.BottomMenu.type);
2025-07-11 16:08:17 +08:00
break;
}
this.closeMenu();
},
2025-08-15 16:39:00 +08:00
setMode(mode, type) {
let dataValue = 0;
this.setBleFormData();
2025-07-11 16:08:17 +08:00
2025-08-15 16:39:00 +08:00
if (type == 'main') {
2025-07-11 16:08:17 +08:00
2025-08-15 16:39:00 +08:00
type = 0x04;
} else if (type == 'fu') {
type = 0x05;
}
2025-07-11 16:08:17 +08:00
this.currentMode = mode;
2025-08-15 16:39:00 +08:00
2025-07-11 16:08:17 +08:00
switch (mode) {
case 0:
dataValue = 0x01;
break;
case 1:
2025-08-15 16:39:00 +08:00
dataValue = 0x04;
2025-07-11 16:08:17 +08:00
break;
case 2:
2025-08-15 16:39:00 +08:00
dataValue = 0x02;
2025-07-11 16:08:17 +08:00
break;
2025-08-15 16:39:00 +08:00
case 3:
dataValue = 0x03;
2025-07-11 16:08:17 +08:00
break;
case 4:
2025-08-15 16:39:00 +08:00
dataValue = 0x00;
2025-07-11 16:08:17 +08:00
break;
2025-08-15 16:39:00 +08:00
2025-07-11 16:08:17 +08:00
}
// 构建数据包
2025-08-15 16:39:00 +08:00
var buffer = new ArrayBuffer(6);
var dataView = new DataView(buffer);
2025-07-11 16:08:17 +08:00
2025-08-15 16:39:00 +08:00
dataView.setUint8(0, 0xFA); // 帧头
dataView.setUint8(1, dataValue); // 帧类型
dataView.setUint8(2, 0x00); // 数据
dataView.setUint8(3, 0x01); // 数据
dataView.setUint8(4, 0x00); // 数据
dataView.setUint8(5, 0xFF); // 数据
2025-07-29 09:34:15 +08:00
let f = this.getDevice();
2025-07-11 16:08:17 +08:00
// 发送数据
2025-08-15 16:39:00 +08:00
if (!f) {
these.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
2025-08-07 08:48:02 +08:00
});
2025-08-15 16:39:00 +08:00
return;
2025-08-07 08:48:02 +08:00
}
2025-08-15 16:39:00 +08:00
showLoading(these, {
text: "请稍候..."
});
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30).then(() => {
}).catch((ex) => {
these.showPop({
message: "发送失败," + ex.msg,
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
}).finally(() => {
hideLoading(these);
});
2025-08-07 08:48:02 +08:00
2025-07-11 16:08:17 +08:00
},
handleItemClick(item, index) {
switch (this.Status.BottomMenu.type) {
case "main":
break;
case "fu":
break;
}
this.Status.BottomMenu.activeIndex = index;
2025-08-15 16:39:00 +08:00
},
setBleFormData() {
ble.data.LinkedList.find((v) => {
if (v.deviceId == these.formData.deviceId) {
v.formData = these.formData;
return true;
}
return false;
});
uni.setStorage({
key: ble.StorageKey,
data: ble.data.LinkedList
})
2025-07-11 16:08:17 +08:00
},
HidePop: function() {
if (this.Status.Pop.clickEvt == 'SendUsr') {
}
this.Status.Pop.showPop = false;
},
2025-08-15 16:39:00 +08:00
showPop: function(option) {
2025-07-11 16:08:17 +08:00
2025-08-15 16:39:00 +08:00
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];
}
if (!option.borderColor) {
option.borderColor = '#BBE600';
option.buttonBgColor = '#BBE600';
}
these.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",
});
return;
}
showLoading(these, {
text: "请稍候..."
});
this.setBleFormData();
let task = async () => {
var sendTxtPackge = (rgbdata, type, str) => {
2025-07-11 16:08:17 +08:00
2025-08-15 16:39:00 +08:00
var promise = new Promise((resolve, reject) => {
try {
2025-07-11 16:08:17 +08:00
2025-08-15 16:39:00 +08:00
let packetSize = rgbdata.length; //每包均分的数量
let mode = rgbdata.length % packetSize; //最后一包的数量
let cnt = parseInt(rgbdata.length / packetSize) + (mode > 0 ? 1 :
0); //总包数量
let curr = 1; //当前包序号
2025-07-11 16:08:17 +08:00
2025-08-15 16:39:00 +08:00
let sendNext = () => {
2025-07-29 09:34:15 +08:00
2025-08-15 16:39:00 +08:00
if (curr > cnt) {
resolve();
return;
}
2025-08-07 08:48:02 +08:00
2025-08-15 16:39:00 +08:00
let bufferSize = 261;
2025-08-07 08:48:02 +08:00
2025-08-15 16:39:00 +08:00
console.log("bufferSize=", bufferSize)
let buffer = new ArrayBuffer(bufferSize);
let dataView = new DataView(buffer);
let startIndex = (curr - 1) * packetSize;
2025-08-07 08:48:02 +08:00
2025-08-15 16:39:00 +08:00
let endIndex = Math.min(startIndex + packetSize, rgbdata
.length);
if (startIndex > endIndex) {
2025-08-07 08:48:02 +08:00
2025-08-15 16:39:00 +08:00
return;
}
2025-07-11 16:08:17 +08:00
2025-08-15 16:39:00 +08:00
let packetData = rgbdata.slice(startIndex,
endIndex); //取一片数据发送
let start = 0;
if (curr == 1) {
dataView.setUint8(0, 0xFA);
dataView.setUint8(1, type);
dataView.setUint8(2, 0x01);
dataView.setUint8(3, 0x00);
// dataView.setUint16(2, str.length, false);
start = 4;
2025-08-07 08:48:02 +08:00
}
2025-08-15 16:39:00 +08:00
for (let i = 0; i < packetData.length; i++) {
dataView.setUint8(start + i, packetData[i]);
}
dataView.setUint8(bufferSize - 1, 0xFF);
let inteval = parseInt(this.inteval ? this.inteval : 0);
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
.wirteCharactId, 30).then(() => {
curr++;
setTimeout(sendNext, inteval);
}).catch(err => {
if (err.code == '10007') {
setTimeout(sendNext, inteval);
} else {
reject(err);
}
});
}
sendNext();
} catch (ex) {
console.log("ex=", ex);
reject(ex);
2025-08-07 08:48:02 +08:00
}
2025-08-15 16:39:00 +08:00
});
2025-08-07 08:48:02 +08:00
2025-08-15 16:39:00 +08:00
return promise;
}
var result = await this.$refs.textToHex.drawAndGetPixels();
result = result.map(level1 => {
return level1.flat(Infinity);
2025-08-07 08:48:02 +08:00
});
2025-07-11 16:08:17 +08:00
2025-08-15 16:39:00 +08:00
let h3dic = [0x06, 0x07, 0x08];
let pros = [];
let flag = true;
for (var i = 0; i < result.length; i++) {
2025-07-11 16:08:17 +08:00
2025-08-15 16:39:00 +08:00
let str = this.formData.textLines[i];
2025-07-11 16:08:17 +08:00
2025-08-15 16:39:00 +08:00
if (str.length > 0) {
2025-08-07 08:48:02 +08:00
2025-08-15 16:39:00 +08:00
let width = str.length * 16;
var rgb = result[i];
2025-08-07 08:48:02 +08:00
2025-08-15 16:39:00 +08:00
try {
console.log("1111");
await sendTxtPackge(rgb, h3dic[i], str);
console.log("222222");
} catch (ex) {
flag = false;
console.log("33333");
break;
}
}
2025-08-07 08:48:02 +08:00
2025-08-15 16:39:00 +08:00
}
2025-08-07 08:48:02 +08:00
2025-08-15 16:39:00 +08:00
hideLoading(these);
if (flag) {
console.log("发送成功");
this.showPop( {
message: "发送成功"
});
} else {
this.showPop({
message: "出现异常发送失败",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
}
2025-08-07 08:48:02 +08:00
}
2025-07-11 16:08:17 +08:00
2025-08-15 16:39:00 +08:00
setTimeout(task, 0);
2025-07-11 16:08:17 +08:00
},
2025-08-15 16:39:00 +08:00
2025-07-11 16:08:17 +08:00
ack: function() {
2025-08-15 16:39:00 +08:00
2025-07-11 16:08:17 +08:00
let eventChannel = this.getOpenerEventChannel();
eventChannel.emit('ack', {
data: '我已收到了您的消息,谢谢。'
});
},
sliderChange: function(evt) {
this.formData.liangDu = evt.detail.value;
//给蓝牙设备发送信号更新亮度
setTimeout(() => {
this.sendBrightness();
2025-08-15 16:39:00 +08:00
this.setBleFormData();
2025-07-14 11:42:35 +08:00
}, 10);
2025-07-11 16:08:17 +08:00
},
sendBrightness: function() {
const buffer = new ArrayBuffer(6);
const dataView = new DataView(buffer);
let data = '0x' + parseInt(this.formData.liangDu).toString(16);
console.log("亮度:" + this.formData.liangDu + ',16进制:' + data);
dataView.setUint8(0, 0x55); // 帧头
dataView.setUint8(1, 0x01); // 帧类型:亮度调节
dataView.setUint8(2, 0x01); // 包序号
dataView.setUint8(3, 0x00); // 数据长度
dataView.setUint8(4, 0x01); // 数据长度
dataView.setUint8(5, data); // 数据
2025-07-29 09:34:15 +08:00
let f = this.getDevice();
if (f) {
// 发送数据
2025-07-11 16:08:17 +08:00
2025-08-07 08:48:02 +08:00
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30);
2025-07-29 09:34:15 +08:00
}
2025-07-11 16:08:17 +08:00
2025-07-14 11:42:35 +08:00
},
//获取当前设备状态
2025-07-29 09:34:15 +08:00
GetDeviceStatu: function() {
2025-07-14 11:42:35 +08:00
//数据头 命令码 数据 校验码
//JQOC 0B 00 9C41
2025-07-29 09:34:15 +08:00
2025-07-14 11:42:35 +08:00
//硬件响应
//数据头 命令码 主灯模式 副灯模式 亮度(%) 电量(%) 充电状态 校验码
//JQOC 0B 01 01 64 85 01 9C41
this.sendCmd('0x0B');
},
//设备重启
2025-07-29 09:34:15 +08:00
DeviceReStart: function() {
2025-07-14 11:42:35 +08:00
//数据头 命令码 数据 校验码
//JQOC 0C 01 9C412
this.sendCmd('0x0C');
},
//恢复出厂设置
2025-07-29 09:34:15 +08:00
DeviceReSet: function() {
2025-07-14 11:42:35 +08:00
//数据头 命令码 数据 校验码
//JQOC 0D 01 9C412
this.sendCmd('0x0D');
},
2025-07-29 09:34:15 +08:00
sendCmd: function(type, callback) {
2025-07-14 11:42:35 +08:00
//数据头 命令码 数据 校验码
2025-07-29 09:34:15 +08:00
2025-07-14 11:42:35 +08:00
const buffer = new ArrayBuffer(7);
const dataView = new DataView(buffer);
let data = '0x' + parseInt(this.formData.liangDu).toString(16);
console.log("亮度:" + this.formData.liangDu + ',16进制:' + data);
dataView.setUint8(0, 'JQOC'); // 帧头
dataView.setUint8(1, type); // 帧类型:亮度调节
dataView.setUint8(2, '0x01'); // 包序号
dataView.setUint8(3, '9C41'); // 数据长度
2025-07-29 09:34:15 +08:00
let f = this.getDevice();
if (f) {
// 发送数据
2025-08-07 08:48:02 +08:00
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30);
2025-07-29 09:34:15 +08:00
}
2025-07-11 16:08:17 +08:00
}
2025-07-29 09:34:15 +08:00
2025-07-11 16:08:17 +08:00
}
}
</script>
<style>
.content {
box-sizing: border-box;
width: 100%;
min-height: 100vh;
height: auto;
}
.contentBg {
background-color: #121212;
color: #ffffffde;
}
.fleft {
float: left;
}
.fright {
float: right;
}
.clear {
clear: both;
}
.displayNone {
display: none !important;
}
.p100 {
width: 100%;
height: 100%;
}
.center {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-content: center;
justify-content: center;
align-items: center;
}
.centerLeft {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-content: center;
justify-content: flex-start;
align-items: center;
}
.content {
padding: 30rpx;
box-sizing: border-box;
}
.eq {
width: 100%;
height: 250rpx;
border-radius: 8px;
background: rgba(26, 26, 26, 1);
box-sizing: border-box;
padding: 24rpx 28rpx;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-content: center;
justify-content: center;
align-items: center;
margin-bottom: 24rpx;
}
.eq .leftImg {
box-sizing: border-box;
padding: 36rpx;
border-radius: 16rpx;
background: rgba(42, 42, 42, 0.5);
}
.eq .leftImg,
.eq .rightTxt {
width: 50%;
height: 100%;
}
.eq .rightTxt {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
align-content: flex-start;
justify-content: space-evenly;
align-items: flex-start;
}
.eq .leftImg .img {
width: 100%;
height: 100%;
}
.eq .rightTxt .img {
width: 52rpx;
height: 52rpx;
}
.eq .rightTxt .row {
width: 100%;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-content: center;
justify-content: flex-start;
align-items: center;
box-sizing: border-box;
padding-left: 50rpx;
}
.eq .rightTxt .row .txt {
padding-left: 20rpx;
}
.eq .bigTxt {
color: rgba(255, 255, 255, 0.87);
2025-08-12 15:27:14 +08:00
font-family: "PingFang SC";
2025-07-11 16:08:17 +08:00
font-size: 28rpx;
font-weight: 400;
}
.eq .smallTxt {
color: rgba(255, 255, 255, 0.6);
2025-08-12 15:27:14 +08:00
font-family: "PingFang SC";
2025-07-11 16:08:17 +08:00
font-size: 24rpx;
font-weight: 400;
}
.eqinfo {
border-radius: 16rpx;
background: rgba(26, 26, 26, 1);
box-sizing: border-box;
padding: 14rpx 0rpx;
}
.eqinfo .item {
width: 100%;
height: 60rpx;
line-height: 60rpx;
padding: 0rpx 28rpx;
box-sizing: border-box;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-content: center;
justify-content: space-between;
align-items: center;
}
.eqinfo .lbl {
color: rgba(255, 255, 255, 0.87);
2025-08-12 15:27:14 +08:00
font-family: "PingFang SC";
2025-07-11 16:08:17 +08:00
font-size: 28rpx;
font-weight: 400;
letter-spacing: 0.07px;
text-align: left;
}
.eqinfo .value {
color: rgba(255, 255, 255, 0.6);
2025-08-12 15:27:14 +08:00
font-family: "PingFang SC";
2025-07-11 16:08:17 +08:00
font-size: 28rpx;
font-weight: 400;
letter-spacing: 0.07px;
text-align: left;
}
.lamp {
margin-top: 24rpx;
}
.lamp .title {
width: 100%;
height: 60rpx;
line-height: 60rpx;
padding: 0rpx 28rpx;
box-sizing: border-box;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-content: center;
justify-content: space-between;
align-items: center;
font-size: 28rpx;
}
.lampMode {
padding: 30rpx 0rpx;
width: 100%;
box-sizing: border-box;
}
.lampMode .mode {
width: calc(calc(100% - 34rpx) / 2);
border-radius: 8px;
margin-top: 20rpx;
background: rgba(26, 26, 26, 1);
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-content: center;
align-items: center;
justify-content: flex-start;
padding: 30rpx;
box-sizing: border-box;
}
.mode.marginLeft {
margin-left: 34rpx !important;
}
.mode .leftImg .img {
width: 70rpx;
height: 70rpx;
}
.mode .rightTxt {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
align-content: flex-start;
justify-content: center;
align-items: flex-start;
padding-left: 20rpx;
}
.mode .bigTxt {
color: rgba(255, 255, 255, 0.87);
2025-08-12 15:27:14 +08:00
font-family: "PingFang SC";
2025-07-11 16:08:17 +08:00
font-size: 28rpx;
font-weight: 400;
letter-spacing: 0.07px;
}
.mode .smallTxt {
color: rgba(255, 255, 255, 0.6);
2025-08-12 15:27:14 +08:00
font-family: "PingFang SC";
2025-07-11 16:08:17 +08:00
font-size: 24rpx;
font-weight: 400;
letter-spacing: 0.07px;
}
.usrinfo {
border-radius: 8px;
width: 100%;
box-sizing: border-box;
padding: 24rpx 28rpx;
background: rgba(26, 26, 26, 1);
}
.usrtitle {
color: rgba(255, 255, 255, 0.87);
2025-08-12 15:27:14 +08:00
font-family: "PingFang SC";
2025-07-11 16:08:17 +08:00
font-size: 28rpx;
font-weight: 400;
height: 40rpx;
line-height: 40rpx;
letter-spacing: 0.07px;
}
.usrinfo .btnSend {
2025-08-15 16:39:00 +08:00
line-height: 65rpx;
2025-07-11 16:08:17 +08:00
border-radius: 8px;
2025-08-15 16:39:00 +08:00
width: 120rpx;
height: 65rpx;
2025-07-11 16:08:17 +08:00
color: rgba(35, 35, 35, 0.87);
2025-08-12 15:27:14 +08:00
font-family: "PingFang SC";
2025-07-11 16:08:17 +08:00
font-size: 20rpx;
font-weight: 400;
letter-spacing: 0.07px;
text-align: center;
background-color: #BBE600;
}
.usrinfo .item {
border-radius: 8px;
width: 100%;
box-sizing: border-box;
line-height: 90rpx;
height: 90rpx;
background: rgba(42, 42, 42, 1);
margin-top: 24rpx;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-content: center;
justify-content: flex-start;
align-items: center;
}
.usrinfo .lbl {
width: 120rpx;
height: 100%;
padding-left: 24rpx;
box-sizing: border-box;
text-align: right;
color: rgba(255, 255, 255, 0.87);
2025-08-12 15:27:14 +08:00
font-family: "PingFang SC";
2025-07-11 16:08:17 +08:00
font-size: 28rpx;
font-weight: 400;
letter-spacing: 0.07px;
}
.usrinfo .value {
width: calc(100% - 120rpx);
height: 100%;
}
.usrinfo .value .uni-input-input {
color: rgba(255, 255, 255, 0.87);
2025-08-12 15:27:14 +08:00
font-family: "PingFang SC";
2025-07-11 16:08:17 +08:00
font-size: 28rpx;
font-weight: 400;
letter-spacing: 0.07px;
text-align: left;
}
.usrplace {
color: rgba(255, 255, 255, 0.4);
2025-08-12 15:27:14 +08:00
font-family: "PingFang SC";
2025-07-11 16:08:17 +08:00
font-size: 28rpx;
font-weight: 400;
letter-spacing: 0.07px;
text-align: left;
}
.proinfo .itemcontent {
display: flex;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-content: center;
justify-content: space-evenly;
}
.proinfo .item {
width: 180rpx;
height: 180rpx;
box-sizing: border-box;
padding: 40rpx;
border-radius: 16rpx;
background: rgba(26, 26, 26, 1);
display: flex;
flex-direction: column;
flex-wrap: nowrap;
align-content: center;
justify-content: center;
align-items: center;
}
.proinfo .item .img {
width: 50rpx;
height: 50rpx;
}
.proinfo .item .txt {
color: rgba(255, 255, 255, 0.6);
2025-08-12 15:27:14 +08:00
font-family: "PingFang SC";
2025-07-11 16:08:17 +08:00
font-size: 24rpx;
font-weight: 400;
margin-top: 20rpx;
letter-spacing: 0.07px;
text-align: left;
}
.slider-container {
padding: 0px;
}
.addIco {
width: 100%;
height: 360rpx;
display: flex;
flex-wrap: nowrap;
flex-direction: row;
align-content: center;
justify-content: center;
align-items: center;
}
.icoContent {
width: 240rpx;
height: 240rpx;
border-radius: 8rpx;
background: rgba(58, 58, 58, 1);
}
.icoContent .img {
width: 70rpx;
height: 70rpx;
}
2025-08-15 16:39:00 +08:00
2025-08-07 08:48:02 +08:00
.TextToHex {
position: fixed;
top: -99999rpx;
left: -99999rpx;
visibility: hidden;
}
2025-07-11 16:08:17 +08:00
</style>