Files
APP/pages/6155/deviceDetail.vue

2181 lines
53 KiB
Vue
Raw Normal View History

2025-07-11 16:08:17 +08:00
<template>
<view class="content contentBg">
<view class="eq">
2025-11-07 11:57:35 +08:00
<view class="leftImg" @click.stop="previewImg(device.devicePic?device.devicePic:formData.img)">
<image class="img" :src="device.devicePic?device.devicePic:formData.img" mode="aspectFit"></image>
2025-11-20 16:40:14 +08:00
2025-07-11 16:08:17 +08:00
</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">
2025-11-20 16:40:14 +08:00
2025-07-11 16:08:17 +08:00
<view class="item">
2025-08-27 11:06:49 +08:00
<text class="lbl">设备名称</text>
<text class="value">{{device.deviceName}}</text>
2025-07-11 16:08:17 +08:00
</view>
2025-11-07 11:57:35 +08:00
<view class="item">
2025-11-20 16:40:14 +08:00
<text class="lbl">Mac地址</text>
<text class="value">{{device.deviceMac}}</text>
</view>
2025-07-11 16:08:17 +08:00
<view class="item">
<text class="lbl">设备状态</text>
2025-07-11 16:08:17 +08:00
<text class="value">{{formData.statu}}</text>
</view>
<view class="item">
<text class="lbl">蓝牙名称</text>
<text class="value">{{device.bluetoothName}}</text>
</view>
<view class="item">
<text class="lbl">蓝牙状态</text>
<text class="value" :class="formData.bleStatu?'green':'red'">{{formData.bleStatu?'已连接':'未连接'}}</text>
</view>
2025-07-11 16:08:17 +08:00
</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">{{getMode('main')}}</text>
2025-07-11 16:08:17 +08:00
</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">{{getMode('fu')}}</text>
2025-07-11 16:08:17 +08:00
</view>
</view>
2025-11-21 18:47:20 +08:00
<view class="mode fleft" v-on:click.stop="UploadOpenImg()">
2025-07-11 16:08:17 +08:00
<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>
2025-11-21 18:47:20 +08:00
</view>
<view class="mode marginLeft fleft" v-on:click.stop="UploadOpenVideo()">
2025-11-20 16:40:14 +08:00
<view class="leftImg">
<image class="img" src="/static/images/common/video.png" mode="aspectFit"></image>
</view>
<view class="rightTxt">
<text class="bigTxt">开机视频</text>
<text class="smallTxt">上传</text>
</view>
</view>
2025-07-11 16:08:17 +08:00
<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-09-15 11:55:44 +08:00
<TextToHexV1 class="TextToHex" ref="textToHex" :txts="formData.textLines" :bgColor="'#FFFFFF'"
:color="'#000000'" :fontSize="14" />
2025-07-11 16:08:17 +08:00
</view>
<view class="item">
<text class="lbl">单位</text>
<input class="value" v-model.trim="formData.textLines[0]" placeholder="请输入单位"
placeholder-class="usrplace" />
2025-07-11 16:08:17 +08:00
</view>
<view class="item">
2025-08-27 11:06:49 +08:00
<text class="lbl">部门</text>
<input class="value" v-model.trim="formData.textLines[1]" placeholder="请输入姓名"
placeholder-class="usrplace" />
2025-07-11 16:08:17 +08:00
</view>
<view class="item">
2025-08-27 11:06:49 +08:00
<text class="lbl">姓名</text>
<input class="value" v-model.trim="formData.textLines[2]" placeholder="请输入职位"
placeholder-class="usrplace" />
2025-07-11 16:08:17 +08:00
</view>
2025-08-27 11:06:49 +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" @closePop="closePop" :visiblePrompt="Status.Pop.visiblePrompt"
:promptTitle="Status.Pop.promptTitle" v-model="Status.Pop.modelValue" />
2025-07-11 16:08:17 +08:00
<!-- 下方菜单 -->
<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-27 11:06:49 +08:00
<global-loading ref="loading" />
2025-07-11 16:08:17 +08:00
</view>
</template>
<script>
2025-09-15 11:55:44 +08:00
import TextToHexV1 from '@/components/TextToHex/TextToHexV1.vue';
2025-08-27 11:06:49 +08:00
import bleTool from '@/utils/BleHelper.js';
import usrApi from '@/api/670/HBY670.js'
2025-08-27 11:06:49 +08:00
import {
showLoading,
hideLoading,
updateLoading
} from '@/utils/loading.js'
import BleReceive from '@/utils/BleReceive';
2025-11-20 16:40:14 +08:00
import {
baseURL
} from '@/utils/request.js';
var pagePath = "/pages/6155/deviceDetail";
2025-08-27 11:06:49 +08:00
var ble = null;
var these = null;
2025-09-15 11:55:44 +08:00
var BrighInteval = null;
var recei = null;
2025-07-11 16:08:17 +08:00
export default {
2025-09-15 11:55:44 +08:00
components: {
TextToHexV1
2025-09-15 11:55:44 +08:00
},
2025-07-11 16:08:17 +08:00
data() {
return {
Status: {
pageHide: false,
2025-07-11 16:08:17 +08:00
Pop: {
showPop: false, //是否显示弹窗
popType: 'custom',
2025-08-27 11:06:49 +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,
okCallback: null
2025-07-11 16:08:17 +08:00
},
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-11-07 11:57:35 +08:00
img: '/static/images/common/HBY6155.png',
2025-08-27 11:06:49 +08:00
battary: '',
xuhang: '',
deviceName: '',
RSSI: '',
statu: '正常',
liangDu: '100',
id: '',
deviceId: '',
2025-09-15 11:55:44 +08:00
textLines: ['', '', ''],
mode: '',
light:null,
bleStatu: ''
2025-07-11 16:08:17 +08:00
},
2025-11-20 16:40:14 +08:00
inteval: 80,
device: {
id: "",
deviceName: "",
deviceImei: "",
deviceMac: "",
communicationMode: 0,
devicePic: "",
typeName: "",
bluetoothName: null,
deviceStatus: null,
bindingTime: "",
onlineStatus: 0,
battery: "0",
latitude: null,
longitude: null,
alarmStatus: null,
detailPageUrl: "/pages/6155/deviceDetail",
showConfirm: false
}
2025-08-27 11:06:49 +08:00
2025-07-11 16:08:17 +08:00
}
},
2025-08-27 11:06:49 +08:00
onUnload() {
ble.removeAllCallback(pagePath);
2025-08-27 11:06:49 +08:00
},
2025-07-11 16:08:17 +08:00
onLoad: function() {
2025-08-27 11:06:49 +08:00
these = this;
recei = BleReceive.getBleReceive();
2025-08-27 11:06:49 +08:00
ble = bleTool.getBleTool();
2025-09-15 11:55:44 +08:00
// let bleName = 'FB_Site_UART'; //JQZM-EF4651 FB_Site_UART
// let f = ble.data.LinkedList.find((v) => {
// if (v.name == bleName) {
// console.log("找到设备了", v);
// these.formData.deviceId = v.deviceId;
// return true;
// }
// return false;
// });
// let link = () => {
// if (bleName == 'FB_Site_UART') {
// ble.LinkBlue(f.deviceId, '0000AE30-0000-1000-8000-00805F9B34FB',
// '0000AE03-0000-1000-8000-00805F9B34FB', '0000AE02-0000-1000-8000-00805F9B34FB');
// } else {
// ble.LinkBlue(f.deviceId, '0000FFE0-0000-1000-8000-00805F9B34FB',
// '0000FFE1-0000-1000-8000-00805F9B34FB', '0000FFE2-0000-1000-8000-00805F9B34FB');
// }
// }
// if (!f) {
// ble.addDeviceFound((res) => {
// // console.log("发现新设备", res);
// f = res.devices.find((v) => {
// return v.name == bleName;
// });
// if (f) {
// console.log("找到目标设备了", f);
// these.formData.deviceId = f.deviceId;
// link();
// ble.StopSearch();
// }
// });
// ble.StartSearch();
// } else {
// link();
// }
console.log("6155");
ble.addReceiveCallback(these.bleValueNotify, pagePath);
ble.addStateBreakCallback(these.bleStateBreak, pagePath);
ble.addStateRecoveryCallback(these.bleStateRecovry, pagePath);
ble.addDisposeCallback(these.deviceDispose, pagePath);
ble.addRecoveryCallback(these.deviceRecovry, pagePath);
2025-07-11 16:08:17 +08:00
let eventChannel = this.getOpenerEventChannel();
eventChannel.on('detailData', function(data) {
2025-08-27 11:06:49 +08:00
let device = data.data;
these.device = device;
2025-08-27 11:06:49 +08:00
let f = ble.data.LinkedList.find((v) => {
if (v.macAddress == device.deviceMac) {
2025-08-27 11:06:49 +08:00
console.log("找到设备了", v);
these.formData.deviceId = v.deviceId;
return true;
}
return false;
});
if (!f) {
2025-07-11 16:08:17 +08:00
these.getDetail();
these.showBleUnConnect();
2025-08-27 11:06:49 +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];
}
}
these.formData.blename = f.name ? f.name : "Unname";
these.formData.deviceName = device.deviceName;
2025-11-20 16:40:14 +08:00
2025-08-27 11:06:49 +08:00
these.formData.id = device.id;
these.formData.deviceId = f.deviceId;
these.formData.bleStatu = false;
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
these.formData.bleStatu = true;
});
2025-08-27 11:06:49 +08:00
these.setBleFormData();
these.getDetail();
2025-07-11 16:08:17 +08:00
2025-08-27 11:06:49 +08:00
});
2025-07-11 16:08:17 +08:00
2025-08-27 11:06:49 +08:00
},
onHide: function() {
this.Status.pageHide = true;
},
onShow() {
this.Status.pageHide = false;
2025-08-27 11:06:49 +08:00
},
onBackPress(e) {
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: {
getMode(type) {
let txt = "关闭";
switch (this.formData.light) {
case 0:
if (type == 'fu' && this.formData.mode == 'fu') {
txt = '泛光';
} else if (type == 'main' && this.formData.mode == 'main') {
txt = "强光";
}
break;
case 1:
if (type == 'fu' && this.formData.mode == 'fu') {
txt = '强+泛光';
} else if (type == 'main' && this.formData.mode == 'main') {
txt = "弱光";
}
break;
case 2:
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;
},
2025-11-20 17:51:26 +08:00
calcTotalPackets(frames) {
if (!Array.isArray(frames) || frames.length === 0) {
return 0;
}
return frames.reduce((frameSum, frame) => {
if (!Array.isArray(frame)) {
return frameSum;
}
const packSum = frame.reduce((packAcc, pack) => {
if (!Array.isArray(pack)) {
return packAcc;
}
return packAcc + pack.length;
}, 0);
return frameSum + packSum;
}, 0);
},
toByteValue(value) {
if (typeof value === 'number') {
return value;
}
if (typeof value === 'string') {
if (value.startsWith('0x') || value.startsWith('0X')) {
return parseInt(value, 16);
}
return parseInt(`0x${value}`, 16);
}
return 0;
},
deviceRecovry(res) {
if (this.Status.pageHide) {
return;
}
if (res.deviceId == these.formData.deviceId) {
this.formData.bleStatu = true;
setTimeout(() => {
hideLoading(these, 1000);
});
uni.showToast({
icon: 'success',
title: '蓝牙连接成功'
});
}
},
deviceDispose(res) {
if (this.Status.pageHide) {
return;
}
if (res.deviceId == these.formData.deviceId) {
this.formData.bleStatu = false;
setTimeout(() => {
hideLoading(these, 1000);
});
uni.showToast({
icon: 'fail',
title: '蓝牙连接已断开'
});
}
},
bleStateBreak() {
if (this.Status.pageHide) {
return;
}
//蓝牙适配器不可用
this.formData.bleStatu = false;
uni.showToast({
icon: 'fail',
title: '蓝牙已不可用'
})
hideLoading(this);
},
bleStateRecovry() {
console.log("蓝牙可用");
if (this.Status.pageHide) {
return;
}
console.log("蓝牙可用");
//蓝牙适配器再次可用,尝试恢复连接
showLoading(this, {
text: "蓝牙恢复可用,正在连接设备"
});
ble.LinkBlue(these.formData.deviceId).then(() => {
these.formData.bleStatu = true;
updateLoading(these, {
text: '连接成功'
});
}).catch(ex => {
updateLoading(these, {
text: ex.msg
})
}).finally(() => {
setTimeout(() => {
hideLoading(these);
}, 1000);
});
},
previewImg(img) {
if (!img) {
return;
}
uni.previewImage({
urls: [img]
})
},
2025-08-27 11:06:49 +08:00
getDevice: function() {
2025-09-15 11:55:44 +08:00
// console.log("LinkedList=", ble.data.LinkedList);
// console.log("formData=", these.formData);
2025-08-27 11:06:49 +08:00
let f = ble.data.LinkedList.find((v) => {
return v.macAddress == these.device.deviceMac;
2025-08-27 11:06:49 +08:00
});
return f;
},
bleValueNotify: function(receive, device, path, recArr) {
if (receive.deviceId !== this.formData.deviceId) {
return;
}
if (this.Status.pageHide) {
return;
}
let json = recei.ReceiveData(receive, device, path, recArr);
if (!json) {
return;
}
console.log("收到原始数据:", receive);
console.log("解析设备数据:", json);
let keys = Object.keys(json);
keys.forEach((key) => {
if (key in these.formData) {
2025-11-21 11:07:10 +08:00
// 确保响应式更新
// console.log(`更新字段 ${key}: ${these.formData[key]} -> ${json[key]}`);
2025-11-21 11:07:10 +08:00
these.$set(these.formData, key, json[key]);
} else {
console.log(`字段 ${key} 不在 formData 中,跳过更新`);
}
});
2025-11-21 16:12:55 +08:00
2025-11-21 11:07:10 +08:00
// 强制触发视图更新,确保电量显示同步
these.$forceUpdate();
// console.log("更新后的电量:", these.formData.battary);
if (this.formData.battary <= 20) {
this.showPop({
message: "设备电量低",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
2025-08-27 11:06:49 +08:00
}
2025-07-11 16:08:17 +08:00
},
2025-07-11 16:08:17 +08:00
proParam: function() {
2025-08-27 11:06:49 +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-27 11:06:49 +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-27 11:06:49 +08:00
uni.navigateTo({
url: '/pages/common/operationVideo/index?id=' + this.formData.id,
success(ev) {
}
});
2025-07-11 16:08:17 +08:00
},
showBleUnConnect() {
this.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
buttonText: '去连接',
buttonTextColor: '#232323de',
okCallback: function() {
// console.log("1111");
uni.navigateTo({
url: "/pages/common/addBLE/addEquip",
events: {
BindOver: function(data) {
console.log(data)
these.formData.bleStatu = true;
}
},
success: function(res) {
// 通过eventChannel向被打开页面传送数据
res.eventChannel.emit('detailData', {
data: these.device
})
},
fail(ex) {
console.log("跳转失败", ex);
}
})
}
});
},
2025-07-11 16:08:17 +08:00
checkImgUpload: function() {
2025-08-27 11:06:49 +08:00
let f = these.getDevice();
if (!f) {
these.showBleUnConnect();
2025-08-27 11:06:49 +08:00
return;
}
2025-07-11 16:08:17 +08:00
// 处理像素数据并发送
var processAndSendImageData = function(pixels) {
return new Promise((resolve, reject) => {
// 创建RGB565格式的像素数据
2025-11-14 17:28:20 +08:00
// console.log("pixels=",pixels);
2025-09-15 11:55:44 +08:00
const arr = ble.convertToRGB565(pixels, 'bgr');
2025-11-20 16:40:14 +08:00
2025-09-15 11:55:44 +08:00
var list = [];
let index = 0; // 用于追踪arr的当前位置
2025-11-14 17:28:20 +08:00
let packetSize = 3200;
let cSize = 200;
2025-09-15 11:55:44 +08:00
// 外层循环7个主要元素i从1到7
2025-11-14 17:28:20 +08:00
for (let i = 1; i < 9; i++) {
2025-09-15 11:55:44 +08:00
let secondLevel = [];
let secondCnt = 0;
2025-09-15 11:55:44 +08:00
// 中层循环每个主要元素包含9个子数组j从1到9
2025-11-14 17:28:20 +08:00
for (let j = 1; j < 9; j++) {
2025-09-15 11:55:44 +08:00
// 确定当前子数组的长度前8个是254第9个是64
2025-11-20 16:40:14 +08:00
2025-09-15 11:55:44 +08:00
let thirdLevel = [];
2025-11-20 16:40:14 +08:00
2025-09-15 11:55:44 +08:00
// 从arr中提取相应数量的元素
for (let k = 0; k < cSize && index < arr.length; k++) {
2025-11-20 16:40:14 +08:00
if (secondCnt == packetSize) {
2025-09-15 11:55:44 +08:00
break;
}
thirdLevel.push(arr[index]);
secondCnt++;
index++;
}
2025-11-20 16:40:14 +08:00
2025-09-15 11:55:44 +08:00
secondLevel.push(thirdLevel);
}
list.push(secondLevel);
}
2025-11-20 16:40:14 +08:00
console.log("list=", list);
2025-11-20 16:40:14 +08:00
let length = 0;
2025-09-15 11:55:44 +08:00
for (let i = 0; i < list.length; i++) {
const item = list[i];
let clength = 0;
for (let j = 0; j < item.length; j++) {
const element = item[j];
console.log("第" + i + "包,第" + j + "小包,长度:" + element.length)
length += element.length;
clength += element.length;
2025-11-20 16:40:14 +08:00
}
2025-09-15 11:55:44 +08:00
}
2025-07-11 16:08:17 +08:00
// 分包发送
2025-09-15 11:55:44 +08:00
sendImagePackets(list).then(resolve).catch(reject);
2025-07-11 16:08:17 +08:00
});
}
// 分包发送图片数据
var sendImagePackets = function(imageData) {
return new Promise((resolve, reject) => {
// 总数据包数
2025-11-14 17:28:20 +08:00
const totalPackets = 8;
2025-07-11 16:08:17 +08:00
let currentPacket = 1;
2025-09-15 11:55:44 +08:00
let childPacket = 1;
2025-11-14 17:28:20 +08:00
let totalChildPacket = 8;
2025-11-20 16:40:14 +08:00
2025-08-27 11:06:49 +08:00
// 发送单个数据包
const sendNextPacket = () => {
if (currentPacket > totalPackets) {
2025-11-20 16:40:14 +08:00
updateLoading(these, {
text: '发送完成,等待设备30秒'
});
setTimeout(() => {
2025-09-15 11:55:44 +08:00
hideLoading(these);
these.Status.BottomMenu.show = false;
2025-11-20 16:40:14 +08:00
2025-09-15 11:55:44 +08:00
these.showPop({
message: "上传成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
borderColor: '#BBE600',
buttonBgColor: '#BBE600'
2025-09-15 11:55:44 +08:00
});
2025-11-20 16:40:14 +08:00
2025-09-15 11:55:44 +08:00
resolve();
2025-11-14 17:28:20 +08:00
}, 0)
2025-11-20 16:40:14 +08:00
2025-08-27 11:06:49 +08:00
return;
}
2025-11-20 16:40:14 +08:00
var packetData = imageData[currentPacket - 1][childPacket - 1];
2025-11-14 17:28:20 +08:00
console.log("childPacket=", childPacket);
console.log("packetData=", packetData);
let start = 0;
let bufferSize = packetData.length * 2;
2025-11-20 16:40:14 +08:00
if (childPacket == 1) {
bufferSize = bufferSize + 8
start = 8;
2025-09-15 11:55:44 +08:00
}
2025-11-14 17:28:20 +08:00
if (childPacket == 8) { //|| (currentPacket==7 && childPacket==3
bufferSize = bufferSize + 1
2025-09-15 11:55:44 +08:00
}
2025-11-20 16:40:14 +08:00
2025-11-21 18:47:20 +08:00
//FA 09 0C 84 FE 09 00 [01~08] + 3200字节 +FF 数据格式
2025-09-15 11:55:44 +08:00
var buffer = new ArrayBuffer(bufferSize);
var dataView = new DataView(buffer);
if (childPacket == 1) {
2025-09-15 11:55:44 +08:00
dataView.setUint8(0, 0xFA); // 帧头
dataView.setUint8(1, 0x09); // 帧头
2025-11-14 17:28:20 +08:00
dataView.setUint8(2, 0x0C); // 帧头
dataView.setUint8(3, 0x84); // 帧头
2025-11-21 18:47:20 +08:00
dataView.setUint8(4, 0xFE); // 帧头
2025-11-14 17:28:20 +08:00
dataView.setUint8(5, 0x09);
dataView.setUint8(6, 0x00); // 帧头
dataView.setUint8(7, currentPacket); //包序号
2025-08-27 11:06:49 +08:00
}
2025-11-20 16:40:14 +08:00
2025-08-27 11:06:49 +08:00
for (let i = 0; i < packetData.length; i++) {
2025-09-15 11:55:44 +08:00
dataView.setUint16(start + i * 2, packetData[i], false); //本包数据,大端字节序
}
console.log("packetData.length=", packetData.length);
console.log("bufferSize=", bufferSize)
2025-11-14 17:28:20 +08:00
if (childPacket == 8) { // || (currentPacket==7 && childPacket==3
dataView.setUint8(bufferSize - 1, 0xFF);
2025-08-27 11:06:49 +08:00
}
2025-11-20 16:40:14 +08:00
2025-08-27 11:06:49 +08:00
//发送数据包
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
30)
.then(() => {
2025-11-20 16:40:14 +08:00
2025-09-15 11:55:44 +08:00
let curr = childPacket + (currentPacket - 1) *
totalChildPacket;
console.log("第" + currentPacket + "大包,第" + childPacket +
"小包发送完成,总计:" + curr);
2025-08-27 11:06:49 +08:00
updateLoading(these, {
2025-11-14 17:28:20 +08:00
text: "正在发送" + curr + "/64"
2025-11-20 16:40:14 +08:00
2025-08-27 11:06:49 +08:00
})
2025-11-14 17:28:20 +08:00
if (childPacket == 8) {
2025-09-15 11:55:44 +08:00
currentPacket++;
childPacket = 1;
} else {
childPacket++;
}
2025-11-20 16:40:14 +08:00
2025-08-27 11:06:49 +08:00
setTimeout(sendNextPacket, 100);
}).catch(err => {
2025-09-15 11:55:44 +08:00
if (err.code == 10007) {
setTimeout(sendNextPacket, 100);
return;
}
2025-11-20 16:40:14 +08:00
2025-08-27 11:06:49 +08:00
console.log("发送数据包失败了", err);
2025-11-20 16:40:14 +08:00
2025-08-27 11:06:49 +08:00
these.Status.BottomMenu.show = false;
these.showPop({
message: "发送数据包失败了" + err.msg,
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
2025-11-20 16:40:14 +08:00
2025-08-27 11:06:49 +08:00
hideLoading(these);
reject(err);
});
2025-07-11 16:08:17 +08:00
}
2025-08-27 11:06:49 +08:00
// 开始发送数据
sendNextPacket();
2025-11-20 16:40:14 +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-27 11:06:49 +08:00
showLoading(these, {
2025-11-17 16:37:37 +08:00
text: "正在发送0/64"
2025-07-11 16:08:17 +08:00
});
2025-08-27 11:06:49 +08:00
2025-07-11 16:08:17 +08:00
these.Status.BottomMenu.show = false;
setTimeout(function() {
2025-09-15 11:55:44 +08:00
processAndSendImageData(data.piexls).catch((
ex) => {
2025-08-27 11:06:49 +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-08-27 11:06:49 +08:00
console.log("跳转页面失败" + JSON.stringify(ex));
2025-07-11 16:08:17 +08:00
}
});
}
});
},
2025-11-20 16:40:14 +08:00
UploadOpenVideo: function() { //开机动画
let f = these.getDevice();
if (!f) {
these.showBleUnConnect();
return;
}
let timeDelayCloseLoading = () => {
setTimeout(() => {
hideLoading(these);
}, 1500);
}
//视频上传
2025-11-21 14:43:23 +08:00
let uplploadVideo = (videoPath, width, height) => {
2025-11-20 16:40:14 +08:00
return new Promise((resolve, reject) => {
let start = new Date();
let token = uni.getStorageSync('token');
let clientid = uni.getStorageSync('clientID');
uni.uploadFile({
url: baseURL + "/app/video/upload",
filePath: videoPath,
name: 'file',
header: {
"Method": "POST",
"Content-Type": "multipart/form-data",
"Authorization": 'Bearer ' + token,
"clientid": clientid
},
formData: {
code: 1,
2025-11-21 14:43:23 +08:00
width: width,
height: height
2025-11-20 16:40:14 +08:00
},
timeout: 600000,
fail: (ex) => {
updateLoading(these, {
text: '视频文件上传失败了,请检查网络连接'
2025-11-20 16:40:14 +08:00
});
reject(ex);
},
success: (res) => {
// console.error(res);
let end = new Date();
var diff = (end.getTime() - start.getTime()) / 1000;
let s = diff % 60;
let m = parseInt((diff - s) / 60);
console.log("res.statusCode==", res.statusCode);
res.data = JSON.parse(res.data);
if (res.statusCode === 200) {
if (res.data.code == 200) {
console.log("上传完成,耗时:" + m + "分" + s + "秒");
updateLoading(these, {
text: "上传完成,耗时:" + m + "分" + s + "秒,正在切片。"
})
2025-11-20 16:40:14 +08:00
resolve(res.data);
return;
} else {
console.log("res.data=", res.data);
2025-11-20 16:40:14 +08:00
}
}
console.error("上传完成,耗时:" + m + "分" + s + "秒");
reject(res);
}
});
});
}
//视频切片
2025-11-20 17:51:26 +08:00
let videoCutPacket = (data) => {
2025-11-20 16:40:14 +08:00
return new Promise((resolve, reject) => {
try {
2025-11-20 17:51:26 +08:00
const imgSize = 25600;
const packetSize = 3200;
const chunkSize = 500;
const maxPacketCount = 30;
2025-11-20 16:40:14 +08:00
2025-11-20 17:51:26 +08:00
let source = Array.isArray(data) ? data.slice() : [];
2025-11-20 16:40:14 +08:00
let results = [];
2025-11-20 17:51:26 +08:00
for (let i = 0; i < maxPacketCount && source.length >= imgSize; i++) {
let frameBytes = source.splice(0, imgSize);
let framePackets = [];
for (let j = 0; j < 8 && frameBytes.length > 0; j++) {
let majorPacket = frameBytes.splice(0, packetSize);
let childPackets = [];
while (majorPacket.length > 0) {
let chunk = majorPacket.splice(0, chunkSize);
if (chunk.length) {
childPackets.push(chunk);
}
2025-11-20 16:40:14 +08:00
}
2025-11-20 17:51:26 +08:00
if (childPackets.length) {
framePackets.push(childPackets);
}
}
if (framePackets.length) {
results.push(framePackets);
2025-11-20 16:40:14 +08:00
}
}
2025-11-20 17:51:26 +08:00
updateLoading(these, {
text: '切片完成,正在发送'
});
2025-11-20 16:40:14 +08:00
resolve(results);
} catch (error) {
updateLoading(these, {
text: '视频切片发生异常'
});
reject(error);
}
});
}
2025-11-20 16:40:14 +08:00
//发送视频到设备
let shotVideoClick = (array, type, ReSendNo) => {
var sendImagePackets = () => {
return new Promise((resolve, reject) => {
this.currentPacket = 0;
2025-11-20 17:51:26 +08:00
let totalPackets = these.calcTotalPackets(array);
2025-11-20 16:40:14 +08:00
this.totalPackets = totalPackets;
2025-11-20 17:51:26 +08:00
if (totalPackets === 0) {
reject('没有可发送的数据');
return;
}
2025-11-20 16:40:14 +08:00
let currentPacket = 1;
let imgIndex = 0;
let imgPackIndex = 0;
let childPacketIndex = 0;
if (ReSendNo) {
this.currentPacket = ReSendNo - 1;
currentPacket = ReSendNo;
totalPackets = ReSendNo;
this.totalPackets = ReSendNo;
}
// 发送单个数据包
const sendNextPacket = () => {
2025-11-20 17:51:26 +08:00
if (imgIndex >= array.length) {
2025-11-20 16:40:14 +08:00
resolve();
return;
}
2025-11-20 17:51:26 +08:00
if (!array[imgIndex]) {
console.error("没有找到对应的帧数据", imgIndex);
reject(`帧数据缺失,索引 ${imgIndex}`);
return;
2025-11-20 16:40:14 +08:00
}
2025-11-20 17:51:26 +08:00
let childPacketsGroup = array[imgIndex][imgPackIndex];
if (!childPacketsGroup || !childPacketsGroup.length) {
console.error("帧数据结构异常", imgIndex, imgPackIndex);
reject(`帧数据结构异常,帧 ${imgIndex}`);
return;
2025-11-20 16:40:14 +08:00
}
2025-11-20 17:51:26 +08:00
let packetData = childPacketsGroup[childPacketIndex];
let packetSize = packetData.length;
2025-11-20 17:51:26 +08:00
const isFirstChild = childPacketIndex === 0;
const isLastChild = childPacketIndex === (childPacketsGroup
.length - 1);
2025-11-20 17:51:26 +08:00
if (isFirstChild) {
packetSize = packetData.length + 8;
2025-11-20 16:40:14 +08:00
}
2025-11-20 17:51:26 +08:00
if (isLastChild) {
packetSize = packetData.length + (isFirstChild ? 9 : 1);
}
2025-11-20 17:51:26 +08:00
const buffer = new ArrayBuffer(packetSize);
const dataView = new DataView(buffer);
2025-11-20 16:40:14 +08:00
let start = 0;
2025-11-20 17:51:26 +08:00
if (isFirstChild) {
2025-11-20 16:40:14 +08:00
// 填充头部
dataView.setUint8(0, 0xFA); // 帧头
dataView.setUint8(1, 0x09); // 帧类型:开机画面
dataView.setUint8(2, 0x0C);
dataView.setUint8(3, 0x84);
dataView.setUint8(4, 0xFD);
dataView.setUint8(5, 0x09);
dataView.setUint8(6, imgIndex);
dataView.setUint8(7, imgPackIndex + 1);
start = 8;
}
2025-11-20 16:40:14 +08:00
for (let i = 0; i < packetData.length; i++) {
2025-11-20 17:51:26 +08:00
dataView.setUint8(start + i, these.toByteValue(packetData[i]));
2025-11-20 16:40:14 +08:00
}
2025-11-20 17:51:26 +08:00
if (isLastChild) {
dataView.setUint8(packetSize - 1, 0xFF);
2025-11-20 16:40:14 +08:00
}
let inteval = parseInt(this.inteval ? this.inteval : 80);
// console.log(inteval, 'intevalinteval');
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
.wirteCharactId).then(() => {
2025-11-20 16:40:14 +08:00
if (ReSendNo) {
resolve();
return;
}
// 更新进度
this.currentPacket = currentPacket;
updateLoading(these, {
text: '正在发送:' + currentPacket + "/" +
totalPackets
2025-11-20 16:40:14 +08:00
});
2025-11-20 16:40:14 +08:00
childPacketIndex++;
2025-11-20 17:51:26 +08:00
if (childPacketIndex >= childPacketsGroup.length) {
childPacketIndex = 0;
2025-11-20 16:40:14 +08:00
imgPackIndex++;
2025-11-20 17:51:26 +08:00
if (imgPackIndex >= array[imgIndex].length) {
2025-11-20 16:40:14 +08:00
imgPackIndex = 0;
2025-11-20 17:51:26 +08:00
imgIndex++;
2025-11-20 16:40:14 +08:00
}
}
// 发送下一个包(添加延迟避免蓝牙缓冲区溢出)
currentPacket++;
2025-11-20 16:40:14 +08:00
setTimeout(sendNextPacket, inteval);
}).catch(err => {
if (err.code == 10007) {
console.error(err.errMsg + ",发送失败了,正在补偿:" +
currentPacket);
setTimeout(sendNextPacket, 100);
return;
}
2025-11-20 16:40:14 +08:00
console.error(err.errMsg + ",发送失败了" + currentPacket);
updateLoading(these, {
text: "发送失败," + err.errMsg
});
2025-11-20 16:40:14 +08:00
reject(err);
});
};
sendNextPacket();
});
}
return sendImagePackets();
}
uni.chooseVideo({
sourceType: ['album'],
2025-11-21 15:59:58 +08:00
compressed: false, // 关闭视频压缩,确保上传原始文件
2025-11-20 16:40:14 +08:00
success: function(res) {
console.log("res=", res);
2025-11-20 16:40:14 +08:00
let path = res.tempFilePath;
// iOS可能返回浮点数需要转换为整数进行比较
let width = Math.round(res.width);
let height = Math.round(res.height);
2025-11-20 16:40:14 +08:00
let duration = res.duration;
2025-11-21 16:12:55 +08:00
2025-11-21 14:43:23 +08:00
// 获取平台信息
const systemInfo = uni.getSystemInfoSync();
const platform = systemInfo.platform;
const isIOS = platform === 'ios';
2025-11-21 16:12:55 +08:00
console.log("平台:", platform, "uni.chooseVideo返回 - 宽度:", width, "高度:", height,
"时长:", duration);
2025-11-21 14:43:23 +08:00
// iOS特殊处理如果返回的是80*40很可能是160*80的一半iOS的bug
if (isIOS && width === 80 && height === 40) {
console.log("检测到iOS特殊情况返回80*40实际应该是160*80进行修正");
width = 160;
height = 80;
}
2025-11-21 16:12:55 +08:00
2025-11-21 14:43:23 +08:00
// 检查分辨率是否符合要求
let checkResolution = (w, h) => {
// 使用容差比较允许1像素的误差
return Math.abs(w - 160) <= 1 && Math.abs(h - 80) <= 1;
};
2025-11-21 16:12:55 +08:00
2025-11-20 16:40:14 +08:00
let err = [];
if (duration < 2) {
err.push("视频时长至少2秒");
}
2025-11-21 14:43:23 +08:00
if (!checkResolution(width, height)) {
err.push("视频宽高必须是160*80当前分辨率" + width + "*" + height);
2025-11-20 16:40:14 +08:00
}
2025-11-21 16:12:55 +08:00
2025-11-20 16:40:14 +08:00
if (err.length > 0) {
err = err.join(";");
these.showPop({
message: err,
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
return;
}
2025-11-21 16:12:55 +08:00
2025-11-20 16:40:14 +08:00
showLoading(these, {
text: '正在上传'
});
setTimeout(() => {
2025-11-21 14:43:23 +08:00
uplploadVideo(path, width, height).then(result => {
2025-11-20 16:40:14 +08:00
2025-11-20 17:51:26 +08:00
let data = result.data;
let convertedData = [];
for (let i = 0; i < data.length; i += 2) {
if (i + 1 < data.length) {
const byte1 = these.toByteValue(data[i]);
const byte2 = these.toByteValue(data[i + 1]);
const rgb565 = (byte1 << 8) | byte2;
const red = (rgb565 & 0xF800) >> 11;
const green = (rgb565 & 0x07E0) >> 5;
const blue = (rgb565 & 0x001F);
const bgr565 = (blue << 11) | (green << 5) | red;
convertedData.push((bgr565 >> 8) & 0xFF);
convertedData.push(bgr565 & 0xFF);
} else {
convertedData.push(these.toByteValue(data[i]));
}
}
videoCutPacket(convertedData).then(array => {
let start = new Date();
console.log("开始发送");
shotVideoClick(array).then(() => {
console.log("发送完成");
let end = new Date();
var diff = (end.getTime() - start
.getTime()) / 1000;
let s = parseInt(diff % 60);
let m = parseInt((diff - s) / 60);
console.log("发送完成,耗时:" + m + "分" +
s + "秒");
updateLoading(these, {
text: "发送完成,耗时:" + m +
"分" + s + "秒",
});
}).catch((ex1) => {
console.log("出现了异常", ex1)
}).finally(() => {
timeDelayCloseLoading();
});
2025-11-20 16:40:14 +08:00
}).catch(err => {
timeDelayCloseLoading();
});
}).catch(ex => {
timeDelayCloseLoading();
});
}, 0);
}
});
},
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-07-11 16:08:17 +08:00
let items = [];
let title = '';
2025-07-11 16:08:17 +08:00
switch (type) {
case "main":
title = '主灯模式';
2025-08-27 11:06:49 +08:00
items = [{
2025-07-11 16:08:17 +08:00
text: '强光',
icon: '/static/images/6155/DeviceDetail/qiang.png'
},
// {
// 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-09-15 11:55:44 +08:00
},
2025-08-27 11:06:49 +08:00
{
text: '关闭',
icon: '/static/images/6155/DeviceDetail/close.png'
2025-07-11 16:08:17 +08:00
}
];
break;
case "fu":
title = '辅灯模式';
items = [{
2025-11-26 15:57:52 +08:00
text: '泛光',
icon: '/static/images/6155/DeviceDetail/fan.png'
},
{
text: '强+泛光',
icon: '/static/images/6155/DeviceDetail/fan.png'
},
];
2025-07-11 16:08:17 +08:00
break;
}
2025-07-11 16:08:17 +08:00
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;
}
2025-07-11 16:08:17 +08:00
},
showMenu(flag) {
this.Status.BottomMenu.show = true;
},
closeMenu() {
this.Status.BottomMenu.show = false;
},
btnClick(item, index) {
if (parseInt(this.Status.BottomMenu.activeIndex) === NaN) {
uni.showToast('请选择模式');
2025-07-11 16:08:17 +08:00
return;
}
//发送指令给设备
switch (this.Status.BottomMenu.type) {
case "main":
2025-08-27 11:06:49 +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-27 11:06:49 +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-27 11:06:49 +08:00
setMode(mode, type) {
let dataValue = 0;
2025-07-11 16:08:17 +08:00
switch (mode) {
case 0:
2025-09-15 11:55:44 +08:00
if (type == 'main') {
dataValue = 0x01;
} else if (type == 'fu') {
dataValue = 0x04;
2025-09-15 11:55:44 +08:00
}
2025-07-11 16:08:17 +08:00
break;
case 1:
2025-11-26 15:57:52 +08:00
if (type == 'main') {
dataValue = 0x02;
} else if (type == 'fu') {
dataValue = 0x0A; //强泛光
}
2025-07-11 16:08:17 +08:00
break;
case 2:
2025-08-27 11:06:49 +08:00
dataValue = 0x03;
2025-07-11 16:08:17 +08:00
break;
case 3:
2025-09-15 11:55:44 +08:00
dataValue = 0x0B;
2025-07-11 16:08:17 +08:00
break;
2025-08-27 11:06:49 +08:00
2025-07-11 16:08:17 +08:00
}
2025-11-26 15:57:52 +08:00
console.log("dataValue=", dataValue)
2025-07-11 16:08:17 +08:00
// 构建数据包
2025-08-27 11:06:49 +08:00
var buffer = new ArrayBuffer(6);
var dataView = new DataView(buffer);
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-11 16:08:17 +08:00
2025-08-27 11:06:49 +08:00
let f = this.getDevice();
2025-07-11 16:08:17 +08:00
// 发送数据
2025-08-27 11:06:49 +08:00
if (!f) {
these.showBleUnConnect();
2025-08-27 11:06:49 +08:00
return;
}
showLoading(these, {
text: "请稍候..."
2025-07-11 16:08:17 +08:00
});
2025-08-27 11:06:49 +08:00
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30).then(() => {
this.formData.light = mode;
this.formData.mode = type
this.setBleFormData();
2025-08-27 11:06:49 +08:00
}).catch((ex) => {
these.showPop({
message: "发送失败," + ex.msg,
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
}).finally(() => {
hideLoading(these);
});
2025-07-11 16:08:17 +08:00
},
handleItemClick(item, index) {
// switch (this.Status.BottomMenu.type) {
// case "main":
2025-07-11 16:08:17 +08:00
// break;
// case "fu":
2025-07-11 16:08:17 +08:00
// break;
// }
2025-07-11 16:08:17 +08:00
this.Status.BottomMenu.activeIndex = index;
2025-08-27 11:06:49 +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
},
closePop: function() {
this.Status.Pop.showPop = false;
if (this.Status.Pop.cancelCallback) {
this.Status.Pop.cancelCallback();
}
},
2025-07-11 16:08:17 +08:00
HidePop: function() {
// console.log("1111");
2025-07-11 16:08:17 +08:00
if (this.Status.Pop.clickEvt == 'SendUsr') {
}
if (this.Status.Pop.okCallback) {
this.Status.Pop.okCallback();
2025-07-11 16:08:17 +08:00
}
this.Status.Pop.showPop = false;
},
2025-08-27 11:06:49 +08:00
showPop: function(option) {
hideLoading(this);
let def = {
showPop: true, //是否显示弹窗
popType: 'custom',
bgColor: '#383934bd',
borderColor: '#BBE600',
textColor: '#ffffffde',
buttonBgColor: '#BBE600',
buttonTextColor: '#232323DE',
iconUrl: '',
message: '',
buttonText: '确定',
clickEvt: '',
visiblePrompt: false,
promptTitle: '',
modelValue: '',
visibleClose: false,
okCallback: null,
showSlot: false,
buttonCancelText: '',
showCancel: false,
2025-08-27 11:06:49 +08:00
}
let keys = Object.keys(def);
for (let i = 0; i < keys.length; i++) {
let key = keys[i];
if (key in option) {
continue;
}
this.Status.Pop[key] = def[key];
2025-08-27 11:06:49 +08:00
}
if (option) {
keys = Object.keys(option);
for (let i = 0; i < keys.length; i++) {
let key = keys[i];
this.Status.Pop[key] = option[key];
}
}
if (!option.borderColor) {
option.borderColor = '#BBE600';
option.buttonBgColor = '#BBE600';
}
these.Status.Pop.showPop = true;
2025-08-27 11:06:49 +08:00
},
sendUsr() {
let f = this.getDevice();
if (!f) {
these.showBleUnConnect()
2025-08-27 11:06:49 +08:00
return;
}
let err = false;
this.formData.textLines.find((txt) => {
if (txt.length === 0 || txt.length > 7) {
console.log("txt=", txt);
err = true;
return true;
}
return false;
})
if (err) {
this.showPop({
message: "单位、部门、姓名必须填写且最多7字",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
return;
}
2025-08-27 11:06:49 +08:00
showLoading(these, {
text: "请稍候..."
});
this.setBleFormData();
let task = async () => {
2025-09-15 11:55:44 +08:00
try {
// 预热画布确保画布和字体完全准备好解决APP重新打开后第一次获取数据不完整的问题
console.log("预热画布...");
await this.$refs.textToHex.drawAndGetPixels();
await new Promise(resolve => setTimeout(resolve, 200)); // 等待预热完成
// 1. 获取所有文本行的像素数据
const allPixels = await this.$refs.textToHex.drawAndGetPixels();
if (!allPixels) {
throw new Error("无法生成像素数据");
}
2025-09-15 11:55:44 +08:00
// 2. 将所有像素数据合并到一个大数组中
let combinedData = [];
for (let i = 0; i < 3; i++) {
const linePixels = (allPixels[i] || []).flat(Infinity).map(item =>
typeof item === 'string' ? these.toByteValue(item) : item
);
// 补齐到256字节
while (linePixels.length < 256) {
linePixels.push(0x00);
}
combinedData = combinedData.concat(linePixels.slice(0, 256));
}
2025-09-15 11:55:44 +08:00
// 3. 构建完整的逻辑大包
const logicalPacketSize = 4 + combinedData.length + 1; // Header + Data + Footer
const logicalBuffer = new ArrayBuffer(logicalPacketSize);
const logicalDataView = new DataView(logicalBuffer);
2025-09-15 11:55:44 +08:00
// 写入头部
logicalDataView.setUint8(0, 0xFA);
logicalDataView.setUint8(1, 0x06);
logicalDataView.setUint8(2, 0x03);
logicalDataView.setUint8(3, 0x00);
2025-09-15 11:55:44 +08:00
// 写入数据
for (let i = 0; i < combinedData.length; i++) {
logicalDataView.setUint8(4 + i, combinedData[i]);
}
2025-08-27 11:06:49 +08:00
// 写入尾部
logicalDataView.setUint8(logicalPacketSize - 1, 0xFF);
2025-08-27 11:06:49 +08:00
// 4. 将逻辑大包分包发送
const CHUNK_SIZE = 500; // 每个物理包的大小
const totalChunks = Math.ceil(logicalPacketSize / CHUNK_SIZE);
2025-08-27 11:06:49 +08:00
updateLoading(these, {
text: `准备发送,共 ${totalChunks} 个数据包...`
});
2025-08-27 11:06:49 +08:00
for (let i = 0; i < totalChunks; i++) {
const start = i * CHUNK_SIZE;
const end = Math.min(start + CHUNK_SIZE, logicalPacketSize);
const chunk = logicalBuffer.slice(start, end);
2025-08-27 11:06:49 +08:00
updateLoading(these, {
text: `正在发送 ${i + 1} / ${totalChunks}`
});
2025-08-27 11:06:49 +08:00
await ble.sendData(f.deviceId, chunk, f.writeServiceId, f.wirteCharactId, 50);
await new Promise(resolve => setTimeout(resolve, 50)); // 包之间延迟
2025-08-27 11:06:49 +08:00
}
2025-07-11 16:08:17 +08:00
// 5. 发送成功处理
hideLoading(these);
2025-09-15 11:55:44 +08:00
this.showPop({
message: "发送成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
borderColor: '#BBE600',
buttonBgColor: '#BBE600'
2025-08-27 11:06:49 +08:00
});
let json = {
deviceId: these.device.id,
name: these.formData.textLines[1],
position: these.formData.textLines[0],
unitName: these.formData.textLines[2],
code: ""
};
usrApi.sendUsr(json);
2025-11-26 15:57:52 +08:00
} catch (ex) {
hideLoading(these);
2025-08-27 11:06:49 +08:00
this.showPop({
message: "发送失败: " + (ex.msg || ex.message),
2025-08-27 11:06:49 +08:00
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
}
};
2025-08-27 11:06:49 +08:00
setTimeout(task, 0);
2025-07-11 16:08:17 +08:00
},
getDetail() {
var that = this;
usrApi.getDetail(this.device.id).then(res => {
if (res && res.code == 200) {
res = res.data;
let personnelInfo = res.personnelInfo;
if (personnelInfo) {
these.formData.textLines[2] = personnelInfo.unitName;
these.formData.textLines[1] = personnelInfo.name;
these.formData.textLines[0] = personnelInfo.position;
2025-08-27 11:06:49 +08:00
}
}
});
},
2025-07-11 16:08:17 +08:00
ack: function() {
2025-08-27 11:06:49 +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;
2025-09-15 11:55:44 +08:00
clearTimeout(BrighInteval)
2025-07-11 16:08:17 +08:00
//给蓝牙设备发送信号更新亮度
2025-09-15 11:55:44 +08:00
BrighInteval = setTimeout(() => {
2025-07-11 16:08:17 +08:00
this.sendBrightness();
2025-08-27 11:06:49 +08:00
this.setBleFormData();
2025-09-15 11:55:44 +08:00
}, 100);
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);
2025-09-15 11:55:44 +08:00
dataView.setUint8(0, 0xFA); // 帧头
dataView.setUint8(1, 0x05); // 帧类型:亮度调节
dataView.setUint8(2, 0x00); // 包序号
dataView.setUint8(3, 0x01); // 包序号
dataView.setUint8(4, data); // 数据长度
dataView.setUint8(5, 0xFF); // 数据长度
2025-08-27 11:06:49 +08:00
let f = this.getDevice();
if (f) {
// 发送数据
2025-07-11 16:08:17 +08:00
2025-08-27 11:06:49 +08:00
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30);
2025-07-11 16:08:17 +08:00
2025-08-27 11:06:49 +08:00
}
},
//获取当前设备状态
GetDeviceStatu: function() {
//数据头 命令码 数据 校验码
//JQOC 0B 00 9C41
//硬件响应
//数据头 命令码 主灯模式 副灯模式 亮度(%) 电量(%) 充电状态 校验码
//JQOC 0B 01 01 64 85 01 9C41
this.sendCmd('0x0B');
},
//设备重启
DeviceReStart: function() {
//数据头 命令码 数据 校验码
//JQOC 0C 01 9C412
this.sendCmd('0x0C');
},
//恢复出厂设置
DeviceReSet: function() {
//数据头 命令码 数据 校验码
//JQOC 0D 01 9C412
this.sendCmd('0x0D');
},
sendCmd: function(type, callback) {
//数据头 命令码 数据 校验码
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'); // 数据长度
let f = this.getDevice();
if (f) {
// 发送数据
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30);
2025-07-11 16:08:17 +08:00
2025-08-27 11:06:49 +08:00
}
2025-07-11 16:08:17 +08:00
}
2025-08-27 11:06:49 +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-27 11:06:49 +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-27 11:06:49 +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-27 11:06:49 +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-27 11:06:49 +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-27 11:06:49 +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-27 11:06:49 +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-27 11:06:49 +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-27 11:06:49 +08:00
line-height: 65rpx;
2025-07-11 16:08:17 +08:00
border-radius: 8px;
2025-08-27 11:06:49 +08:00
width: 120rpx;
height: 65rpx;
2025-07-11 16:08:17 +08:00
color: rgba(35, 35, 35, 0.87);
2025-08-27 11:06:49 +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-27 11:06:49 +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-27 11:06:49 +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-27 11:06:49 +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-27 11:06:49 +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-27 11:06:49 +08:00
.TextToHex {
position: fixed;
top: -99999rpx;
left: -99999rpx;
visibility: hidden;
}
2025-07-11 16:08:17 +08:00
</style>