index.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * 获取当前页面路径
  3. * @returns 当前页面路径
  4. */
  5. export function getCurrentPath() {
  6. const pages = getCurrentPages()
  7. const currentPage = pages[pages.length - 1]
  8. return currentPage.route || ''
  9. }
  10. /**
  11. * 检测当前环境是否为微信小程序
  12. */
  13. export function isWxMiniProgram() {
  14. return new Promise((resolve, reject) => {
  15. const apltInfo = uni.getDeviceInfo()
  16. console.log(apltInfo, '当前环境=======================')
  17. if (apltInfo.platform === 'windows') {
  18. useGlobalToast().show('不支持电脑操作地址,请使用手机打开')
  19. reject(new Error('不支持电脑操作地址,请使用手机打开'))
  20. }
  21. resolve(1)
  22. })
  23. }
  24. /**
  25. * 将角度转换为弧度
  26. */
  27. function toRadians(degrees: number): number {
  28. return degrees * Math.PI / 180
  29. }
  30. /**
  31. * 将弧度转换为角度
  32. */
  33. function toDegrees(radians: number): number {
  34. return radians * 180 / Math.PI
  35. }
  36. /**
  37. * 计算两个经纬度的中心点(球面插值法)
  38. * 适用于任意距离,考虑地球曲率,更精确
  39. *
  40. * @param pointA 第一个经纬度坐标
  41. * @param pointB 第二个经纬度坐标
  42. * @returns 中心点经纬度坐标
  43. */
  44. export function calculateCenterPointSpherical(
  45. pointA: { lat: number, lng: number },
  46. pointB: { lat: number, lng: number },
  47. ): { lat: number, lng: number } {
  48. // 将经纬度转换为弧度
  49. const lat1 = toRadians(pointA.lat)
  50. const lng1 = toRadians(pointA.lng)
  51. const lat2 = toRadians(pointB.lat)
  52. const lng2 = toRadians(pointB.lng)
  53. // 计算纬度的差值
  54. const dLng = lng2 - lng1
  55. // 使用球面插值公式计算中心点
  56. const Bx = Math.cos(lat2) * Math.cos(dLng)
  57. const By = Math.cos(lat2) * Math.sin(dLng)
  58. const centerLat = Math.atan2(
  59. Math.sin(lat1) + Math.sin(lat2),
  60. Math.sqrt((Math.cos(lat1) + Bx) * (Math.cos(lat1) + Bx) + By * By),
  61. )
  62. const centerLng = lng1 + Math.atan2(By, Math.cos(lat1) + Bx)
  63. // 将结果转换回角度
  64. return {
  65. lat: toDegrees(centerLat),
  66. lng: toDegrees(centerLng),
  67. }
  68. }