From 0ca50707556bf7d5b55791a7089f7bb2ff36ca2c Mon Sep 17 00:00:00 2001 From: kangwenjing <1138819403@qq.com> Date: Thu, 26 Mar 2026 17:33:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=9A=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/lib/tencentMap.ts | 22 +++++++++++++++++++++- frontend/src/pages/Work.tsx | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/tencentMap.ts b/frontend/src/lib/tencentMap.ts index 3212aa10..cf7302ad 100644 --- a/frontend/src/lib/tencentMap.ts +++ b/frontend/src/lib/tencentMap.ts @@ -87,7 +87,7 @@ export async function resolveTencentMapLocation() { return bestResult; } - throw browserError || sdkError || new Error("定位失败,请稍后重试。"); + throw new Error(buildLocationFailureMessage(browserError, sdkError)); } async function resolveWithTencentSdk() { @@ -379,6 +379,26 @@ function getBrowserLocationErrorMessage(error?: GeolocationPositionError | null) } } +function buildLocationFailureMessage(browserError: Error | null, sdkError: Error | null) { + const reasons: string[] = []; + + if (!window.isSecureContext) { + reasons.push("当前页面未被浏览器视为安全环境,请使用已信任的 HTTPS 地址打开。"); + } + if (browserError) { + reasons.push(`浏览器定位:${browserError.message}`); + } + if (sdkError) { + reasons.push(`腾讯定位:${sdkError.message}`); + } + + if (!reasons.length) { + return "定位失败,请稍后重试。"; + } + + return reasons.join(";"); +} + export function wgs84ToGcj02(latitude: number, longitude: number) { if (isOutsideChina(latitude, longitude)) { return { latitude, longitude }; diff --git a/frontend/src/pages/Work.tsx b/frontend/src/pages/Work.tsx index f1a2fdb8..6d7d6e78 100644 --- a/frontend/src/pages/Work.tsx +++ b/frontend/src/pages/Work.tsx @@ -354,7 +354,7 @@ export default function Work() { setCheckInError(""); setRefreshingLocation(true); if (!window.isSecureContext && location.hostname !== "localhost" && location.hostname !== "127.0.0.1") { - setLocationHint("当前地址不是 HTTPS,手机浏览器会拦截定位。请使用 HTTPS 地址打开。"); + setLocationHint("当前页面未被浏览器视为安全环境,常见原因是 HTTP 或证书未被手机信任。请使用已信任的 HTTPS 地址打开。"); setRefreshingLocation(false); return; }