后端 · 订单与计时器(timer.py / routes/rental.py / routes/share.py)
- R2 关闭自动还车后,巡检 / 重启恢复 / sweep 不再强制还车(_should_auto_return 读骑行人设置)
- R3 手动还车撞续租窗口:先等 _renewal_lock,再按同车活跃行重查,不再误回「订单已结束」
- R4 续租复用巡检行时补齐 renewal_round / rounds_override / rider_user_id / source
- R5 续租策略统一读骑行人(rider_user_id or user_id);上游调用与卡支付仍用车主
- R6 续租落库失败立即 _check_user_order 兜底,仍失败则管理员告警
- R7 /record/qrOrder 失败撤销半成品订单(续租 + 共享开锁两处)
- R8 跨进程租约移入 auto_return_bike 本体(ttl 180);线程内重入只由最外层释放一次;新增 _background_enabled 总开关
- R9 自动还车失败先复查 expired,已结束则不再重试、不发紧急邮件
- R10 开锁响应 SELECT 补 order_id,轮次预估不再恒为 1 轮
- R11 共享开锁落库:IntegrityError 复用活跃行;其它异常同步订单并在响应带 warning
- R12 0 分钟自动还车的结果邮件不再依赖「0 分钟提醒」被勾选
后端 · 鉴权与基础设施
- A3 /api/admin/users 不再返回完整 access_token / token_id(只留掩码)
- A4 采集调度循环 try/except;后台线程登记,看门狗按 is_alive 重拉;租约 True/False/None 三态显式
- A5 采集改走 _request_api_uncached;map_cache 失败标 stale / stale_since,fetched_at 保持上次成功时间
- A6 bootstrap try/finally,异常时复位 _bootstrap_started
- A7 删除含明文 AK/SK 的旧分发包 1.zip
- A8 record_cooldown 不再翻转已有有效验证码的 purpose(修注册验证码 DoS)
- A9 登录新增邮箱维度限流(10 次 / 900 秒)
- A10 管理员代还车一律按订单归属用户执行,body user_id 不一致时返回 warning
- A11 /api/ring_progress 改用 /api/ring_ticket 签发的一次性 ticket,不再接受 ?token=
- A12 导出令牌绑定创建者、下载一次性、可撤销(POST /api/export/revoke)
- 时区:CURRENT_TIMESTAMP 全部统一为 datetime('now', '+8 hours')(db.py / admin.py / share.py)
- JSON:auth 入参非字符串时返回 400 而非 500
前端(src-ts / templates / static)
- F1 登录后静默定位;找车 / 导航无定位时现场申请;被拒弹卡片并提供「用地图中心找车」
- F2 真实订单的计时条不再被 status 轮询清掉;startRentalFromServer 记录 order_id
- F3 登出 / 会话失效时 resetUserState 清掉横幅、计时条、共享横幅与本地存储
- F4 toast 改为 #toast-stack(最多 3 条、role=status),不再互相覆盖
- F6 新增 fetchWithTimeout(8 秒),全站 fetch 接入;/api/config 超时显示失败卡片
- F7 getBikeState 顺序统一为 损坏→使用中→欠压→低电量→空闲,图例与卡片同源
- F8 快照刷新后卡片按车牌重绘,车辆离开实时列表则关闭并提示
- F10 共享权限复选框改为 label 包裹
- F11 分析页 echarts / mapvgl 加 defer + onerror;BMap 超时显示失败卡片
- F12 删除订阅规则增加二次确认,按钮加 tap-44
- F13 扫码查询按钮禁用态;401 / 非 JSON 响应走登录门
- F14 刷新按钮绑定真实请求,失败必提示
- ring_progress.html 改两步 ticket 流程;bike-clusters addEventListener 特性检测
测试
- 新增 tests/test_fix_order_lifecycle.py(27)、tests/test_fix_infra_fixes.py(24)、tests/test_fix_frontend.cjs(13)
- tests/test_order_sync.py、tests/test_ring_owner.py 按 R12 / A11 新语义更新
- pytest 322 passed;tsc / esbuild / verify:globals 通过;cjs 58 passed
181 lines
8.5 KiB
TypeScript
181 lines
8.5 KiB
TypeScript
/* 由 static/js/{navigation,share,subscribe,map}.js 逐块搬运而来;正文与原实现一致。 */
|
||
|
||
import { S } from "../core/state";
|
||
import { escHtml } from "../core/format";
|
||
import { appConfirm, showToast } from "../ui/modals";
|
||
import { closeAllModals } from "../ui/settings";
|
||
// static/js/subscribe.js:6-6
|
||
let subscribeLocations: any = [];
|
||
|
||
// static/js/subscribe.js:7-7
|
||
const SUB_WEEKDAYS = { 0: "每天", 1: "周一", 2: "周二", 3: "周三", 4: "周四", 5: "周五", 6: "周六", 7: "周日" };
|
||
|
||
// static/js/subscribe.js:8-13
|
||
export async function openSubscribeModal() {
|
||
closeAllModals();
|
||
SettingsPages.open("subscribe-modal");
|
||
await loadSubscribeLocations();
|
||
loadSubscribeRules();
|
||
}
|
||
|
||
// static/js/subscribe.js:14-16
|
||
export function closeSubscribeModal() {
|
||
SettingsPages.back();
|
||
}
|
||
|
||
// static/js/subscribe.js:17-32
|
||
export 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>';
|
||
}
|
||
|
||
// static/js/subscribe.js:33-63
|
||
export 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 tap-44" style="padding:4px 9px;border:none;border-radius:8px;font-size:12px;background:#fce4ec;color:#c62828;" onclick="deleteSubscribeRule(${r.id})">删除</button>
|
||
</div>
|
||
</div>
|
||
</div>`;
|
||
}
|
||
// 订阅表单「更多筛选」折叠开关(高级调优项默认收起)
|
||
|
||
// static/js/subscribe.js:64-69
|
||
export function toggleSubAdvanced() {
|
||
const box = document.getElementById("sub-advanced");
|
||
if (!box) return;
|
||
const show = box.style.display === "none";
|
||
box.style.display = show ? "block" : "none";
|
||
}
|
||
|
||
// static/js/subscribe.js:70-89
|
||
export 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 ${S.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>';
|
||
}
|
||
}
|
||
|
||
// static/js/subscribe.js:90-132
|
||
export 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 ${S.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("网络错误,请重试");
|
||
}
|
||
}
|
||
|
||
// static/js/subscribe.js:133-144
|
||
export async function toggleSubscribeRule(ruleId, enable) {
|
||
try {
|
||
const resp = await fetch(`/api/subscribe/rules/${ruleId}`, {
|
||
method: "PUT",
|
||
headers: { "Authorization": `Bearer ${S.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("网络错误"); }
|
||
}
|
||
|
||
// static/js/subscribe.js:145-155
|
||
export async function deleteSubscribeRule(ruleId) {
|
||
// F12:删除不可撤销,先确认(页面内弹窗,原生壳里 window.confirm 不可用)
|
||
const ok = await appConfirm("删除这条订阅规则?", { title: "删除订阅规则", okText: "删除", danger: true });
|
||
if (!ok) return;
|
||
try {
|
||
const resp = await fetch(`/api/subscribe/rules/${ruleId}`, {
|
||
method: "DELETE",
|
||
headers: { "Authorization": `Bearer ${S.authToken}` }
|
||
});
|
||
const data = await resp.json();
|
||
if (data.rtn_code === 0) loadSubscribeRules();
|
||
else showToast(data.message || "删除失败");
|
||
} catch (err) { showToast("网络错误"); }
|
||
}
|