完成100
This commit is contained in:
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