fix: 地图key增加。

This commit is contained in:
tianyongbao
2026-06-17 21:46:14 +08:00
parent b0fbf6261d
commit 8bdb9699e5
2 changed files with 59 additions and 9 deletions

View File

@@ -73,6 +73,16 @@
"mp-toutiao" : { "mp-toutiao" : {
"usingComponents" : true "usingComponents" : true
}, },
/* H5 */
"h5" : {
"sdkConfigs" : {
"maps" : {
"qqmap" : {
"key" : "7C7BZ-VY6L4-Q2LUN-KTJDR-HL7K6-RRFNN"
}
}
}
},
"uniStatistics" : { "uniStatistics" : {
"enable" : false "enable" : false
}, },

View File

@@ -547,30 +547,53 @@ onLoad((option) => {
form.value.latitude = null form.value.latitude = null
} }
function stopLocationLoading() {
locationLoading.value = false
}
function loadCurrentCoordinate() { function loadCurrentCoordinate() {
if (typeof uni.getLocation !== 'function') { if (typeof uni.getLocation !== 'function') {
locationLoading.value = false stopLocationLoading()
proxy.$refs['uToast'].show({ proxy.$refs['uToast'].show({
message: '当前端暂不支持定位', type: 'warning' message: '当前端暂不支持定位', type: 'warning'
}) })
return return
} }
// 超时保护10秒后强制结束 loading
const timer = setTimeout(() => {
stopLocationLoading()
proxy.$refs['uToast'].show({
message: '定位超时,请检查定位权限或网络后重试', type: 'warning'
})
}, 10000)
uni.getLocation({ uni.getLocation({
type: 'gcj02', type: 'gcj02',
isHighAccuracy: true, isHighAccuracy: true,
success(res) { success(res) {
clearTimeout(timer)
applyLocationResult(res) applyLocationResult(res)
proxy.$refs['uToast'].show({ proxy.$refs['uToast'].show({
message: '已获取当前位置坐标,可补充地点名称', type: 'success' message: '已获取当前位置坐标,可补充地点名称', type: 'success'
}) })
}, },
fail() { fail(err) {
proxy.$refs['uToast'].show({ clearTimeout(timer)
message: '定位失败,请检查定位权限后重试', type: 'warning' const msg = (err && err.errMsg) ? err.errMsg : ''
}) if (msg.indexOf('auth') !== -1 || msg.indexOf('deny') !== -1 || msg.indexOf('permission') !== -1) {
proxy.$refs['uToast'].show({
message: '定位权限被拒绝,请到系统设置中开启定位权限', type: 'warning'
})
} else {
proxy.$refs['uToast'].show({
message: '定位失败请检查GPS或网络后重试', type: 'warning'
})
}
}, },
complete() { complete() {
locationLoading.value = false clearTimeout(timer)
stopLocationLoading()
} }
}) })
} }
@@ -580,24 +603,41 @@ onLoad((option) => {
return return
} }
locationLoading.value = true locationLoading.value = true
// 总体超时保护15秒后强制重置 loading 状态,防止按钮永久卡住
const safeTimer = setTimeout(() => {
if (locationLoading.value) {
stopLocationLoading()
proxy.$refs['uToast'].show({
message: '定位服务响应超时,已自动重置,请重试', type: 'warning'
})
}
}, 15000)
if (typeof uni.chooseLocation !== 'function') { if (typeof uni.chooseLocation !== 'function') {
clearTimeout(safeTimer)
loadCurrentCoordinate() loadCurrentCoordinate()
return return
} }
uni.chooseLocation({ uni.chooseLocation({
success(res) { success(res) {
clearTimeout(safeTimer)
applyLocationResult(res) applyLocationResult(res)
proxy.$refs['uToast'].show({ proxy.$refs['uToast'].show({
message: '定位成功', type: 'success' message: '定位成功', type: 'success'
}) })
locationLoading.value = false stopLocationLoading()
}, },
fail(err) { fail(err) {
const errMsg = err && err.errMsg ? err.errMsg : '' clearTimeout(safeTimer)
const errMsg = (err && err.errMsg) ? err.errMsg : ''
// 用户取消选择,直接重置 loading不降级
if (errMsg.indexOf('cancel') !== -1) { if (errMsg.indexOf('cancel') !== -1) {
locationLoading.value = false stopLocationLoading()
return return
} }
// 其他失败降级到坐标定位
loadCurrentCoordinate() loadCurrentCoordinate()
} }
}) })