tool.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. return new Promise((resolve, reject) => {
  17. if (tel) {
  18. uni.makePhoneCall({
  19. phoneNumber: tel + '',
  20. success: res => {
  21. resolve()
  22. },
  23. fail: () => {
  24. reject()
  25. }
  26. });
  27. } else {
  28. uni.showToast({
  29. title: '暂未设置电话'
  30. });
  31. }
  32. })
  33. }
  34. // 导航
  35. export const getMapLocation = (parmas = {}) => {
  36. const { latitude, longitude, name, detailedAddress } = parmas
  37. uni.openLocation({
  38. latitude: parseFloat(latitude), // 要去的地址经度,浮点数
  39. longitude: parseFloat(longitude), // 要去的地址纬度,浮点数
  40. name: name, // 位置名
  41. address: detailedAddress, // 要去的地址详情说明
  42. scale: 16, // 地图缩放级别,整形值,范围从1~28。默认为最大
  43. });
  44. }
  45. export const getLocation = () => {
  46. return new Promise((resolve, reject) => {
  47. try {
  48. uni.getLocation({
  49. type: 'wgs84', // 返回可以用于uni.openLocation的经纬度
  50. success: (res) => {
  51. console.log("getLocation 1111111111111111111= ", res)
  52. // this.selfLatitude = res.longitude;
  53. // this.selfLongitude = res.latitude;
  54. resolve(res)
  55. },
  56. fail: (err) => {
  57. console.log('获取位置失败2 :', err);
  58. reject()
  59. }
  60. });
  61. } catch (error) {
  62. console.log('获取位置失败 1:', error);
  63. //TODO handle the exception
  64. }
  65. })
  66. }