Merge branch 'new-20250827' of http://47.107.152.87:3000/liubiao/APP into new-20250827
This commit is contained in:
@ -35,7 +35,9 @@
|
|||||||
currentCanvasWidth: 0,
|
currentCanvasWidth: 0,
|
||||||
currentCanvasHeight: 0,
|
currentCanvasHeight: 0,
|
||||||
// Canvas上下文(复用)
|
// Canvas上下文(复用)
|
||||||
ctx: null
|
ctx: null,
|
||||||
|
// 标记画布是否已预热(解决首次发送像素不完整问题)
|
||||||
|
canvasWarmed: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -63,10 +65,63 @@
|
|||||||
this.ctx.fillRect(0, 0, this.currentCanvasWidth, this.currentCanvasHeight);
|
this.ctx.fillRect(0, 0, this.currentCanvasWidth, this.currentCanvasHeight);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 预热画布,防止 APP 首次调用时获取到的像素数据不完整
|
||||||
|
*/
|
||||||
|
async warmupCanvas() {
|
||||||
|
if (this.canvasWarmed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 先用一个最小画布绘制测试字形,触发字体和 canvas 初始化
|
||||||
|
this.currentCanvasWidth = 16;
|
||||||
|
this.currentCanvasHeight = 16;
|
||||||
|
this.clearCanvas();
|
||||||
|
this.ctx.setFillStyle(this.color);
|
||||||
|
this.ctx.setFontSize(this.fontSize);
|
||||||
|
this.ctx.font = `${this.fontSize}px "PingFangBold", "PingFang SC", Arial, sans-serif`;
|
||||||
|
this.ctx.setTextBaseline('middle');
|
||||||
|
this.ctx.fillText('测', 0, 8);
|
||||||
|
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
this.ctx.draw(false, () => {
|
||||||
|
// 读取一次数据,确保 canvasGetImageData 就绪
|
||||||
|
setTimeout(() => {
|
||||||
|
uni.canvasGetImageData({
|
||||||
|
canvasId: 'reusableCanvas',
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
width: 16,
|
||||||
|
height: 16,
|
||||||
|
success: () => {
|
||||||
|
this.canvasWarmed = true;
|
||||||
|
resolve();
|
||||||
|
},
|
||||||
|
fail: () => {
|
||||||
|
// 即便失败也认为已尝试过,避免反复预热阻塞流程
|
||||||
|
this.canvasWarmed = true;
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// 额外等待,确保字体完全加载
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 200));
|
||||||
|
} catch (ex) {
|
||||||
|
console.log("画布预热异常:", ex);
|
||||||
|
this.canvasWarmed = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 复用单个Canvas处理所有文本行
|
* 复用单个Canvas处理所有文本行
|
||||||
*/
|
*/
|
||||||
async drawAndGetPixels() {
|
async drawAndGetPixels() {
|
||||||
|
// 首次调用先做预热,避免第一次上报缺字
|
||||||
|
await this.warmupCanvas();
|
||||||
|
|
||||||
let binaryToHex = (binaryArray) => {
|
let binaryToHex = (binaryArray) => {
|
||||||
if (!Array.isArray(binaryArray) || binaryArray.length !== 8) {
|
if (!Array.isArray(binaryArray) || binaryArray.length !== 8) {
|
||||||
throw new Error("输入必须是包含8个元素的二进制数组");
|
throw new Error("输入必须是包含8个元素的二进制数组");
|
||||||
@ -92,7 +147,7 @@
|
|||||||
|
|
||||||
let convertCharToMatrix = (imageData, item) => {
|
let convertCharToMatrix = (imageData, item) => {
|
||||||
const charWidth = 13;
|
const charWidth = 13;
|
||||||
const charHeight = 12;
|
const charHeight = 13;
|
||||||
const pixels = [];
|
const pixels = [];
|
||||||
for (let i = 0; i < imageData.length; i += 4) {
|
for (let i = 0; i < imageData.length; i += 4) {
|
||||||
const R = imageData[i];
|
const R = imageData[i];
|
||||||
@ -123,7 +178,7 @@
|
|||||||
|
|
||||||
// 1. 动态调整Canvas尺寸
|
// 1. 动态调整Canvas尺寸
|
||||||
this.currentCanvasWidth = 13;
|
this.currentCanvasWidth = 13;
|
||||||
this.currentCanvasHeight = 12;
|
this.currentCanvasHeight = 13;
|
||||||
|
|
||||||
// 2. 清空Canvas(绘制背景)
|
// 2. 清空Canvas(绘制背景)
|
||||||
this.clearCanvas();
|
this.clearCanvas();
|
||||||
|
|||||||
@ -199,11 +199,47 @@
|
|||||||
<image src="/static/images/210/delete.png" mode="aspectFit" class="uploadIMG"></image>
|
<image src="/static/images/210/delete.png" mode="aspectFit" class="uploadIMG"></image>
|
||||||
<text>删除文件</text>
|
<text>删除文件</text>
|
||||||
</view>
|
</view>
|
||||||
|
<!-- 展示已上传的报警声音文件 -->
|
||||||
|
<view class="file-list-tip" v-if="soundFileList.length > 0">
|
||||||
|
<text>已上传文件:{{ soundFileList.map(item => item.name).join('、') }}</text>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<!-- 按钮组 -->
|
<!-- 按钮组 -->
|
||||||
<view class="popup-buttons">
|
<view class="popup-buttons">
|
||||||
<button class="agree" @click="handleupload">确定</button>
|
<button class="agree" @click="handleSoundUpload">确定</button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<!-- =====删除报警声音文件列表弹窗======= -->
|
||||||
|
<view class="agreement-mask" v-if="deleteSoundMode" @click.stop="closeDeleteSoundPopup">
|
||||||
|
<view class="agreement-popupB" @click.stop style="height: 45%;">
|
||||||
|
<!-- 标题 -->
|
||||||
|
<view class="popup-title">选择要删除的报警声音</view>
|
||||||
|
<view class="popup-content">
|
||||||
|
<!-- 无文件提示 -->
|
||||||
|
<view v-if="soundFileList.length === 0" class="empty-tip">
|
||||||
|
<text>暂无已上传的报警声音文件</text>
|
||||||
|
</view>
|
||||||
|
<view v-else class="file-list">
|
||||||
|
<view
|
||||||
|
class="file-item"
|
||||||
|
v-for="(file, index) in soundFileList"
|
||||||
|
:key="index"
|
||||||
|
>
|
||||||
|
<checkbox
|
||||||
|
v-model="selectedSoundFiles"
|
||||||
|
:value="file"
|
||||||
|
@change="handleSoundFileSelect"
|
||||||
|
/>
|
||||||
|
<text class="file-name">{{ file.name }}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<!-- 按钮组 -->
|
||||||
|
<view class="popup-buttons" style="position: relative; bottom: 0;">
|
||||||
|
<button class="disagree" @click="closeDeleteSoundPopup" style="width: 48%;">取消</button>
|
||||||
|
<button class="agreeBtn" @click="confirmDeleteSound" :disabled="selectedSoundFiles.length === 0" style="width: 48%;">确定删除</button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -292,9 +328,23 @@
|
|||||||
console.log('自动报警确认');
|
console.log('自动报警确认');
|
||||||
// 这里可以添加自动报警的逻辑
|
// 这里可以添加自动报警的逻辑
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
// 报警声音上传成功
|
||||||
|
soundUpload: {
|
||||||
|
config: {
|
||||||
|
icon: '/static/images/common/upload.png',
|
||||||
|
message: '报警声音上传成功',
|
||||||
|
showCancel: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 报警声音删除成功
|
||||||
|
soundDelete: {
|
||||||
|
config: {
|
||||||
|
icon: '/static/images/common/sendSucc.png',
|
||||||
|
message: '报警声音删除成功',
|
||||||
|
showCancel: false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
import MqttClient from '@/utils/mqtt.js';
|
import MqttClient from '@/utils/mqtt.js';
|
||||||
import {
|
import {
|
||||||
@ -400,7 +450,11 @@
|
|||||||
radioSelected: 0, // -1表示未选中任何项
|
radioSelected: 0, // -1表示未选中任何项
|
||||||
deviceType: '',
|
deviceType: '',
|
||||||
popupType: '', //弹框类型
|
popupType: '', //弹框类型
|
||||||
lightModeC: false
|
lightModeC: false,
|
||||||
|
// 新增:报警声音文件相关
|
||||||
|
soundFileList: [],
|
||||||
|
deleteSoundMode: false,
|
||||||
|
selectedSoundFiles: []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -408,11 +462,112 @@
|
|||||||
closePopup() {
|
closePopup() {
|
||||||
this.lightModeA = false;
|
this.lightModeA = false;
|
||||||
this.lightModeB = false;
|
this.lightModeB = false;
|
||||||
|
this.lightModeC = false;
|
||||||
|
},
|
||||||
|
// 关闭删除报警声音弹窗
|
||||||
|
closeDeleteSoundPopup() {
|
||||||
|
this.deleteSoundMode = false;
|
||||||
|
this.selectedSoundFiles = []; // 清空选中状态
|
||||||
|
this.lightModeC = true; // 回到报警声音上传弹窗
|
||||||
|
},
|
||||||
|
|
||||||
|
handleSoundFileSelect() {
|
||||||
|
console.log("选中的报警声音文件:", this.selectedSoundFiles);
|
||||||
|
},
|
||||||
|
// 确认删除选中的报警声音文件
|
||||||
|
confirmDeleteSound() {
|
||||||
|
this.soundFileList = this.soundFileList.filter(file => !this.selectedSoundFiles.includes(file));
|
||||||
|
this.showPopup('soundDelete');
|
||||||
|
this.selectedSoundFiles = [];
|
||||||
|
this.closeDeleteSoundPopup();
|
||||||
|
},
|
||||||
|
// 上传报警声音文件
|
||||||
|
uploadFile() {
|
||||||
|
uni.chooseFile({
|
||||||
|
count: 1,
|
||||||
|
success: (res) => {
|
||||||
|
const file = res.tempFiles[0];
|
||||||
|
const fileSize = file.size || 0;
|
||||||
|
// 限制文件大小(示例:5MB)
|
||||||
|
if (fileSize > 5 * 1024 * 1024) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '文件大小不能超过5MB',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 3000
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 显示上传中加载提示
|
||||||
|
uni.showLoading({
|
||||||
|
title: '上传中...',
|
||||||
|
mask: true
|
||||||
|
});
|
||||||
|
// 调用上传接口
|
||||||
|
uni.uploadFile({
|
||||||
|
url: baseURL + '/app/device/uploadSound', // 替换为真实的报警声音上传接口
|
||||||
|
filePath: file.path,
|
||||||
|
name: 'file',
|
||||||
|
formData: {
|
||||||
|
deviceId: this.deviceID,
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
'Authorization': 'Bearer ' + getToken(),
|
||||||
|
'clientid': clientid(),
|
||||||
|
},
|
||||||
|
complete: (res) => {
|
||||||
|
uni.hideLoading();
|
||||||
|
try {
|
||||||
|
const responseData = JSON.parse(res.data);
|
||||||
|
if (responseData.code === 200) {
|
||||||
|
// 上传成功,添加到文件列表
|
||||||
|
this.soundFileList.push({
|
||||||
|
name: file.name,
|
||||||
|
url: responseData.data.url // 接口返回的文件地址
|
||||||
|
});
|
||||||
|
this.showPopup('soundUpload');
|
||||||
|
} else {
|
||||||
|
uni.showToast({
|
||||||
|
title: responseData.msg,
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '上传失败',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
console.error('选择文件失败:', err);
|
||||||
|
uni.showToast({
|
||||||
|
title: '选择文件失败',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
deleteQ() {
|
||||||
|
if (this.soundFileList.length === 0) {
|
||||||
|
uni.showToast({
|
||||||
|
title: "暂无可删除的报警声音文件",
|
||||||
|
icon: "none"
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.lightModeC = false;
|
||||||
|
this.deleteSoundMode = true;
|
||||||
|
},
|
||||||
|
// 报警声音上传弹窗确定按钮
|
||||||
|
handleSoundUpload() {
|
||||||
|
uni.showToast({
|
||||||
|
title: "报警声音配置确认成功",
|
||||||
|
icon: "success"
|
||||||
|
});
|
||||||
|
this.closePopup();
|
||||||
},
|
},
|
||||||
// 上传文件
|
|
||||||
uploadFile() {},
|
|
||||||
// 删除文件
|
|
||||||
deleteQ() {},
|
|
||||||
// 打开弹框
|
// 打开弹框
|
||||||
showPopup(type) {
|
showPopup(type) {
|
||||||
this.currentPopup = {
|
this.currentPopup = {
|
||||||
@ -497,7 +652,7 @@
|
|||||||
uploadStartup() {
|
uploadStartup() {
|
||||||
this.lightModeB = true
|
this.lightModeB = true
|
||||||
},
|
},
|
||||||
// 上传开机画面
|
// 上传开机画面-选择图片
|
||||||
checkImgUpload() {
|
checkImgUpload() {
|
||||||
uni.chooseImage({
|
uni.chooseImage({
|
||||||
count: 1,
|
count: 1,
|
||||||
@ -766,7 +921,6 @@
|
|||||||
title: '加载中...'
|
title: '加载中...'
|
||||||
})
|
})
|
||||||
eventChannel.on('detailData', (data) => {
|
eventChannel.on('detailData', (data) => {
|
||||||
console.log(data, '这是传过来的惨呼啊');
|
|
||||||
this.itemInfo = data.data;
|
this.itemInfo = data.data;
|
||||||
this.deviceID = data.data.id;
|
this.deviceID = data.data.id;
|
||||||
this.navTitle = data.data.deviceName;
|
this.navTitle = data.data.deviceName;
|
||||||
@ -1380,4 +1534,30 @@
|
|||||||
margin-top: 60rpx;
|
margin-top: 60rpx;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 新增:删除文件列表样式 */
|
||||||
|
.file-list-tip {
|
||||||
|
margin-top: 20rpx;
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
.empty-tip {
|
||||||
|
text-align: center;
|
||||||
|
color: #999;
|
||||||
|
padding: 20rpx 0;
|
||||||
|
}
|
||||||
|
.file-list {
|
||||||
|
padding: 10rpx 0;
|
||||||
|
}
|
||||||
|
.file-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 10rpx 0;
|
||||||
|
border-bottom: 1px solid #eee;
|
||||||
|
}
|
||||||
|
.file-name {
|
||||||
|
margin-left: 10rpx;
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: rgba(255, 255, 255, 0.87);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
@ -27,12 +27,12 @@
|
|||||||
<text class="value">{{device.deviceName}}</text>
|
<text class="value">{{device.deviceName}}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="item">
|
<view class="item">
|
||||||
<text class="lbl">Mac地址</text>
|
<text class="lbl">Mac地址</text>
|
||||||
<text class="value">{{device.deviceMac}}</text>
|
<text class="value">{{device.deviceMac}}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="item">
|
<view class="item">
|
||||||
<text class="lbl">设备状态</text>
|
<text class="lbl">设备状态</text>
|
||||||
<text class="value">{{formData.statu}}</text>
|
<text class="value" :class="formData.statu === '充电中' ? 'red' : 'white'">{{formData.statu}}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="item">
|
<view class="item">
|
||||||
<text class="lbl">蓝牙名称</text>
|
<text class="lbl">蓝牙名称</text>
|
||||||
@ -390,6 +390,7 @@
|
|||||||
}
|
}
|
||||||
if (res.deviceId == these.formData.deviceId) {
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
this.formData.bleStatu = true;
|
this.formData.bleStatu = true;
|
||||||
|
// 重新连接后状态以设备上报为准
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
hideLoading(these, 1000);
|
hideLoading(these, 1000);
|
||||||
});
|
});
|
||||||
@ -406,6 +407,9 @@
|
|||||||
}
|
}
|
||||||
if (res.deviceId == these.formData.deviceId) {
|
if (res.deviceId == these.formData.deviceId) {
|
||||||
this.formData.bleStatu = false;
|
this.formData.bleStatu = false;
|
||||||
|
// 断开连接时先将充电状态复位,避免保持旧值
|
||||||
|
this.formData.statu = '未充电';
|
||||||
|
this.setBleFormData();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
hideLoading(these, 1000);
|
hideLoading(these, 1000);
|
||||||
});
|
});
|
||||||
@ -491,7 +495,10 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if ('statu' in json) {
|
if ('statu' in json) {
|
||||||
these.formData.statu = json.statu == '1' ? '充电中' : '未充电';
|
const chargingVal = json.statu;
|
||||||
|
const isCharging = chargingVal === 1 || chargingVal === '1' || chargingVal === true ||
|
||||||
|
chargingVal === '充电中';
|
||||||
|
these.formData.statu = isCharging ? '充电中' : '未充电';
|
||||||
}
|
}
|
||||||
if ('xuhang' in json) {
|
if ('xuhang' in json) {
|
||||||
these.formData.xuhang = json.xuhang;
|
these.formData.xuhang = json.xuhang;
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
}
|
}
|
||||||
.deviceTitle{
|
.deviceTitle{
|
||||||
color: rgba(255, 255, 255, 0.87);
|
color: rgba(255, 255, 255, 0.87);
|
||||||
line-height: 45mnrpx;
|
line-height: 45rpx;
|
||||||
font-size: 28rpx;
|
font-size: 28rpx;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
Reference in New Issue
Block a user