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:
@@ -0,0 +1,155 @@
|
||||
/* 车辆订阅:停车点提醒与定时用车(规则的增删改查)。
|
||||
* 从 static/js/map.js 拆出。 */
|
||||
|
||||
|
||||
// ========== 订阅提醒(我的 → 车辆订阅) ==========
|
||||
let subscribeLocations = [];
|
||||
const SUB_WEEKDAYS = { 0: "每天", 1: "周一", 2: "周二", 3: "周三", 4: "周四", 5: "周五", 6: "周六", 7: "周日" };
|
||||
async function openSubscribeModal() {
|
||||
closeAllModals();
|
||||
SettingsPages.open("subscribe-modal");
|
||||
await loadSubscribeLocations();
|
||||
loadSubscribeRules();
|
||||
}
|
||||
function closeSubscribeModal() {
|
||||
SettingsPages.back();
|
||||
}
|
||||
async function loadSubscribeLocations() {
|
||||
const sel = document.getElementById("sub-location");
|
||||
sel.innerHTML = '<option value="">加载中...</option>';
|
||||
try {
|
||||
const resp = await fetch("/api/campus/locations");
|
||||
const data = await resp.json();
|
||||
// 订阅只针对「停车点」(楼/兴趣点只用于起终点归属)
|
||||
subscribeLocations = ((data.rtn_code === 0 ? data.data : []) || [])
|
||||
.filter(l => l.kind === "parking");
|
||||
} catch (err) {
|
||||
subscribeLocations = [];
|
||||
}
|
||||
sel.innerHTML = subscribeLocations.length
|
||||
? subscribeLocations.map(l => `<option value="${l.id}">${escHtml(l.name)}</option>`).join("")
|
||||
: '<option value="">(管理员尚未配置停车点)</option>';
|
||||
}
|
||||
function subRuleRowHtml(r) {
|
||||
const loc = subscribeLocations.find(l => l.id === r.location_id);
|
||||
const locName = loc ? loc.name : (r.location_name || "停车点已删除");
|
||||
const hh = String(Math.floor(r.minute_of_day / 60)).padStart(2, "0");
|
||||
const mm = String(r.minute_of_day % 60).padStart(2, "0");
|
||||
const kindText = (r.kind_labels && r.kind_labels.length)
|
||||
? r.kind_labels.join("/") : "全部车型";
|
||||
const eMin = r.min_electric != null ? r.min_electric : 0;
|
||||
const eMax = r.max_electric != null ? r.max_electric : 100;
|
||||
const sortLabel = r.sort_by_label || r.sort_by || "";
|
||||
const tags = [];
|
||||
if (r.auto_unlock) {
|
||||
tags.push(`自动开锁 · ${kindText} · 电量${eMin}-${eMax}% · ${sortLabel} · 重试${r.retry_times || 3}次`);
|
||||
}
|
||||
return `
|
||||
<div class="device-item" style="display:block;padding:9px 12px;border-bottom:1px solid var(--bg-tertiary,#ececf1);">
|
||||
<div style="display:flex;justify-content:space-between;align-items:flex-start;gap:8px;">
|
||||
<div style="font-size:13px;line-height:1.6;min-width:0;">
|
||||
<b>${escHtml(locName)}</b>
|
||||
<span style="color:var(--text-secondary);"> · ${SUB_WEEKDAYS[r.weekday] || "每周"} ${hh}:${mm}</span>
|
||||
<div style="font-size:11.5px;color:var(--text-secondary);">${r.enabled ? "已启用" : "已停用"}${r.notify_enabled ? " · 邮件提醒" : ""}</div>
|
||||
${tags.length ? `<div style="font-size:11.5px;color:#005bbf;">${escHtml(tags[0])}</div>` : ""}
|
||||
</div>
|
||||
<div style="display:flex;gap:6px;flex:0 0 auto;">
|
||||
<button class="btn" style="padding:4px 9px;border:none;border-radius:8px;font-size:12px;background:#ececf1;" onclick="toggleSubscribeRule(${r.id}, ${r.enabled ? 0 : 1})">${r.enabled ? "停用" : "启用"}</button>
|
||||
<button class="btn" style="padding:4px 9px;border:none;border-radius:8px;font-size:12px;background:#fce4ec;color:#c62828;" onclick="deleteSubscribeRule(${r.id})">删除</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
}
|
||||
// 订阅表单「更多筛选」折叠开关(高级调优项默认收起)
|
||||
function toggleSubAdvanced() {
|
||||
const box = document.getElementById("sub-advanced");
|
||||
if (!box) return;
|
||||
const show = box.style.display === "none";
|
||||
box.style.display = show ? "block" : "none";
|
||||
}
|
||||
async function loadSubscribeRules() {
|
||||
const box = document.getElementById("subscribe-list");
|
||||
box.innerHTML = '<div class="device-loading">加载中...</div>';
|
||||
try {
|
||||
const resp = await fetch("/api/subscribe/rules", {
|
||||
headers: { "Authorization": `Bearer ${authToken}` }
|
||||
});
|
||||
const data = await resp.json();
|
||||
if (data.rtn_code !== 0) {
|
||||
box.innerHTML = `<div class="device-loading">${escHtml(data.message || "加载失败")}</div>`;
|
||||
return;
|
||||
}
|
||||
const rules = data.data || [];
|
||||
box.innerHTML = rules.length
|
||||
? rules.map(subRuleRowHtml).join("")
|
||||
: '<div class="device-loading">暂无规则,在下方添加</div>';
|
||||
} catch (err) {
|
||||
box.innerHTML = '<div class="device-loading">网络错误,请重试</div>';
|
||||
}
|
||||
}
|
||||
async function addSubscribeRule() {
|
||||
const locationId = Number(document.getElementById("sub-location").value || 0);
|
||||
const weekday = Number(document.getElementById("sub-weekday").value);
|
||||
const time = document.getElementById("sub-time").value;
|
||||
const notify = document.getElementById("sub-notify").checked;
|
||||
const auto = document.getElementById("sub-auto").checked;
|
||||
const kinds = [...document.querySelectorAll(".sub-kind:checked")].map(el => el.value);
|
||||
const minE = Number(document.getElementById("sub-min-e").value || 0);
|
||||
const maxE = Number(document.getElementById("sub-max-e").value || 100);
|
||||
const sortBy = document.getElementById("sub-sort").value;
|
||||
const retry = Number(document.getElementById("sub-retry").value || 3);
|
||||
|
||||
if (!locationId) { showToast("请先选择停车点(需要管理员先配置停车点)"); return; }
|
||||
if (!/^\d{2}:\d{2}$/.test(time)) { showToast("请选择时间"); return; }
|
||||
if (!kinds.length) { showToast("至少选择一个车型"); return; }
|
||||
if (!(minE >= 0 && maxE <= 100 && minE <= maxE)) { showToast("电量区间需在 0-100 且下限≤上限"); return; }
|
||||
if (auto) {
|
||||
const ok = await appConfirm(
|
||||
"开启自动开锁后,命中规则时系统会用你的账号直接开锁车辆。\n\n" +
|
||||
`筛选:${kinds.map(k => ({small:"小车",big:"大车",red:"红车"}[k])).join("/")},` +
|
||||
`电量 ${minE}%-${maxE}%,${document.getElementById("sub-sort").selectedOptions[0].textContent};` +
|
||||
`被他人抢先时最多重试 ${retry} 次。`,
|
||||
{ title: "开启自动开锁", okText: "确认添加" });
|
||||
if (!ok) return;
|
||||
}
|
||||
try {
|
||||
const resp = await fetch("/api/subscribe/rules", {
|
||||
method: "POST",
|
||||
headers: { "Authorization": `Bearer ${authToken}`, "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
location_id: locationId, weekday, time,
|
||||
notify_enabled: notify, auto_unlock: auto,
|
||||
kinds, min_electric: minE, max_electric: maxE,
|
||||
sort_by: sortBy, retry_times: retry
|
||||
})
|
||||
});
|
||||
const data = await resp.json();
|
||||
showToast(data.message || (data.rtn_code === 0 ? "已添加" : "添加失败"));
|
||||
if (data.rtn_code === 0) loadSubscribeRules();
|
||||
} catch (err) {
|
||||
showToast("网络错误,请重试");
|
||||
}
|
||||
}
|
||||
async function toggleSubscribeRule(ruleId, enable) {
|
||||
try {
|
||||
const resp = await fetch(`/api/subscribe/rules/${ruleId}`, {
|
||||
method: "PUT",
|
||||
headers: { "Authorization": `Bearer ${authToken}`, "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ enabled: !!enable })
|
||||
});
|
||||
const data = await resp.json();
|
||||
if (data.rtn_code === 0) loadSubscribeRules();
|
||||
else showToast(data.message || "操作失败");
|
||||
} catch (err) { showToast("网络错误"); }
|
||||
}
|
||||
async function deleteSubscribeRule(ruleId) {
|
||||
try {
|
||||
const resp = await fetch(`/api/subscribe/rules/${ruleId}`, {
|
||||
method: "DELETE",
|
||||
headers: { "Authorization": `Bearer ${authToken}` }
|
||||
});
|
||||
const data = await resp.json();
|
||||
if (data.rtn_code === 0) loadSubscribeRules();
|
||||
else showToast(data.message || "删除失败");
|
||||
} catch (err) { showToast("网络错误"); }
|
||||
}
|
||||
Reference in New Issue
Block a user