liujie
2026-09-17 819124be8f16794d409a67f58d5257aef37d9b64
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function normalizeCoordinate(value) {
  const number = Number(value)
  return Number.isFinite(number) ? number : 0
}
 
export function hasMeetingPointLocation(point = {}) {
  return Boolean(normalizeCoordinate(point.latitude || point.meetingPointLatitude) && normalizeCoordinate(point.longitude || point.meetingPointLongitude))
}
 
export function buildMeetingPointPayload(point = {}) {
  const latitude = normalizeCoordinate(point.latitude || point.meetingPointLatitude)
  const longitude = normalizeCoordinate(point.longitude || point.meetingPointLongitude)
 
  return {
    scenicId: point.scenicId || '',
    scenicName: point.scenicName || '',
    meetingPointId: point.id || point.meetingPointId || '',
    meetingPointName: point.name || point.meetingPointName || '汇合点',
    meetingPointAddress: point.address || point.meetingPointAddress || '',
    latitude,
    longitude
  }
}
 
export function buildMeetingPointCircles(point = {}) {
  const payload = buildMeetingPointPayload(point)
  if (!hasMeetingPointLocation(payload)) {
    return []
  }
 
  return [
    {
      latitude: payload.latitude,
      longitude: payload.longitude,
      radius: 36,
      strokeWidth: 4,
      color: '#4d8fe899',
      fillColor: '#4d8fe833'
    }
  ]
}
 
export function openMeetingPointPage(point = {}) {
  const payload = buildMeetingPointPayload(point)
  if (!hasMeetingPointLocation(payload)) {
    uni.showToast({
      title: '汇合点坐标暂未配置',
      icon: 'none'
    })
    return
  }
  openSystemLocation(payload).catch((error) => {
    console.log('Open meeting point location failed', error)
    uni.showToast({
      title: '暂时无法打开地图导航',
      icon: 'none'
    })
  })
}
 
export function parseMeetingPointPayload(payload = '') {
  if (!payload) {
    return null
  }
 
  try {
    const parsed = JSON.parse(decodeURIComponent(payload))
    return buildMeetingPointPayload(parsed)
  } catch (error) {
    console.log('Parse meeting point payload failed', error)
    return null
  }
}
 
export function openSystemLocation(point = {}) {
  const payload = buildMeetingPointPayload(point)
  if (!hasMeetingPointLocation(payload)) {
    uni.showToast({
      title: '汇合点坐标暂未配置',
      icon: 'none'
    })
    return Promise.reject(new Error('Missing meeting point coordinates'))
  }
 
  return new Promise((resolve, reject) => {
    uni.openLocation({
      latitude: payload.latitude,
      longitude: payload.longitude,
      scale: 18,
      name: payload.meetingPointName,
      address: payload.meetingPointAddress,
      success() {
        resolve(payload)
      },
      fail(error) {
        reject(error)
      }
    })
  })
}