Files
jobslink-user-clent/untils/tools.js

61 lines
1.5 KiB
JavaScript
Raw Normal View History

2024-04-25 11:42:21 +08:00
export function onDialingPhoneNumber(phone) {
2024-04-22 22:31:50 +08:00
return new Promise((resolve, reject) => {
uni.makePhoneCall({
phoneNumber: phone, // 电话号码
success: (res) => {
resolve(res)
},
fail: (err) => {
reject(err)
} // 失败
});
})
}
2024-04-25 11:42:21 +08:00
/**
* 个位数加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);
}
2024-04-22 22:31:50 +08:00
2024-04-30 11:20:41 +08:00
export function debounce(fun, delay) {
return function(args) {
let that = this;
let _args = args;
clearTimeout(fun.id);
fun.id = setTimeout(() => {
fun.call(that, _args)
}, delay)
}
}
2024-04-22 22:31:50 +08:00
export default {
2024-04-25 11:42:21 +08:00
onDialingPhoneNumber,
addZeroPrefix,
2024-04-30 11:20:41 +08:00
getDistanceFromLatLonInKm,
debounce
2024-04-22 22:31:50 +08:00
}