完成100
This commit is contained in:
@ -789,7 +789,7 @@ class BleHelper {
|
||||
}
|
||||
|
||||
try {
|
||||
console.log("11111");
|
||||
// console.log("11111");
|
||||
let recData = {
|
||||
deviceId: receive.deviceId,
|
||||
serviceId: receive.serviceId,
|
||||
@ -798,7 +798,7 @@ class BleHelper {
|
||||
str: str,
|
||||
hexs: hexs
|
||||
};
|
||||
console.log("监听到特征值:" + JSON.stringify(recData));
|
||||
// console.log("监听到特征值:" + JSON.stringify(recData));
|
||||
if (this.cfg.receivDataCallback) {
|
||||
|
||||
if (this.cfg.receivDataCallback.length > 0) {
|
||||
|
||||
@ -7,7 +7,7 @@ class BleReceive {
|
||||
'/pages/650/HBY650': this.Receive_650.bind(this),
|
||||
'/pages/670/HBY670': this.Receive_670.bind(this),
|
||||
'/pages/4877/BJQ4877': this.Receive_4877.bind(this),
|
||||
'/pages/100/HBY100': this.Receive_4877.bind(this)
|
||||
'/pages/100/HBY100': this.Receive_100.bind(this)
|
||||
};
|
||||
}
|
||||
|
||||
@ -45,8 +45,9 @@ class BleReceive {
|
||||
let handler = null;
|
||||
let keys = Object.keys(this.HandlerMap);
|
||||
for (let index = 0; index < keys.length; index++) {
|
||||
let key = keys[index].replaceAll('/', '').toLowerCase();
|
||||
let devKey = f.device.detailPageUrl ? f.device.detailPageUrl.replaceAll('/', '').toLowerCase() : '';
|
||||
|
||||
let key = keys[index].replace(/\//g, "").toLowerCase();
|
||||
let devKey = f.device.detailPageUrl ? f.device.detailPageUrl.replace(/\//g, "").toLowerCase() : '';
|
||||
if (key == devKey) {
|
||||
handler = this.HandlerMap[keys[index]];
|
||||
break;
|
||||
@ -150,8 +151,8 @@ class BleReceive {
|
||||
this.setBleFormData(formData, f);
|
||||
|
||||
let recCnt = recArr.find(v => {
|
||||
return v.key.replaceAll('/', '').toLowerCase() == f.device.detailPageUrl
|
||||
.replaceAll('/', '').toLowerCase();
|
||||
return v.key.replace(/\//g, "").toLowerCase() == f.device.detailPageUrl
|
||||
.replace(/\//g, "").toLowerCase();
|
||||
});
|
||||
if (!recCnt) {
|
||||
|
||||
@ -318,8 +319,8 @@ class BleReceive {
|
||||
this.setBleFormData(receiveData, f);
|
||||
console.log("recArr=", recArr);
|
||||
let recCnt = recArr.find(v => {
|
||||
return v.key.replaceAll('/', '').toLowerCase() == f.device.detailPageUrl
|
||||
.replaceAll('/', '').toLowerCase();
|
||||
return v.key.replace(/\//g, "").toLowerCase() == f.device.detailPageUrl
|
||||
.replace(/\//g, "").toLowerCase();
|
||||
});
|
||||
if (!recCnt) {
|
||||
if (this.formData.staticWarn) { //有静止报警
|
||||
@ -470,7 +471,7 @@ class BleReceive {
|
||||
|
||||
let recCnt = recArr.find(v => {
|
||||
|
||||
return v.key.replaceAll('/', '').toLowerCase() === f.device.detailPageUrl.replaceAll(
|
||||
return v.key.replace(/\//g, "").toLowerCase() === f.device.detailPageUrl.replaceAll(
|
||||
'/', '').toLowerCase();
|
||||
});
|
||||
if (!recCnt) {
|
||||
@ -497,12 +498,12 @@ class BleReceive {
|
||||
|
||||
try {
|
||||
|
||||
console.log("str=",receive.str);
|
||||
// console.log("str=",receive.str);
|
||||
receiveData = JSON.parse(receive.str);
|
||||
|
||||
let recCnt = recArr.find(v => {
|
||||
return v.key.replaceAll('/', '').toLowerCase() == f.device.detailPageUrl
|
||||
.replaceAll('/', '').toLowerCase();
|
||||
return v.key.replace(/\//g, "").toLowerCase() == f.device.detailPageUrl
|
||||
.replace(/\//g, "").toLowerCase();
|
||||
});
|
||||
if (!recCnt) {
|
||||
if (receiveData.sta_PowerPercent<=20) {
|
||||
@ -521,7 +522,36 @@ class BleReceive {
|
||||
|
||||
}
|
||||
|
||||
Receive_100(receive,f,path,recArr){
|
||||
let receiveData={};
|
||||
|
||||
try {
|
||||
|
||||
// console.log("str=",receive.str);
|
||||
receiveData = JSON.parse(receive.str);
|
||||
|
||||
let recCnt = recArr.find(v => {
|
||||
return v.key.replace(/\//g, "").toLowerCase() == f.device.detailPageUrl
|
||||
.replace(/\//g, "").toLowerCase();
|
||||
});
|
||||
if (!recCnt) {
|
||||
if (receiveData.sta_battery<=20) {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "设备电量低",
|
||||
showCancel: false
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
receiveData = {};
|
||||
console.log("文本解析失败",error)
|
||||
}
|
||||
return receiveData;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
144
utils/Common.js
144
utils/Common.js
@ -1,10 +1,11 @@
|
||||
import request from "@/utils/request.js";
|
||||
export default {
|
||||
|
||||
audioStorageKey: "audioStorageKey",
|
||||
pcmStorageKey: "pcmStorageKey",
|
||||
guid: function generateUUID() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
const r = Math.random() * 16 | 0;
|
||||
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||
let r = Math.random() * 16 | 0;
|
||||
let v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
},
|
||||
@ -137,7 +138,7 @@ export default {
|
||||
checkLAN: function(succ, error) {
|
||||
uni.getNetworkType({
|
||||
success: (res) => {
|
||||
const networkType = res.networkType;
|
||||
let networkType = res.networkType;
|
||||
|
||||
|
||||
// 判断网络是否连接
|
||||
@ -182,7 +183,7 @@ export default {
|
||||
}
|
||||
|
||||
// 定义格式化映射
|
||||
const formatMap = {
|
||||
let formatMap = {
|
||||
'yyyy': date.getFullYear(),
|
||||
'MM': String(date.getMonth() + 1).padStart(2, '0'),
|
||||
'dd': String(date.getDate()).padStart(2, '0'),
|
||||
@ -203,15 +204,15 @@ export default {
|
||||
return formatMap[match];
|
||||
});
|
||||
},
|
||||
getdeviceShareId(id) {//获取设备分享信息
|
||||
return request({
|
||||
url: `/app/deviceShare/${id}`,
|
||||
method: 'get',
|
||||
})
|
||||
getdeviceShareId(id) { //获取设备分享信息
|
||||
return request({
|
||||
url: `/app/deviceShare/${id}`,
|
||||
method: 'get',
|
||||
})
|
||||
},
|
||||
getPermissions(type) {
|
||||
if (!type) {
|
||||
type='6170';
|
||||
type = '6170';
|
||||
}
|
||||
let array = [{
|
||||
value: "1",
|
||||
@ -222,7 +223,7 @@ export default {
|
||||
{
|
||||
value: "2",
|
||||
label: "激光模式",
|
||||
checked: false,
|
||||
checked: false,
|
||||
type: ['210', '6170']
|
||||
},
|
||||
{
|
||||
@ -260,53 +261,106 @@ export default {
|
||||
type: ['670']
|
||||
}
|
||||
]
|
||||
|
||||
let arr=[];
|
||||
|
||||
let arr = [];
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
let item = array[i];
|
||||
if(!item){
|
||||
if (!item) {
|
||||
continue;
|
||||
}
|
||||
if(!item.type){
|
||||
if (!item.type) {
|
||||
continue;
|
||||
}
|
||||
let typeContais=item.type.find(v=>{
|
||||
let typeContais = item.type.find(v => {
|
||||
return v.includes(type);
|
||||
});
|
||||
if(typeContais){
|
||||
let json={};
|
||||
Object.assign(json,item);
|
||||
if (typeContais) {
|
||||
let json = {};
|
||||
Object.assign(json, item);
|
||||
arr.push(json);
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
},
|
||||
//10进制转换为16进制字符串
|
||||
decimalToHexLittleEndian(num, byteCount,revers) {
|
||||
// 处理负数(如果需要支持负数,可先转为补码)
|
||||
if (num < 0) {
|
||||
num = 0xFFFFFFFF + num + 1;
|
||||
}
|
||||
|
||||
// 转为16进制,去除前缀0x,转为大写
|
||||
let hex = num.toString(16).toUpperCase();
|
||||
|
||||
// 计算需要补充的0的数量,确保每个字节占2位
|
||||
let padLength = (byteCount || Math.ceil(hex.length / 2) * 2) - hex.length;
|
||||
if (padLength > 0) {
|
||||
hex = '0'.repeat(padLength) + hex;
|
||||
}
|
||||
|
||||
// 分割为字节数组(每2位一个字节)
|
||||
const bytes = [];
|
||||
for (let i = 0; i < hex.length; i += 2) {
|
||||
bytes.push(hex.substr(i, 2));
|
||||
}
|
||||
|
||||
// 是否反转字节顺序(低位在前)并拼接
|
||||
if(revers){
|
||||
decimalToHexLittleEndian(num, byteCount, revers) {
|
||||
// 处理负数(如果需要支持负数,可先转为补码)
|
||||
if (num < 0) {
|
||||
num = 0xFFFFFFFF + num + 1;
|
||||
}
|
||||
|
||||
// 转为16进制,去除前缀0x,转为大写
|
||||
let hex = num.toString(16).toUpperCase();
|
||||
|
||||
// 计算需要补充的0的数量,确保每个字节占2位
|
||||
let padLength = (byteCount || Math.ceil(hex.length / 2) * 2) - hex.length;
|
||||
if (padLength > 0) {
|
||||
hex = '0'.repeat(padLength) + hex;
|
||||
}
|
||||
|
||||
// 分割为字节数组(每2位一个字节)
|
||||
let bytes = [];
|
||||
for (let i = 0; i < hex.length; i += 2) {
|
||||
bytes.push(hex.substr(i, 2));
|
||||
}
|
||||
|
||||
// 是否反转字节顺序(低位在前)并拼接
|
||||
if (revers) {
|
||||
return bytes.reverse().join('');
|
||||
}
|
||||
return bytes.join('');
|
||||
}
|
||||
return bytes.join('');
|
||||
},
|
||||
//将相对路径的文件移动到_downloads文件夹中
|
||||
moveFileToDownloads(tempFilePath) {
|
||||
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if(!tempFilePath){
|
||||
console.log("无文件需要移动");
|
||||
resolve(tempFilePath);
|
||||
return;
|
||||
}
|
||||
//本来就在此目录时直接返回
|
||||
if (tempFilePath.indexOf("_downloads") === 0) {
|
||||
console.log("文件已存在,无需移动");
|
||||
resolve(tempFilePath);
|
||||
return;
|
||||
}
|
||||
//不是app直接返回
|
||||
if (!uni.getSystemInfoSync().uniPlatform.includes('app')) {
|
||||
resolve('仅支持 App 端操作');
|
||||
return;
|
||||
}
|
||||
// console.log("tempFilePath=", tempFilePath);
|
||||
var srcPath = plus.io.convertLocalFileSystemURL(tempFilePath);
|
||||
// console.log("srcPath=", srcPath);
|
||||
plus.io.resolveLocalFileSystemURL(srcPath,
|
||||
(fileEntry) => {
|
||||
|
||||
plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS, (fs) => {
|
||||
// console.log("fs=",fs.name);
|
||||
// console.log("fs=",fs.root.fullPath);
|
||||
|
||||
fileEntry.moveTo(fs.root, fileEntry.name, (entry) => {
|
||||
console.log("entry=", entry);
|
||||
let relativePath = `_downloads/${entry.name}`;
|
||||
resolve(relativePath);
|
||||
|
||||
}, (ex) => {
|
||||
reject(ex)
|
||||
});
|
||||
|
||||
|
||||
}, (e) => {
|
||||
console.error("请求download目录失败 " + e);
|
||||
reject(e);
|
||||
});
|
||||
},
|
||||
(error) => {
|
||||
console.log('文件不存在/路径错误:', error.message); // 核心问题!
|
||||
}
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user