fix: 远距不导航 + 卡片按钮自适应 + 寻车换铃铛图标
- 直线距离 ≥ 20km 时卡片不再显示「导航」按钮(距离格同隐藏), 正在导航该车时仍保留「结束」 - startNavigation 兜底静默返回;_requestNavRoute 识别 too_far 不弹报错 - 后端 get_nav_route 调百度前按上限拦截(步行/骑行 200km、驾车 500km), 返回 error_kind=too_far 与中文提示;百度的 "the distance of path must less then 200Km" 也翻成中文 - 顺手修 get_nav_route 里 float(d_lng) -> float(dest_lng) 的笔误 (会让整个函数抛 UnboundLocalError) - 卡片顶部按钮是否收成纯图标改为实测:车牌被 ellipsis 截断才收, 同时考虑车牌长度与屏宽;resize 与「导航/结束」换字后重新测量 - 「寻车」放大镜换成描边铃铛 SVG,title 改为「寻车(响铃)」 测试:136 pytest + 30 node 全绿
This commit is contained in:
+22
-1
@@ -196,6 +196,8 @@
|
||||
function _navBtnText(text) {
|
||||
const el = document.getElementById("bike-nav-btn-text");
|
||||
if (el) el.textContent = text;
|
||||
// 「导航」和「结束」宽度不同,换字后重新量一次是否还放得下
|
||||
if (typeof _fitCardActions === "function") _fitCardActions();
|
||||
}
|
||||
|
||||
function _clearNavLayers() {
|
||||
@@ -549,7 +551,13 @@
|
||||
const json = await resp.json();
|
||||
const d = json && json.data;
|
||||
if (json.rtn_code !== 0 || !d || !d.points || !d.points.length) {
|
||||
throw new Error((json && json.message) || "没有拿到路线");
|
||||
const msg = (json && json.message) || "没有拿到路线";
|
||||
const err = new Error(msg);
|
||||
// 后端已挡掉超远距离;这里再认一次文案,前端可静默处理
|
||||
if (json && (json.error_kind === "too_far" || /太远|200Km/i.test(msg))) {
|
||||
err.tooFar = true;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
@@ -658,6 +666,13 @@
|
||||
if (!bike || !bike.latitude || !bike.longitude) {
|
||||
showToast("这辆车没有坐标,无法导航"); return;
|
||||
}
|
||||
// 兜底:太远就不导航(卡片上「导航」按钮本身已隐藏,正常点不到这里)。
|
||||
// 百度步行路线有 200km 上限,超了会返回 status=2 的英文报错,不要把它抛给用户。
|
||||
try {
|
||||
const dest = offsetCoord(bike.latitude, bike.longitude); // GCJ02 -> BD09
|
||||
const straight = calcDistance(me.lat, me.lng, dest.lat, dest.lng);
|
||||
if (Number.isFinite(straight) && straight >= MAX_WALK_DISTANCE_M) return;
|
||||
} catch (e) { /* 距离算不出来就照常尝试 */ }
|
||||
|
||||
if (_nav) stopNavigation();
|
||||
const epoch = ++_navEpoch;
|
||||
@@ -723,6 +738,12 @@
|
||||
} catch (err) {
|
||||
console.error("[导航] 失败", err);
|
||||
_navBanner(false);
|
||||
if (err && err.tooFar) {
|
||||
// 距离太远:静默退出,不弹报错(卡片上的「导航」按钮本来也已隐藏)
|
||||
_navBtnText("导航");
|
||||
_nav = null;
|
||||
return;
|
||||
}
|
||||
showToast("导航失败:" + (err && err.message ? err.message : "请稍后再试"));
|
||||
if (_nav && !_nav.ptsBD) _nav = null;
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user