diff --git a/app.py b/app.py index 644c5c5..a5f9746 100644 --- a/app.py +++ b/app.py @@ -709,6 +709,14 @@ def bootstrap(): except Exception as exc: print(f"[启动] 选主失败,按 leader 处理(单进程部署可忽略): {exc}") is_leader = True + # 测试/工具场景:只要数据库和路由,不启动任何后台线程(避免采集线程写库 + # 干扰用例的统计断言) + if os.environ.get("XBCR_DISABLE_BACKGROUND") == "1": + print("[启动] XBCR_DISABLE_BACKGROUND=1:只初始化数据库,不启动后台线程") + with _bootstrap_lock: + _bootstrap_done = True + return True + if not is_leader: print("[启动] 本进程不是 leader:跳过采集/巡检/定时器/调度线程") print("[启动] bootstrap 完成(web worker)") diff --git a/routes/map_api.py b/routes/map_api.py index 8e13f94..988725c 100644 --- a/routes/map_api.py +++ b/routes/map_api.py @@ -460,8 +460,7 @@ def api_user_info(): MAP_ASSETS = ( "css/map.css", "css/bike-clusters.css", "css/map-settings.css", "css/ui-system.css", "js/ui-motion.js", "js/qrcode.min.js", "js/coordtransform.js", "js/bike-clusters.js", - "js/settings-pages.js", "js/navigation.js", "js/share.js", "js/subscribe.js", - "js/src/core/geo.js", "js/map.js", + "js/settings-pages.js", "js/src/core/geo.js", "dist/app.js", ) diff --git a/src-ts/compat/globals.ts b/src-ts/compat/globals.ts index 93bea5e..e0af6a3 100644 --- a/src-ts/compat/globals.ts +++ b/src-ts/compat/globals.ts @@ -5,6 +5,7 @@ * 函数清单由 tools/gen.mjs 从源文件里抓,正常情况下与 map.js 的全局面 1:1 对应。 */ import { Geo, offsetCoord, calcDistance } from "../core/geo"; +import { S } from "../core/state"; import { _fitCardActions, closeCard, showBikeDetail, updateRingProgress, viewBikeDetailFromOrder, viewBikeDetailFromOrderModal } from "../card/bike-card"; import { describeTokenExpiry, escHtml, fmtClock, fmtDuration, fmtLocalTime, fmtOrderTime, fmtRemainShort, fmtTime, friendlyError, remainingTimeText, rideProgressText } from "../core/format"; import { shareApi } from "../core/http"; @@ -317,3 +318,7 @@ window.Geo = Geo; window.offsetCoord = offsetCoord; window.calcDistance = calcDistance; +/* 排障用:原版 91 个顶层 let/var 都是全局词法绑定,控制台可直接读写; + bundle 里它们收在 state 对象内(ESM 不能给 import 绑定赋值), + 这里把 state 本身挂出去,保持同样的可观测性。 */ +(window as any).S = S; diff --git a/src-ts/nav/walk-route.ts b/src-ts/nav/walk-route.ts index 35f82f6..517478e 100644 --- a/src-ts/nav/walk-route.ts +++ b/src-ts/nav/walk-route.ts @@ -90,7 +90,14 @@ export async function refineWalkRoute(bike) { const walk = new BMapGL.WalkingRoute(S.map, { renderOptions: { map: null, panel: null }, onSearchComplete: res => { - if (!res || res.getStatus() !== 0) return finish(null); + // 退化路线(起点≈终点)时 res 可能是空壳、没有 getStatus, + // 直接调用会抛未捕获 TypeError(与原 JS 版同步修复) + let status = -1; + try { + status = (res && typeof (res as any).getStatus === "function") + ? (res as any).getStatus() : -1; + } catch (e) { status = -1; } + if (status !== 0) return finish(null); try { const p = res.getPlan(0); const d = parseWalkDistance(p.getDistance()); diff --git a/static/dist/README.md b/static/dist/README.md index 33b1013..6c417fd 100644 --- a/static/dist/README.md +++ b/static/dist/README.md @@ -132,3 +132,11 @@ MAP_ASSETS = ( 除此之外,块内正文与 `static/js/*.js` **逐行一致**(`node src-ts/tools/gen.mjs` 的 保真度报告:6144 行搬运,归一化后只剩上述 1 行结构差异)。 + +## 补充(验收后修正) + +- **状态可观测性**:原版 91 个顶层 `let/var` 是全局词法绑定,控制台能直接读写。 + bundle 里它们收进 `core/state.ts` 的 `S` 对象,并额外执行 `window.S = S;`, + 排障时用 `S.selectedBike` / `S.orderCountdownSeconds` 等价替代。 +- **退化路线**:`nav/walk-route.ts` 的 `onSearchComplete` 对 `res.getStatus()` + 增加了存在性判断(起点≈终点时上游会返回空壳),原 JS 版已同步修掉这条历史 TypeError。 diff --git a/static/dist/app.js b/static/dist/app.js index d15dc65..6a01bbf 100644 --- a/static/dist/app.js +++ b/static/dist/app.js @@ -432,7 +432,13 @@ const walk = new BMapGL.WalkingRoute(S.map, { renderOptions: { map: null, panel: null }, onSearchComplete: (res) => { - if (!res || res.getStatus() !== 0) return finish(null); + let status = -1; + try { + status = res && typeof res.getStatus === "function" ? res.getStatus() : -1; + } catch (e) { + status = -1; + } + if (status !== 0) return finish(null); try { const p = res.getPlan(0); const d = parseWalkDistance(p.getDistance()); @@ -5726,6 +5732,7 @@ window.Geo = Geo; window.offsetCoord = offsetCoord; window.calcDistance = calcDistance; + window.S = S; // src-ts/main.ts function bootstrap() { diff --git a/static/js/navigation.js b/static/js/navigation.js index 38bc8be..198fd44 100644 --- a/static/js/navigation.js +++ b/static/js/navigation.js @@ -85,7 +85,14 @@ const walk = new BMapGL.WalkingRoute(map, { renderOptions: { map: null, panel: null }, onSearchComplete: res => { - if (!res || res.getStatus() !== 0) return finish(null); + // 退化路线(起点≈终点)时 res 可能是空壳、没有 getStatus, + // 直接调用会抛未捕获 TypeError(两版都有的历史问题) + let status = -1; + try { + status = (res && typeof res.getStatus === "function") + ? res.getStatus() : -1; + } catch (e) { status = -1; } + if (status !== 0) return finish(null); try { const p = res.getPlan(0); const d = parseWalkDistance(p.getDistance()); diff --git a/templates/map.html b/templates/map.html index f2db887..3f36c04 100644 --- a/templates/map.html +++ b/templates/map.html @@ -970,10 +970,8 @@ - - - - + +