修复小程序内来馆地图导航
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
lyf
2026-07-11 17:24:45 +08:00
parent 12c0b5ede2
commit f9fefa11ef
12 changed files with 1161 additions and 146 deletions

View File

@@ -0,0 +1,40 @@
import type { WechatOpenLocationTarget } from '@/utils/wechatOpenLocationProtocol'
export type WechatOpenLocationResult =
| { status: 'opened' }
| { status: 'failed'; reason: 'api-failed' | 'timeout' }
const OPEN_LOCATION_TIMEOUT = 5000
export const openWechatHostLocation = (
target: WechatOpenLocationTarget
) => new Promise<WechatOpenLocationResult>((resolve) => {
let settled = false
const finish = (result: WechatOpenLocationResult) => {
if (settled) return
settled = true
clearTimeout(timeout)
resolve(result)
}
const timeout = setTimeout(() => {
finish({ status: 'failed', reason: 'timeout' })
}, OPEN_LOCATION_TIMEOUT)
try {
uni.openLocation({
latitude: target.latitude,
longitude: target.longitude,
name: target.name,
address: target.address || '',
scale: 18,
success: () => finish({ status: 'opened' }),
fail: (error) => {
console.error('打开地图位置失败:', error)
finish({ status: 'failed', reason: 'api-failed' })
}
})
} catch (error) {
console.error('调用微信地图能力失败:', error)
finish({ status: 'failed', reason: 'api-failed' })
}
})