This commit is contained in:
cansnow
2026-01-01 04:15:30 +08:00
parent 09c7889525
commit 78386d4cc1
75 changed files with 1995 additions and 1715 deletions
+125 -2
View File
@@ -4,6 +4,7 @@ import base from '@/common/config';
//import store from "@/store";
import IMSDK from "openim-uniapp-polyfill";
import CryptoJS from 'crypto-js';
import md5 from "md5";
import {downloadFile} from "@/uni_modules/network-manage";
@@ -233,8 +234,6 @@ const get_absolute_path = (fn)=>{
}
const pendingDownloads = new Map();
const cacheFile = (url, saveDir,progressCallback) => {
let cacheDir = plus.io.convertLocalFileSystemURL(`_doc/{{dir}}/{{key}}.{{ext}}`);
cacheDir = cacheDir.replace('apps/'+plus.runtime.appid+'/doc','cache');
return new Promise(async (resolve, reject) => {
try {
if(!url || !url.startsWith('http')){
@@ -246,6 +245,8 @@ const cacheFile = (url, saveDir,progressCallback) => {
if(url.toLowerCase().indexOf('.mp4')!==-1){
ext = "mp4";
}
let cacheDir = plus.io.convertLocalFileSystemURL(`_doc/{{dir}}/{{key}}.{{ext}}`);
cacheDir = cacheDir.replace('apps/'+plus.runtime.appid+'/doc','cache');
const cacheFilePath = cacheDir.replace('{{dir}}',saveDir)
.replace('{{key}}',key)
.replace('{{ext}}',ext);
@@ -315,8 +316,130 @@ const cacheFile = (url, saveDir,progressCallback) => {
}
});
};
const toMapAPP = (latitude,longitude,name) =>{
let url = "";
if (plus.os.name == "Android") {//判断是安卓端
plus.nativeUI.actionSheet({//选择菜单
title: "选择地图应用",
cancel: "取消",
buttons: [{title: "腾讯地图"},{title: "百度地图"}, {title: "高德地图"}]
}, function(e) {
switch (e.index) {
//下面是拼接url,不同系统以及不同地图都有不同的拼接字段
case 1:
//注意referer=xxx的xxx替换成你在腾讯地图开发平台申请的key
url = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=xxx`;
break;
case 2:
url = `baidumap://map/marker?location=${latitude},${longitude}&title=${name}&coord_type=gcj02&src=andr.baidu.openAPIdemo`;
break;
case 3:
url = `androidamap://viewMap?sourceApplication=appname&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
break;
default:
break;
}
if (url != "") {
url = encodeURI(url);
//plus.runtime.openURL(url,function(e){})调起手机APP应用
plus.runtime.openURL(url, function(e) {
plus.nativeUI.alert("本机未安装指定的地图应用");
});
}
})
} else {
// iOS上获取本机是否安装了百度高德地图,需要在manifest里配置
// 在manifest.json文件app-plus->distribute->apple->urlschemewhitelist节点下添加
//(如urlschemewhitelist:["iosamap","baidumap"]
plus.nativeUI.actionSheet({
title: "选择地图应用",
cancel: "取消",
buttons: [{title: "腾讯地图"},{title: "百度地图"}, {title: "高德地图"}]
}, function(e) {
switch (e.index) {
case 1:
url = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=xxx`;
break;
case 2:
url = `baidumap://map/marker?location=${latitude},${longitude}&title=${name}&content=${name}&src=ios.baidu.openAPIdemo&coord_type=gcj02`;
break;
case 3:
url = `iosamap://viewMap?sourceApplication=applicationName&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
break;
default:
break;
}
if (url != "") {
url = encodeURI(url);
plus.runtime.openURL(url, function(e) {
plus.nativeUI.alert("本机未安装指定的地图应用");
});
}
})
}
}
/**
* AES 加密函数
* @param {String|Object|Array} str 要加密的内容
* @param {String} key 加密密钥
* @returns {String} 加密后的Base64字符串
*/
const aesencode = (str, key = 'muNcJyt0XXV6faCGe41VSIaf0ecZeW2jXmgpL0Ak93Kbwjyr')=> {
// 如果是对象或数组,转为JSON字符串
if (typeof str === 'object') {
str = JSON.stringify(str);
}
// 使用SHA-256哈希处理密钥
const hashedKey = CryptoJS.SHA256(key);
// 生成IV(前16字节)
const iv = CryptoJS.lib.WordArray.create(hashedKey.words.slice(0, 4));
// 加密
const encrypted = CryptoJS.AES.encrypt(str,hashedKey,{
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
// 返回Base64编码结果
const _str = encrypted.toString();
return _str.replace(/\+/ig,'%2b');
}
/**
* AES 解密函数
* @param {String} str 要解密的Base64字符串
* @param {String} key 解密密钥
* @returns {String} 解密后的原始字符串
*/
const aesdecode = (str, key = 'muNcJyt0XXV6faCGe41VSIaf0ecZeW2jXmgpL0Ak93Kbwjyr') => {
// 使用SHA-256哈希处理密钥
const hashedKey = CryptoJS.SHA256(key);
// 生成IV(前16字节)
const iv = CryptoJS.lib.WordArray.create(hashedKey.words.slice(0, 4));
str = str.replace(/\%2b/ig,'+');
// 解密
const decrypted = CryptoJS.AES.decrypt(str,hashedKey,{
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
// 转为UTF-8字符串
let _str = decrypted.toString(CryptoJS.enc.Utf8);
console.log(_str);
const obj = _str.startsWith('{') || _str.startsWith('[') ? JSON.parse(_str) : _str;
return obj;
}
export default{
aesdecode,
aesencode,
toMapAPP,
cacheFile,
fileExsit,
get_absolute_path,