feat: 前端拆分 + 跟随式导航 + 百度步行路线 + 管理员追溯

## 前端拆分(map.js 6215 -> 4776 行)
- 新增 navigation.js(跟随式导航 + 步行距离精算)、share.js、subscribe.js
- map.html 与 MAP_ASSETS 版本哈希同步纳入;test_order_return.cjs 按模块顺序加载
- 修复拆分带来的 SUB_WEEKDAYS 重复声明与 let map TDZ(延后绑定拖动事件)

## 导航与步行
- walk_route.py:百度 directionlite 接入,coord_type/ret_coordtype 均为 GCJ02,
  SN 签名与接口路径解耦(riding/driving 也能用),3 QPS 节流 + 7 天缓存 + 本地估算兜底
- 跟随式导航:行进方向朝上(setHeading(-方位角),实测逆符号),
  当前位置锁下方 80%,已走灰/剩余蓝,偏航 60m 重算(12s 冷却),
  拖动后显示「返回导航」8 秒自动回正,亚克力导航条 + 分阶段指引「前方 X 米 XX」
- 罗盘箭头跟手机朝向(无权限则朝行进方向),目的地换 SVG 定位针

## 管理员
- /api/admin/rentals 返回起终点标签与坐标;订单表新增「起点 → 终点」列
  (老订单无标签时退回坐标)
- 用户/订单/共享表的邮箱可点击,右侧贴着被点邮箱弹出上游信息浮层
  (trueName/学校/学院/专业/年级/学号),支持空间不足翻转与点外收起

## 修复
- 自己账号开锁成功时车牌被清空:先存局部 code 再 closeUnlockConfirm,
  避免 activeRental/localStorage 写入 null(新增回归测试)
- state=2 文案统一为「损坏」,不再误写「已被预约」

## 文档
- README:保留期 3 天 -> 30 天,Leaflet -> BMapGL,补拆分后模块结构
- docs/:百度 GL 官方类参考(离线 HTML)+ 踩坑速查

测试:136 pytest + 30 node 全绿
This commit is contained in:
zzy
2026-11-15 00:33:31 +08:00
parent 75f040d90a
commit e51d77d42a
16 changed files with 16499 additions and 1115 deletions
+32 -1
View File
@@ -3,7 +3,11 @@ const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const source = fs.readFileSync(path.join(__dirname, '../static/js/map.js'), 'utf8');
// map.js 已拆分为多个模块(navigation/share/subscribe/map),按 HTML 里的顺序加载
const MODULES = ['navigation.js', 'share.js', 'subscribe.js', 'map.js'];
const source = MODULES.map(name =>
fs.readFileSync(path.join(__dirname, '../static/js', name), 'utf8')
).join('\n;\n');
async function environment({ dependencies = true } = {}) {
const elements = new Map(), requests = [], notices = [], events = {};
@@ -162,3 +166,30 @@ test('countdown accounts for background throttling instead of decrementing only
assert.equal(e.element('order-countdown').textContent, '本轮剩余 9:55');
assert.match(e.element('order-final-time').textContent, /第 1\/1 轮/);
});
// 回归:自己账号开锁成功时,closeUnlockConfirm 会清空 unlockPendingCode,
// 本地 activeRental / localStorage 绝不能把车牌写成 null。
test('self unlock keeps the bike code after the confirm dialog clears the pending code', async () => {
const e = await environment();
const store = {};
e.context.localStorage.setItem = (key, value) => { store[key] = value; };
e.context.fetch = async (url) => {
if (url === '/api/order/unlock') {
return { json: async () => ({ rtn_code: 0, order_id: '9001',
data: { remaining: 1140, end_time: '2026-01-01 00:19:00' } }) };
}
return { json: async () => ({ rtn_code: 0, data: {} }) };
};
vm.runInContext(`
unlockPendingCode = '51241';
unlockPendingPosition = { lat: 36.5, lng: 116.7 };
unlockChoice = { mode: 'self' };
`, e.context);
await vm.runInContext('doUnlockBike()', e.context);
// closeUnlockConfirm 已经执行过,全局变量确实被清空了
assert.equal(vm.runInContext('unlockPendingCode', e.context), null);
const stored = JSON.parse(store.xbniu_rental_key || '{}');
assert.equal(stored.bike_code, '51241');
});