Files
jobslink-user-clent/untils/tools.js
2024-04-25 11:42:21 +08:00

49 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export function onDialingPhoneNumber(phone) {
return new Promise((resolve, reject) => {
uni.makePhoneCall({
phoneNumber: phone, // 电话号码
success: (res) => {
resolve(res)
},
fail: (err) => {
reject(err)
} // 失败
});
})
}
/**
* 个位数加0前缀
* @param {*} number
* @returns
*/
export function addZeroPrefix(number) {
return number < 10 ? `0${number}` : number
}
export function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) {
const R = 6371; // 地球平均半径,单位为公里
const dLat = deg2rad(lat2 - lat1);
const dLon = deg2rad(lon2 - lon1);
const a =
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
Math.sin(dLon / 2) * Math.sin(dLon / 2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
const d = R * c;
return {
km: d,
m: d * 1000
};
}
// 将角度转换为弧度
function deg2rad(deg) {
return deg * (Math.PI / 180);
}
export default {
onDialingPhoneNumber,
addZeroPrefix,
getDistanceFromLatLonInKm
}