This commit is contained in:
@@ -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',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Taro from "@tarojs/taro";
|
||||
import Taro from '@tarojs/taro';
|
||||
|
||||
export const BASE_URL = process.env.TARO_APP_API;
|
||||
|
||||
@@ -8,15 +8,15 @@ interface Res<T> {
|
||||
msg: string;
|
||||
}
|
||||
|
||||
type Method = "GET" | "POST" | "PUT" | "DELETE";
|
||||
type Method = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
||||
|
||||
// 忽略系统提示白名单
|
||||
const IGNORED_TIPS = ["/user/find/phone"];
|
||||
const IGNORED_TIPS = ['/user/find/phone', '/user/check/payPassword'];
|
||||
|
||||
const request = (
|
||||
url: string,
|
||||
data: object = {},
|
||||
method: Method = "GET"
|
||||
method: Method = 'GET',
|
||||
): Promise<Res<any>> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
Taro.request({
|
||||
@@ -24,15 +24,15 @@ const request = (
|
||||
data: data,
|
||||
method: method,
|
||||
header: {
|
||||
"content-type": "application/json",
|
||||
token: Taro.getStorageSync("token") || "",
|
||||
'content-type': 'application/json',
|
||||
token: Taro.getStorageSync('token') || '',
|
||||
},
|
||||
success: ({ data }) => {
|
||||
success: ({data}) => {
|
||||
if (data.code !== 200) {
|
||||
if (!IGNORED_TIPS.includes(url)) {
|
||||
Taro.showToast({
|
||||
title: data.msg,
|
||||
icon: "none",
|
||||
icon: 'none',
|
||||
});
|
||||
}
|
||||
reject(data);
|
||||
@@ -40,7 +40,7 @@ const request = (
|
||||
resolve(data);
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
fail: err => {
|
||||
reject(err);
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user