1
0
forked from dyf/APP

100J更新兼容性

This commit is contained in:
微微一笑
2026-03-19 15:18:59 +08:00
parent 3a9de3078c
commit 44607f9b0c
2 changed files with 670 additions and 670 deletions

View File

@ -1,180 +1,180 @@
// eslint-disable // eslint-disable
export const isObject = (obj) => { export const isObject = (obj) => {
return obj return obj
? Object.prototype.toString.call(obj) === "[object Object]" ? Object.prototype.toString.call(obj) === "[object Object]"
: false; : false;
}; };
export const isArray = (arr) => { export const isArray = (arr) => {
return arr ? Array.isArray(arr) : false; return arr ? Array.isArray(arr) : false;
}; };
/** /**
* handle async await * handle async await
* @param {*} promise promise * @param {*} promise promise
*/ */
export const awaitWrap = (promise) => export const awaitWrap = (promise) =>
promise.then((res) => [null, res]).catch((err) => [err, {}]); promise.then((res) => [null, res]).catch((err) => [err, {}]);
/** /**
* 深拷贝 * 深拷贝
* @param {*} source * @param {*} source
*/ */
export const deepClone = (source) => { export const deepClone = (source) => {
if (!isObject(source) && !isArray(source)) return source; if (!isObject(source) && !isArray(source)) return source;
const targetObj = isArray(source) ? [] : {}; // 判断复制的目标是数组还是对象 const targetObj = isArray(source) ? [] : {}; // 判断复制的目标是数组还是对象
for (let keys in source) { for (let keys in source) {
// 遍历目标 // 遍历目标
if (source.hasOwnProperty(keys)) { if (source.hasOwnProperty(keys)) {
if (source[keys] && typeof source[keys] === "object") { if (source[keys] && typeof source[keys] === "object") {
// 如果值是对象,就递归一下 // 如果值是对象,就递归一下
targetObj[keys] = isArray(source[keys]) ? [] : {}; targetObj[keys] = isArray(source[keys]) ? [] : {};
targetObj[keys] = deepClone(source[keys]); targetObj[keys] = deepClone(source[keys]);
} else { } else {
// 如果不是,就直接赋值 // 如果不是,就直接赋值
targetObj[keys] = source[keys]; targetObj[keys] = source[keys];
} }
} }
} }
return targetObj; return targetObj;
}; };
/** /**
* @description JS对象深度合并 * @description JS对象深度合并
* @param {object} target 需要拷贝的对象 * @param {object} target 需要拷贝的对象
* @param {object} source 拷贝的来源对象 * @param {object} source 拷贝的来源对象
* @returns {object|boolean} 深度合并后的对象或者false入参有不是对象 * @returns {object|boolean} 深度合并后的对象或者false入参有不是对象
*/ */
export const deepMerge = (target = {}, source = {}) => { export const deepMerge = (target = {}, source = {}) => {
target = deepClone(target); target = deepClone(target);
if (typeof target !== "object" || typeof source !== "object") return false; if (typeof target !== "object" || typeof source !== "object") return false;
for (const prop in source) { for (const prop in source) {
if (!source.hasOwnProperty(prop)) continue; if (!source.hasOwnProperty(prop)) continue;
if (prop in target) { if (prop in target) {
if (typeof target[prop] !== "object") { if (typeof target[prop] !== "object") {
target[prop] = source[prop]; target[prop] = source[prop];
} else if (typeof source[prop] !== "object") { } else if (typeof source[prop] !== "object") {
target[prop] = source[prop]; target[prop] = source[prop];
} else if (target[prop].concat && source[prop].concat) { } else if (target[prop].concat && source[prop].concat) {
target[prop] = target[prop].concat(source[prop]); target[prop] = target[prop].concat(source[prop]);
} else { } else {
target[prop] = deepMerge(target[prop], source[prop]); target[prop] = deepMerge(target[prop], source[prop]);
} }
} else { } else {
target[prop] = source[prop]; target[prop] = source[prop];
} }
} }
return target; return target;
}; };
/** /**
* 将File对象转为 Blob Url * 将File对象转为 Blob Url
* @param {File} File对象 * @param {File} File对象
* @returns Blob Url * @returns Blob Url
*/ */
export const fileToBlob = (file) => { export const fileToBlob = (file) => {
if (!file) return; if (!file) return;
const fileType = file.type; const fileType = file.type;
const blob = new Blob([file], { type: fileType || 'application/*' }); const blob = new Blob([file], { type: fileType || 'application/*' });
const blobUrl = window.URL.createObjectURL(blob); const blobUrl = window.URL.createObjectURL(blob);
return blobUrl; return blobUrl;
}; };
/** /**
* 将File对象转为 base64 * 将File对象转为 base64
* @param {File} File对象 * @param {File} File对象
* @returns base64 * @returns base64
*/ */
export const fileToBase64 = (file) => { export const fileToBase64 = (file) => {
if (!file) return; if (!file) return;
return new Promise((r, j) => { return new Promise((r, j) => {
const reader = new FileReader(); const reader = new FileReader();
reader.onloadend = () => { reader.onloadend = () => {
const base64String = reader.result; const base64String = reader.result;
r(base64String); r(base64String);
}; };
reader.onerror = () => { reader.onerror = () => {
j({ mode: 'fileToBase64', data: { errMsg: 'File to base64 fail.' } }); j({ mode: 'fileToBase64', data: { errMsg: 'File to base64 fail.' } });
}; };
reader.readAsDataURL(file); reader.readAsDataURL(file);
}); });
}; };
/** /**
* base64转临时路径(改自https://github.com/zhetengbiji/image-tools/blob/master/index.js) * base64转临时路径(改自https://github.com/zhetengbiji/image-tools/blob/master/index.js)
* @param base64 * @param base64
* @returns * @returns
*/ */
function dataUrlToBase64(str) { function dataUrlToBase64(str) {
var array = str.split(','); var array = str.split(',');
return array[array.length - 1]; return array[array.length - 1];
}; };
function biggerThan(v1, v2) { function biggerThan(v1, v2) {
var v1Array = v1.split('.'); var v1Array = v1.split('.');
var v2Array = v2.split('.'); var v2Array = v2.split('.');
var update = false; var update = false;
for (var index = 0; index < v2Array.length; index++) { for (var index = 0; index < v2Array.length; index++) {
var diff = v1Array[index] - v2Array[index]; var diff = v1Array[index] - v2Array[index];
if (diff !== 0) { if (diff !== 0) {
update = diff > 0; update = diff > 0;
break; break;
} }
} }
return update; return update;
}; };
var index = 0; var index = 0;
function getNewFileId() { function getNewFileId() {
return Date.now() + String(index++); return Date.now() + String(index++);
}; };
export const base64ToPath = (base64, name = '') => { export const base64ToPath = (base64, name = '') => {
return new Promise((r, j) => { return new Promise((r, j) => {
if (typeof plus !== 'object') { if (typeof plus !== 'object') {
return j(new Error('not support')); return j(new Error('not support'));
} }
var fileName = ''; var fileName = '';
if (name) { if (name) {
const names = name.split('.'); const names = name.split('.');
const extName = names.splice(-1); const extName = names.splice(-1);
fileName = `${names.join('.')}-${getNewFileId()}.${extName}`; fileName = `${names.join('.')}-${getNewFileId()}.${extName}`;
} else { } else {
const names = base64.split(',')[0].match(/data\:\S+\/(\S+);/); const names = base64.split(',')[0].match(/data\:\S+\/(\S+);/);
if (!names) { if (!names) {
j(new Error('base64 error')); j(new Error('base64 error'));
} }
const extName = names[1]; const extName = names[1];
fileName = `${getNewFileId()}.${extName}`; fileName = `${getNewFileId()}.${extName}`;
} }
var basePath = '_doc'; var basePath = '_doc';
var dirPath = 'uniapp_temp'; var dirPath = 'uniapp_temp';
var filePath = `${basePath}/${dirPath}/${fileName}`; var filePath = `${basePath}/${dirPath}/${fileName}`;
if (!biggerThan(plus.os.name === 'Android' ? '1.9.9.80627' : '1.9.9.80472', plus.runtime.innerVersion)) { if (!biggerThan(plus.os.name === 'Android' ? '1.9.9.80627' : '1.9.9.80472', plus.runtime.innerVersion)) {
plus.io.resolveLocalFileSystemURL(basePath, function (entry) { plus.io.resolveLocalFileSystemURL(basePath, function (entry) {
entry.getDirectory(dirPath, { entry.getDirectory(dirPath, {
create: true, create: true,
exclusive: false, exclusive: false,
}, function (entry) { }, function (entry) {
entry.getFile(fileName, { entry.getFile(fileName, {
create: true, create: true,
exclusive: false, exclusive: false,
}, function (entry) { }, function (entry) {
entry.createWriter(function (writer) { entry.createWriter(function (writer) {
writer.onwrite = function () { writer.onwrite = function () {
r(filePath); r(filePath);
} }
writer.onerror = j; writer.onerror = j;
writer.seek(0); writer.seek(0);
writer.writeAsBinary(dataUrlToBase64(base64)); writer.writeAsBinary(dataUrlToBase64(base64));
}, j) }, j)
}, j) }, j)
}, j) }, j)
}, j) }, j)
return; return;
} }
var bitmap = new plus.nativeObj.Bitmap(fileName); var bitmap = new plus.nativeObj.Bitmap(fileName);
bitmap.loadBase64Data(base64, function () { bitmap.loadBase64Data(base64, function () {
bitmap.save(filePath, {}, function () { bitmap.save(filePath, {}, function () {
bitmap.clear(); bitmap.clear();
r(filePath); r(filePath);
}, function (error) { }, function (error) {
bitmap.clear(); bitmap.clear();
j(error); j(error);
}); });
}, function (error) { }, function (error) {
bitmap.clear(); bitmap.clear();
j(error); j(error);
}); });
}); });
}; };

View File

@ -1,491 +1,491 @@
import request from "@/utils/request.js"; import request from "@/utils/request.js";
export default { export default {
audioStorageKey: "audioStorageKey", audioStorageKey: "audioStorageKey",
pcmStorageKey: "pcmStorageKey", pcmStorageKey: "pcmStorageKey",
guid: function generateUUID() { guid: function generateUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
let r = Math.random() * 16 | 0; let r = Math.random() * 16 | 0;
let v = c === 'x' ? r : (r & 0x3 | 0x8); let v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16); return v.toString(16);
}); });
}, },
alert: function(title, content, callback) { alert: function(title, content, callback) {
if (!title) { if (!title) {
title = '提示' title = '提示'
} }
if (!content) { if (!content) {
content = title; content = title;
} }
uni.showModal({ uni.showModal({
title: title, title: title,
content: content, content: content,
success: function(res) { success: function(res) {
if (res.confirm) { if (res.confirm) {
console.log('用户点击确定'); console.log('用户点击确定');
} else if (res.cancel) { } else if (res.cancel) {
console.log('用户点击取消'); console.log('用户点击取消');
} }
if (callback) { if (callback) {
callback(res); callback(res);
} }
} }
}); });
}, },
showLoading: function(title, mask) { showLoading: function(title, mask) {
uni.showLoading({ uni.showLoading({
title: title, title: title,
mask: mask, mask: mask,
}) })
}, },
hideLoading: function() { hideLoading: function() {
uni.hideLoading(); uni.hideLoading();
}, },
showToast: function(title, mask, duration, callback) { showToast: function(title, mask, duration, callback) {
if (!duration) { if (!duration) {
duration = 1500; duration = 1500;
} }
if (mask == undefined) { if (mask == undefined) {
mask = false; mask = false;
} }
uni.showToast({ uni.showToast({
title: title, title: title,
mask: mask, mask: mask,
duration: duration, duration: duration,
callback: callback, callback: callback,
icon: 'none' icon: 'none'
}) })
}, },
GetData: function(url, data, method, contentType, succ, err, complete) { GetData: function(url, data, method, contentType, succ, err, complete) {
var these = this; var these = this;
if (!url) { if (!url) {
console.error("url为空"); console.error("url为空");
return; return;
} }
if (url.toLowerCase().indexOf('http://') == -1 || url.toLowerCase().indexOf('https://') == -1) { if (url.toLowerCase().indexOf('http://') == -1 || url.toLowerCase().indexOf('https://') == -1) {
if (url.indexOf('/') == 0) { if (url.indexOf('/') == 0) {
url = url.substr(1, url.length - 1); url = url.substr(1, url.length - 1);
} }
let ServerPath = these.DevApi; let ServerPath = these.DevApi;
if (these.Version === 'Dev') { if (these.Version === 'Dev') {
ServerPath = these.DevApi; ServerPath = these.DevApi;
} else if (these.Version === 'Uat') { } else if (these.Version === 'Uat') {
ServerPath = these.UatApi; ServerPath = these.UatApi;
} else if (these.Version === 'Relese') { } else if (these.Version === 'Relese') {
ServerPath = these.ReleseApi; ServerPath = these.ReleseApi;
} else { } else {
these.DevApi these.DevApi
} }
url = ServerPath + url; url = ServerPath + url;
} }
var these = this; var these = this;
if (!method) { if (!method) {
method = 'POST'; method = 'POST';
} }
method = method.toUpperCase(); method = method.toUpperCase();
if (!contentType) { if (!contentType) {
contentType = 'application/json;charset=UTF-8'; contentType = 'application/json;charset=UTF-8';
} }
these.checkLAN( these.checkLAN(
function() { function() {
these.showLoading('请稍候..', true); these.showLoading('请稍候..', true);
setTimeout(function() { setTimeout(function() {
uni.request({ uni.request({
url: url, url: url,
data: data, data: data,
header: { header: {
"Content-Type": contentType "Content-Type": contentType
}, },
method: method, method: method,
timeout: 60000, timeout: 60000,
dataType: 'json', dataType: 'json',
success: function(json) { success: function(json) {
if (succ) { if (succ) {
succ(json); succ(json);
} }
}, },
fail: function(ex) { fail: function(ex) {
if (err) { if (err) {
err(ex); err(ex);
} }
}, },
complete: function() { complete: function() {
if (complete) { if (complete) {
complete(); complete();
} }
} }
}); });
}, 0); }, 0);
} }
, ,
function() { function() {
these.showToast('无网络连接'); these.showToast('无网络连接');
}); });
}, },
checkLAN: function(succ, error) { checkLAN: function(succ, error) {
uni.getNetworkType({ uni.getNetworkType({
success: (res) => { success: (res) => {
let networkType = res.networkType; let networkType = res.networkType;
// 判断网络是否连接 // 判断网络是否连接
if (networkType === 'none') { if (networkType === 'none') {
console.error('无网络连接') console.error('无网络连接')
if (error) { if (error) {
error(); error();
} }
} else { } else {
if (succ) { if (succ) {
succ(); succ();
} }
} }
}, },
fail: (err) => { fail: (err) => {
console.error('获取网络状态失败:', err); console.error('获取网络状态失败:', err);
if (error) { if (error) {
error(); error();
} }
} }
}); });
}, },
DateFormat: function(date, format) { DateFormat: function(date, format) {
if (!date) { if (!date) {
date = new Date(); date = new Date();
} }
if (!format) { if (!format) {
format = 'yyyy-MM-dd HH:mm:ss'; format = 'yyyy-MM-dd HH:mm:ss';
} }
// 处理参数默认值 // 处理参数默认值
if (typeof date === 'string' || typeof date === 'number') { if (typeof date === 'string' || typeof date === 'number') {
date = new Date(date); date = new Date(date);
} }
date = date instanceof Date ? date : new Date(); date = date instanceof Date ? date : new Date();
format = format || 'yyyy-MM-dd'; format = format || 'yyyy-MM-dd';
// 检查日期是否有效 // 检查日期是否有效
if (isNaN(date.getTime())) { if (isNaN(date.getTime())) {
return 'Invalid Date'; return 'Invalid Date';
} }
// 定义格式化映射 // 定义格式化映射
let formatMap = { let formatMap = {
'yyyy': date.getFullYear(), 'yyyy': date.getFullYear(),
'MM': String(date.getMonth() + 1).padStart(2, '0'), 'MM': String(date.getMonth() + 1).padStart(2, '0'),
'dd': String(date.getDate()).padStart(2, '0'), 'dd': String(date.getDate()).padStart(2, '0'),
'HH': String(date.getHours()).padStart(2, '0'), 'HH': String(date.getHours()).padStart(2, '0'),
'mm': String(date.getMinutes()).padStart(2, '0'), 'mm': String(date.getMinutes()).padStart(2, '0'),
'ss': String(date.getSeconds()).padStart(2, '0'), 'ss': String(date.getSeconds()).padStart(2, '0'),
'SSS': String(date.getMilliseconds()).padStart(3, '0'), 'SSS': String(date.getMilliseconds()).padStart(3, '0'),
'M': date.getMonth() + 1, 'M': date.getMonth() + 1,
'd': date.getDate(), 'd': date.getDate(),
'H': date.getHours(), 'H': date.getHours(),
'm': date.getMinutes(), 'm': date.getMinutes(),
's': date.getSeconds(), 's': date.getSeconds(),
'S': date.getMilliseconds() 'S': date.getMilliseconds()
}; };
// 替换格式字符串中的占位符 // 替换格式字符串中的占位符
return format.replace(/(yyyy|MM|dd|HH|mm|ss|SSS|M|d|H|m|s|S)/g, (match) => { return format.replace(/(yyyy|MM|dd|HH|mm|ss|SSS|M|d|H|m|s|S)/g, (match) => {
return formatMap[match]; return formatMap[match];
}); });
}, },
getdeviceShareId(id) { //获取设备分享信息 getdeviceShareId(id) { //获取设备分享信息
return request({ return request({
url: `/app/deviceShare/${id}`, url: `/app/deviceShare/${id}`,
method: 'get', method: 'get',
}) })
}, },
getPermissions(type) { getPermissions(type) {
if (!type) { if (!type) {
type = '6170'; type = '6170';
} }
let array = [{ let array = [{
value: "1", value: "1",
label: "灯光模式", label: "灯光模式",
checked: false, checked: false,
type: ['6170', '670','102','6155','650','7305','6075'] type: ['6170', '670','102','6155','650','7305','6075']
}, },
{ {
value: "2", value: "2",
label: "激光模式", label: "激光模式",
checked: false, checked: false,
type: ['6170','6075'] type: ['6170','6075']
}, },
{ {
value: "3", value: "3",
label: "开机画面", label: "开机画面",
checked: false, checked: false,
type: ['210', '6170', '670','6155','650','7305','6075'] type: ['210', '6170', '670','6155','650','7305','6075']
}, },
{ {
value: "4", value: "4",
label: "人员信息登记", label: "人员信息登记",
checked: false, checked: false,
type: ['210', '6170', '670','6155','650','7305','6075'] type: ['210', '6170', '670','6155','650','7305','6075']
}, },
{ {
value: "5", value: "5",
label: "发送信息", label: "发送信息",
checked: false, checked: false,
type: ['210', '6170', '670','6075'] type: ['210', '6170', '670','6075']
}, },
{ {
value: "6", value: "6",
label: "产品信息", label: "产品信息",
checked: false, checked: false,
type: ['210', '6170', '670'] type: ['210', '6170', '670']
}, { }, {
value: "41", value: "41",
label: "静电探测", label: "静电探测",
checked: false, checked: false,
type: ['670','650'] type: ['670','650']
}, { }, {
value: "42", value: "42",
label: "SOS", label: "SOS",
checked: false, checked: false,
type: ['670','4877','6075'] type: ['670','4877','6075']
}, },
{ {
value: "43", value: "43",
label: "联机设备", label: "联机设备",
checked: false, checked: false,
type: ['210'] type: ['210']
}, },
{ {
value: "44", value: "44",
label: "报警声音", label: "报警声音",
checked: false, checked: false,
type: ['210'] type: ['210']
}, },
{ {
value: "45", value: "45",
label: "自动报警", label: "自动报警",
checked: false, checked: false,
type: ['210'] type: ['210']
}, },
{ {
value: "46", value: "46",
label: "手动报警", label: "手动报警",
checked: false, checked: false,
type: ['210','102'] type: ['210','102']
}, },
{ {
value: "47", value: "47",
label: "报警时长", label: "报警时长",
checked: false, checked: false,
type: ['210'] type: ['210']
}, },
{ {
value: "48", value: "48",
label: "物体感应", label: "物体感应",
checked: false, checked: false,
type: ['102'] type: ['102']
}, },
{ {
value: "49", value: "49",
label: "联机模式", label: "联机模式",
checked: false, checked: false,
type: ['102'] type: ['102']
}, },
{ {
value: "50", value: "50",
label: "报警模式", label: "报警模式",
checked: false, checked: false,
type: ['100','100J'] type: ['100','100J']
}, },
{ {
value: "51", value: "51",
label: "警示灯", label: "警示灯",
checked: false, checked: false,
type: ['100','100J'] type: ['100','100J']
}, },
{ {
value: "52", value: "52",
label: "语音管理", label: "语音管理",
checked: false, checked: false,
type: ['100','100J'] type: ['100','100J']
}, },
{ {
value: "53", value: "53",
label: "箭头模式", label: "箭头模式",
checked: false, checked: false,
type: ['4877'] type: ['4877']
}, },
{ {
value: "54", value: "54",
label: "配组设置", label: "配组设置",
checked: false, checked: false,
type: ['4877'] type: ['4877']
}, },
{ {
value: "55", value: "55",
label: "修改信道", label: "修改信道",
checked: false, checked: false,
type: ['4877'] type: ['4877']
}, },
{ {
value: "56", value: "56",
label: "灯光类型设置", label: "灯光类型设置",
checked: false, checked: false,
type: ['100J'] type: ['100J']
}, },
] ]
let arr = []; let arr = [];
for (let i = 0; i < array.length; i++) { for (let i = 0; i < array.length; i++) {
let item = array[i]; let item = array[i];
if (!item) { if (!item) {
continue; continue;
} }
if (!item.type) { if (!item.type) {
continue; continue;
} }
let typeContais = item.type.find(v => { let typeContais = item.type.find(v => {
return v.includes(type); return v.includes(type);
}); });
if (typeContais) { if (typeContais) {
let json = {}; let json = {};
Object.assign(json, item); Object.assign(json, item);
arr.push(json); arr.push(json);
} }
} }
return arr; return arr;
}, },
//10进制转换为16进制字符串 //10进制转换为16进制字符串
decimalToHexLittleEndian(num, byteCount, revers) { decimalToHexLittleEndian(num, byteCount, revers) {
// 处理负数(如果需要支持负数,可先转为补码) // 处理负数(如果需要支持负数,可先转为补码)
if (num < 0) { if (num < 0) {
num = 0xFFFFFFFF + num + 1; num = 0xFFFFFFFF + num + 1;
} }
// 转为16进制去除前缀0x转为大写 // 转为16进制去除前缀0x转为大写
let hex = num.toString(16).toUpperCase(); let hex = num.toString(16).toUpperCase();
// 计算需要补充的0的数量确保每个字节占2位 // 计算需要补充的0的数量确保每个字节占2位
let padLength = (byteCount || Math.ceil(hex.length / 2) * 2) - hex.length; let padLength = (byteCount || Math.ceil(hex.length / 2) * 2) - hex.length;
if (padLength > 0) { if (padLength > 0) {
hex = '0'.repeat(padLength) + hex; hex = '0'.repeat(padLength) + hex;
} }
// 分割为字节数组每2位一个字节 // 分割为字节数组每2位一个字节
let bytes = []; let bytes = [];
for (let i = 0; i < hex.length; i += 2) { for (let i = 0; i < hex.length; i += 2) {
bytes.push(hex.substr(i, 2)); bytes.push(hex.substr(i, 2));
} }
// 是否反转字节顺序(低位在前)并拼接 // 是否反转字节顺序(低位在前)并拼接
if (revers) { if (revers) {
return bytes.reverse().join(''); return bytes.reverse().join('');
} }
return bytes.join(''); return bytes.join('');
}, },
//将相对路径的文件移动到_downloads文件夹中 //将相对路径的文件移动到_downloads文件夹中
moveFileToDownloads(tempFilePath) { moveFileToDownloads(tempFilePath) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if(!tempFilePath){ if(!tempFilePath){
console.log("无文件需要移动"); console.log("无文件需要移动");
resolve(tempFilePath); resolve(tempFilePath);
return; return;
} }
//本来就在此目录时直接返回 //本来就在此目录时直接返回
if (tempFilePath.indexOf("_downloads") === 0) { if (tempFilePath.indexOf("_downloads") === 0) {
console.log("文件已存在,无需移动"); console.log("文件已存在,无需移动");
resolve(tempFilePath); resolve(tempFilePath);
return; return;
} }
//不是app直接返回 //不是app直接返回
if (!uni.getSystemInfoSync().uniPlatform.includes('app')) { if (!uni.getSystemInfoSync().uniPlatform.includes('app')) {
resolve('仅支持 App 端操作'); resolve('仅支持 App 端操作');
return; return;
} }
// console.log("tempFilePath=", tempFilePath); // console.log("tempFilePath=", tempFilePath);
var srcPath = plus.io.convertLocalFileSystemURL(tempFilePath); var srcPath = plus.io.convertLocalFileSystemURL(tempFilePath);
// console.log("srcPath=", srcPath); // console.log("srcPath=", srcPath);
plus.io.resolveLocalFileSystemURL(srcPath, plus.io.resolveLocalFileSystemURL(srcPath,
(fileEntry) => { (fileEntry) => {
plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS, (fs) => { plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS, (fs) => {
// console.log("fs=",fs.name); // console.log("fs=",fs.name);
// console.log("fs=",fs.root.fullPath); // console.log("fs=",fs.root.fullPath);
fileEntry.moveTo(fs.root, fileEntry.name, (entry) => { fileEntry.moveTo(fs.root, fileEntry.name, (entry) => {
console.log("entry=", entry); console.log("entry=", entry);
let relativePath = `_downloads/${entry.name}`; let relativePath = `_downloads/${entry.name}`;
resolve(relativePath); resolve(relativePath);
}, (ex) => { }, (ex) => {
reject(ex) reject(ex)
}); });
}, (e) => { }, (e) => {
console.error("请求download目录失败 " + e); console.error("请求download目录失败 " + e);
reject(e); reject(e);
}); });
}, },
(error) => { (error) => {
console.log('文件不存在/路径错误:', error.message); // 核心问题! console.log('文件不存在/路径错误:', error.message); // 核心问题!
} }
); );
}); });
}, },
getOSAndUpload(){ getOSAndUpload(){
let os=uni.getSystemInfoSync().platform; let os=uni.getSystemInfoSync().platform;
let url='' let url=''
if(os==='ios'){ if(os==='ios'){
url='https://apps.apple.com/cn/app/星汉物联/id6752555460' url='https://apps.apple.com/cn/app/星汉物联/id6752555460'
} }
else if(os==='android'){ else if(os==='android'){
url='https://www.pgyer.com/xhwl'; url='https://www.pgyer.com/xhwl';
} }
return {os:os,url:url}; return {os:os,url:url};
}, },
//将点阵数据转换成RGB565 //将点阵数据转换成RGB565
convertToRGB565(pixels, type) { convertToRGB565(pixels, type) {
if (!type) { if (!type) {
type = 'rgb'; type = 'rgb';
} }
const result = new Uint16Array(pixels.length / 4); const result = new Uint16Array(pixels.length / 4);
let index = 0; let index = 0;
for (let i = 0; i < pixels.length; i += 4) { for (let i = 0; i < pixels.length; i += 4) {
let r = pixels[i]; let r = pixels[i];
let g = pixels[i + 1]; let g = pixels[i + 1];
let b = pixels[i + 2]; let b = pixels[i + 2];
let a = pixels[i + 3]; let a = pixels[i + 3];
if (type == 'bgr') { if (type == 'bgr') {
result[index++] = ((b & 0xF8) << 8) | ((g & 0xFC) << 3) | (r >> 3); result[index++] = ((b & 0xF8) << 8) | ((g & 0xFC) << 3) | (r >> 3);
} else { } else {
result[index++] = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3); result[index++] = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
} }
} }
return result; return result;
} }
} }