tool.js 929 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // 计算点位距离
  2. export const distanceCalculate = (num) => {
  3. const num_ = Number(num);
  4. if (typeof num_ === 'number') {
  5. if (num_ < 1000) {
  6. return `${num_.toFixed(1)}米`
  7. } else {
  8. const n = (num_ / 1000).toFixed(1);
  9. return `${n}公里`
  10. };
  11. }
  12. return num_ || num
  13. }
  14. // 拨打电话
  15. export const PhoneCall = (tel) => {
  16. if (tel) {
  17. uni.makePhoneCall({
  18. phoneNumber: tel + ''
  19. });
  20. } else {
  21. uni.showToast({
  22. title: '暂未设置电话'
  23. });
  24. }
  25. }
  26. // 导航
  27. export const getMapLocation = (parmas = {}) => {
  28. const { latitude, longitude, name, detailedAddress } = parmas
  29. uni.openLocation({
  30. latitude: parseFloat(latitude), // 要去的地址经度,浮点数
  31. longitude: parseFloat(longitude), // 要去的地址纬度,浮点数
  32. name: name, // 位置名
  33. address: detailedAddress, // 要去的地址详情说明
  34. scale: 16, // 地图缩放级别,整形值,范围从1~28。默认为最大
  35. });
  36. }