常规小优化
This commit is contained in:
@ -768,8 +768,9 @@ class BleHelper {
|
||||
} catch (convertException) {
|
||||
if (str && (str.trim().startsWith('{') || str.trim().startsWith('['))) {
|
||||
console.error("JSON解析失败(可能是格式错误的数据)", convertException);
|
||||
console.error("错误的数据", str);
|
||||
|
||||
}
|
||||
console.error("错误的数据", str);
|
||||
}
|
||||
|
||||
if (isUpdate) {
|
||||
@ -790,7 +791,7 @@ class BleHelper {
|
||||
str: str,
|
||||
hexs: hexs
|
||||
};
|
||||
// console.log("监听到特征值:", recData);
|
||||
console.log("监听到特征值:", recData);
|
||||
if (this.cfg.receivDataCallback) {
|
||||
|
||||
if (this.cfg.receivDataCallback.length > 0) {
|
||||
|
||||
165
utils/Common.js
165
utils/Common.js
@ -491,71 +491,85 @@ export default {
|
||||
return result;
|
||||
},
|
||||
formatTime(value, unit = 'minute') {
|
||||
// 边界处理:空值、0或负数
|
||||
if (!value || value <= 0) return '0秒';
|
||||
|
||||
// 将所有单位统一转换为分钟和总秒数
|
||||
let minutes;
|
||||
let totalSeconds;
|
||||
|
||||
switch (unit) {
|
||||
case 'second': // 秒
|
||||
minutes = value / 60;
|
||||
totalSeconds = value;
|
||||
break;
|
||||
case 'minute': // 分钟(默认)
|
||||
minutes = value;
|
||||
totalSeconds = value * 60;
|
||||
break;
|
||||
case 'hour': // 小时
|
||||
minutes = value * 60;
|
||||
totalSeconds = value * 3600;
|
||||
break;
|
||||
case 'day': // 天
|
||||
minutes = value * 24 * 60;
|
||||
totalSeconds = value * 86400;
|
||||
break;
|
||||
default:
|
||||
minutes = value;
|
||||
totalSeconds = value * 60;
|
||||
}
|
||||
|
||||
// 定义时间单位(分钟)
|
||||
const units = [
|
||||
{ label: '年', minutes: 365 * 24 * 60 },
|
||||
{ label: '月', minutes: 30 * 24 * 60 }, // 按30天简化计算
|
||||
{ label: '天', minutes: 24 * 60 },
|
||||
{ label: '小时', minutes: 60 },
|
||||
{ label: '分', minutes: 1 }
|
||||
];
|
||||
|
||||
let remaining = minutes;
|
||||
const parts = [];
|
||||
|
||||
for (const unitObj of units) {
|
||||
const val = Math.floor(remaining / unitObj.minutes);
|
||||
if (val > 0) {
|
||||
parts.push(`${val}${unitObj.label}`);
|
||||
remaining %= unitObj.minutes;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理剩余的秒数(remaining 现在是小于1分钟的分钟数)
|
||||
if (remaining > 0) {
|
||||
const seconds = Math.round(remaining * 60);
|
||||
if (seconds > 0) {
|
||||
parts.push(`${seconds}秒`);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有任何部分,返回总秒数
|
||||
if (parts.length === 0) {
|
||||
return `${Math.floor(totalSeconds)}秒`;
|
||||
}
|
||||
|
||||
return parts.join('');
|
||||
// 边界处理:空值、0或负数
|
||||
if (!value || value <= 0) return '0秒';
|
||||
|
||||
// 将所有单位统一转换为分钟和总秒数
|
||||
let minutes;
|
||||
let totalSeconds;
|
||||
|
||||
switch (unit) {
|
||||
case 'second': // 秒
|
||||
minutes = value / 60;
|
||||
totalSeconds = value;
|
||||
break;
|
||||
case 'minute': // 分钟(默认)
|
||||
minutes = value;
|
||||
totalSeconds = value * 60;
|
||||
break;
|
||||
case 'hour': // 小时
|
||||
minutes = value * 60;
|
||||
totalSeconds = value * 3600;
|
||||
break;
|
||||
case 'day': // 天
|
||||
minutes = value * 24 * 60;
|
||||
totalSeconds = value * 86400;
|
||||
break;
|
||||
default:
|
||||
minutes = value;
|
||||
totalSeconds = value * 60;
|
||||
}
|
||||
|
||||
// 定义时间单位(分钟)
|
||||
const units = [{
|
||||
label: '年',
|
||||
minutes: 365 * 24 * 60
|
||||
},
|
||||
{
|
||||
label: '月',
|
||||
minutes: 30 * 24 * 60
|
||||
}, // 按30天简化计算
|
||||
{
|
||||
label: '天',
|
||||
minutes: 24 * 60
|
||||
},
|
||||
{
|
||||
label: '小时',
|
||||
minutes: 60
|
||||
},
|
||||
{
|
||||
label: '分',
|
||||
minutes: 1
|
||||
}
|
||||
];
|
||||
|
||||
let remaining = minutes;
|
||||
const parts = [];
|
||||
|
||||
for (const unitObj of units) {
|
||||
const val = Math.floor(remaining / unitObj.minutes);
|
||||
if (val > 0) {
|
||||
parts.push(`${val}${unitObj.label}`);
|
||||
remaining %= unitObj.minutes;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理剩余的秒数(remaining 现在是小于1分钟的分钟数)
|
||||
if (remaining > 0) {
|
||||
const seconds = Math.round(remaining * 60);
|
||||
if (seconds > 0) {
|
||||
parts.push(`${seconds}秒`);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有任何部分,返回总秒数
|
||||
if (parts.length === 0) {
|
||||
return `${Math.floor(totalSeconds)}秒`;
|
||||
}
|
||||
|
||||
return parts.join('');
|
||||
},
|
||||
regeo(lon, lat) {
|
||||
regeo(lon, lat) { //逆地理,将坐标解析出地址
|
||||
return new Promise((resolve, reject) => {
|
||||
let url =
|
||||
'https://restapi.amap.com/v3/geocode/regeo?key=ca3af8a20d628897020893892bda5ae4&location=' +
|
||||
@ -579,6 +593,29 @@ export default {
|
||||
});
|
||||
});
|
||||
|
||||
},
|
||||
MapNavi(lon, lat, name, mapType) {//打开地图路线规划页面
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!lon || !lat) {
|
||||
reject("经纬度不能为空");
|
||||
return;
|
||||
}
|
||||
|
||||
let url = "";
|
||||
if (!mapType || mapType == 'amap') {
|
||||
let amapScheme = uni.getSystemInfoSync().platform === 'ios' ? 'iosamap://' : 'androidamap://';
|
||||
url = `${amapScheme}route/plan?sourceApplication=myapp&dlat=${lat}&dlon=${lon}&dname=${name}&dev=0&t=0`;
|
||||
} else {
|
||||
url =`baidumap://map/direction?destination=latlng:${lat},${lon}|name:${name}&coord_type=gcj02&src=myapp`
|
||||
}
|
||||
|
||||
plus.runtime.openURL(url, (ex) => {
|
||||
console.error("ex=",ex);
|
||||
reject("无法打开地图软件"+url);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
import config from '../config/index.js';
|
||||
export const env = 'development'; //production development //开发of线上 改这里就行
|
||||
export const env = 'production'; //production development //开发of线上 改这里就行
|
||||
const BASE = config[env];
|
||||
const request = (options) => {
|
||||
// console.log("options" + JSON.stringify(options), BASE.BASE_URL)
|
||||
|
||||
Reference in New Issue
Block a user