wip: 4.0
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-05-16 14:27:57 +08:00
parent b09c1d9537
commit 8f3b158032
72 changed files with 3931 additions and 2161 deletions

View File

@@ -1,11 +1,11 @@
import { showToast, navigateBack } from "@tarojs/taro";
import Taro from '@tarojs/taro';
// 经纬度计算距离
export function calculateDistance(
la1: number,
lo1: number,
la2: number,
lo2: number
lo2: number,
): any {
var radLat1 = (la1 * Math.PI) / 180.0;
var radLat2 = (la2 * Math.PI) / 180.0;
@@ -16,12 +16,12 @@ export function calculateDistance(
Math.asin(
Math.sqrt(
Math.pow(Math.sin(a / 2), 2) +
Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)
)
Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2),
),
);
s = s * 6378.137;
s = Math.round(s * 10000) / 10000;
return s.toFixed(2) + "km";
return s.toFixed(2) + 'km';
}
// 将角度转换为弧度
@@ -36,20 +36,50 @@ interface UrlParams {
bid?: string;
}
export function parseQueryString(url: string) {
const queryString = url.split("?")[1];
const queryString = url.split('?')[1];
if (!queryString) {
return {};
}
const keyValuePairs = queryString.split("&");
const keyValuePairs = queryString.split('&');
const result: UrlParams = {};
keyValuePairs.forEach((keyValue) => {
const [key, value] = keyValue.split("=");
keyValuePairs.forEach(keyValue => {
const [key, value] = keyValue.split('=');
result[key] = decodeURIComponent(value);
});
return result;
}
// 格式化时间
export function formatTime(time: number): string {
const date = new Date(time);
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
const hour = date.getHours();
const minute = date.getMinutes();
const second = date.getSeconds();
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
}
// 字符串脱敏
export function maskString(str: string, start: number, end: number): string {
const maskLength = Math.min(str.length, end) - Math.max(0, start);
const maskedPart = '*'.repeat(maskLength);
const beginning = str.slice(0, Math.max(0, start));
const endPart = str.slice(end);
return beginning + maskedPart + endPart;
}
// tips
export function showTips(msg: string) {
Taro.showToast({
title: msg,
icon: 'none',
});
}