feat(前端): TypeScript 重写版(esbuild IIFE 产物,暂不接管线上)

- 新增 src-ts/(22 个 .ts / 7792 行):按 core / map / card / order / nav / share /
  subscribe / ui / compat 分层,types 里有 BMapGL 与 API 响应声明
- compat/globals.ts 是唯一挂 window 的地方(292 个),覆盖模板 139 处内联事件
- esbuild 产出 static/dist/app.js(226.6 KiB,IIFE,es2019)+ README(构建/切换/回滚)
- 构建可复现:node esbuild.config.mjs、node --check、npx tsc --noEmit 均通过
- .gitignore 增加 node_modules/ 与 static/dist/*.map(sourcemap 可重生成,不入库)
- 暂不改 templates/map.html 与 MAP_ASSETS:等独立核对通过再切换,回滚=换回四个 script
This commit is contained in:
zzy
2026-11-16 10:44:11 +08:00
parent f8db1240b1
commit 8ece55983a
32 changed files with 16155 additions and 0 deletions
+84
View File
@@ -0,0 +1,84 @@
/* 由 static/js/{navigation,share,subscribe,map}.js 逐块搬运而来;正文与原实现一致。 */
// static/js/map.js:674-678
export function fmtLocalTime(ts) {
const d = new Date(ts * 1000);
const p = n => String(n).padStart(2, "0");
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
}
// static/js/map.js:679-685
export function describeTokenExpiry(expiry) {
const remain = expiry.expireAt - Math.floor(Date.now() / 1000);
const when = fmtLocalTime(expiry.expireAt);
const left = remain <= 0 ? "已过期" : `约剩 ${fmtRemainShort(remain)}`;
const note = expiry.source === "iat+30d" ? "(按签发时间 +30 天推算)" : "";
return { text: `该凭据(登录态)有效期至 ${when}${note},${left}`, remain };
}
// static/js/map.js:686-692
export function fmtRemainShort(remain) {
const dd = Math.floor(remain / 86400), hh = Math.floor((remain % 86400) / 3600),
mm = Math.floor((remain % 3600) / 60);
if (dd >= 1) return `${dd} 天${hh ? " " + hh + " 小时" : ""}`;
if (hh >= 1) return `${hh} 小时${mm ? " " + mm + " 分" : ""}`;
return `${Math.max(1, mm)} 分钟`;
}
// static/js/map.js:865-868
export function escHtml(s) {
return String(s == null ? "" : s).replace(/[&<>"']/g,
c => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[c]));
}
// static/js/map.js:869-872
export function fmtTime(t) {
if (!t) return "";
return escHtml(String(t).replace("T", " ").slice(0, 16));
}
// static/js/map.js:1748-1754
export function rideProgressText(summary) {
const current = Math.max(1, Number(summary.current_round) || 1);
const total = Math.max(current, Number(summary.total_rounds) || current);
const end = String(summary.final_end_time || summary.end_time || "").match(/(?:T|\s)(\d{2}:\d{2})/);
const phase = summary.auto_return ? "自动还车已开启" : "手动还车";
return `第 ${current}/${total} 轮 · ${phase}` + (end ? ` · 预计 ${end[1]} 结束` : "");
}
// static/js/map.js:1756-1759
export function remainingTimeText(seconds) {
const remaining = Math.max(0, Math.ceil(Number(seconds) || 0));
return `${Math.floor(remaining / 60)}:${String(remaining % 60).padStart(2, "0")}`;
}
// static/js/map.js:2668-2673
export function fmtDuration(seconds) {
if (seconds === null || seconds === undefined) return "--";
const mins = Math.round(seconds / 60);
if (mins < 60) return `${mins} 分钟`;
return `${Math.floor(mins / 60)} 小时 ${mins % 60} 分钟`;
}
// static/js/map.js:2674-2677
export function fmtOrderTime(s) {
if (!s) return "--";
return String(s).replace("T", " ").slice(5, 16); // MM-DD HH:MM
}
// static/js/map.js:2678-2681
export function fmtClock(s) {
if (!s) return "--";
return String(s).slice(11, 16); // HH:MM
}
// static/js/map.js:4532-4541
export function friendlyError(e) {
const msg = (e && e.message) || "";
if (/Unexpected token|is not valid JSON|JSON\.parse/i.test(msg)) {
return "服务响应异常,请稍后重试";
}
return msg || "网络错误,请重试";
}
// ========== Token失效弹窗 ==========
// 仅在真正检测到微信凭据失效时调用;带冷却时间,避免轮询/刷新反复打扰