后端 · 订单与计时器(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
307 lines
11 KiB
HTML
307 lines
11 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>全车寻铃进度</title>
|
||
<style>
|
||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||
body {
|
||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||
background: #1a1a2e;
|
||
color: #eee;
|
||
min-height: 100vh;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
padding: 20px;
|
||
}
|
||
.container {
|
||
background: #16213e;
|
||
border-radius: 16px;
|
||
padding: 32px;
|
||
width: 100%;
|
||
max-width: 420px;
|
||
box-shadow: 0 8px 32px rgba(0,0,0,0.3);
|
||
}
|
||
.header {
|
||
text-align: center;
|
||
margin-bottom: 28px;
|
||
}
|
||
.header h1 {
|
||
font-size: 22px;
|
||
margin-bottom: 8px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 8px;
|
||
}
|
||
.header p {
|
||
color: #888;
|
||
font-size: 14px;
|
||
}
|
||
.stats {
|
||
display: grid;
|
||
grid-template-columns: repeat(3, 1fr);
|
||
gap: 12px;
|
||
margin-bottom: 24px;
|
||
}
|
||
.stat {
|
||
background: #0f3460;
|
||
border-radius: 12px;
|
||
padding: 16px 12px;
|
||
text-align: center;
|
||
}
|
||
.stat-value {
|
||
font-size: 28px;
|
||
font-weight: 700;
|
||
color: #e94560;
|
||
}
|
||
.stat-value.success { color: #4ade80; }
|
||
.stat-value.failed { color: #f87171; }
|
||
.stat-label {
|
||
font-size: 12px;
|
||
color: #888;
|
||
margin-top: 4px;
|
||
}
|
||
.progress-bar {
|
||
background: #0f3460;
|
||
border-radius: 10px;
|
||
height: 20px;
|
||
overflow: hidden;
|
||
margin-bottom: 20px;
|
||
}
|
||
.progress-fill {
|
||
height: 100%;
|
||
background: linear-gradient(90deg, #e94560, #ff6b6b);
|
||
border-radius: 10px;
|
||
transition: width 0.2s ease;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: flex-end;
|
||
padding-right: 8px;
|
||
font-size: 11px;
|
||
font-weight: 600;
|
||
min-width: 40px;
|
||
}
|
||
.progress-fill.done { background: linear-gradient(90deg, #4ade80, #22c55e); }
|
||
.actions {
|
||
display: flex;
|
||
gap: 12px;
|
||
}
|
||
.btn {
|
||
flex: 1;
|
||
padding: 14px;
|
||
border: none;
|
||
border-radius: 10px;
|
||
font-size: 15px;
|
||
font-weight: 600;
|
||
cursor: pointer;
|
||
transition: all 0.2s;
|
||
}
|
||
.btn-cancel {
|
||
background: #e94560;
|
||
color: white;
|
||
}
|
||
.btn-cancel:hover { background: #d63850; }
|
||
.btn-close {
|
||
background: #333;
|
||
color: #ccc;
|
||
}
|
||
.btn-close:hover { background: #444; }
|
||
.btn:disabled {
|
||
opacity: 0.5;
|
||
cursor: not-allowed;
|
||
}
|
||
.log {
|
||
margin-top: 20px;
|
||
background: #0a0a1a;
|
||
border-radius: 10px;
|
||
padding: 12px;
|
||
max-height: 120px;
|
||
overflow-y: auto;
|
||
font-size: 12px;
|
||
color: #888;
|
||
}
|
||
.log-entry { margin-bottom: 4px; }
|
||
.log-entry.success { color: #4ade80; }
|
||
.log-entry.failed { color: #f87171; }
|
||
</style>
|
||
<link rel="stylesheet" href="/static/css/ui-system.css">
|
||
<script defer src="/static/js/ui-motion.js"></script>
|
||
</head>
|
||
<body>
|
||
<div class="container">
|
||
<div class="header">
|
||
<h1>
|
||
<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"/><path d="M13.73 21a2 2 0 0 1-3.46 0"/></svg>
|
||
全车寻铃
|
||
</h1>
|
||
<p id="status-text">正在连接...</p>
|
||
</div>
|
||
|
||
<div class="stats">
|
||
<div class="stat">
|
||
<div class="stat-value" id="done-count">0</div>
|
||
<div class="stat-label">已完成</div>
|
||
</div>
|
||
<div class="stat">
|
||
<div class="stat-value success" id="success-count">0</div>
|
||
<div class="stat-label">成功</div>
|
||
</div>
|
||
<div class="stat">
|
||
<div class="stat-value failed" id="failed-count">0</div>
|
||
<div class="stat-label">失败</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="progress-bar">
|
||
<div class="progress-fill" id="progress-fill" style="width: 0%">
|
||
<span id="progress-text">0%</span>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="actions">
|
||
<button class="btn btn-cancel" id="cancel-btn" onclick="cancelTask()">取消任务</button>
|
||
<button class="btn btn-close" onclick="closeWindow()">关闭</button>
|
||
</div>
|
||
|
||
<div class="log" id="log"></div>
|
||
</div>
|
||
|
||
<script>
|
||
const params = new URLSearchParams(window.location.search);
|
||
const taskId = params.get('task_id') || '';
|
||
const total = parseInt(params.get('total') || '0');
|
||
|
||
// ===== 登录态(BUG-20 / A11)=====
|
||
// /api/ring_status | ring_cancel | ring_progress 都要求登录。
|
||
// EventSource 不能自定义 header,所以不再把会话 token 拼进 URL(会进反代访问日志):
|
||
// 先用 Bearer 换一张 60 秒一次性 ticket,再拿 ticket 连 SSE。
|
||
function getAuthToken() {
|
||
try { return localStorage.getItem('auth_token') || ''; } catch (e) { return ''; }
|
||
}
|
||
const authToken = getAuthToken();
|
||
const authHeaders = authToken ? { 'Authorization': 'Bearer ' + authToken } : {};
|
||
|
||
document.getElementById('status-text').textContent = `共 ${total} 辆车`;
|
||
|
||
let cancelled = false;
|
||
let completed = false;
|
||
|
||
function addLog(msg, type = '') {
|
||
const log = document.getElementById('log');
|
||
const entry = document.createElement('div');
|
||
entry.className = 'log-entry ' + type;
|
||
entry.textContent = `[${new Date().toLocaleTimeString()}] ${msg}`;
|
||
log.appendChild(entry);
|
||
log.scrollTop = log.scrollHeight;
|
||
}
|
||
|
||
function updateUI(data) {
|
||
const { status, done, total, success, failed } = data;
|
||
|
||
document.getElementById('done-count').textContent = done;
|
||
document.getElementById('success-count').textContent = success;
|
||
document.getElementById('failed-count').textContent = failed;
|
||
|
||
const pct = total > 0 ? Math.round((done / total) * 100) : 0;
|
||
const fill = document.getElementById('progress-fill');
|
||
fill.style.width = pct + '%';
|
||
document.getElementById('progress-text').textContent = pct + '%';
|
||
|
||
if (pct >= 100 || status === 'completed' || status === 'cancelled') {
|
||
fill.classList.add('done');
|
||
document.getElementById('cancel-btn').disabled = true;
|
||
completed = true;
|
||
}
|
||
|
||
if (status === 'cancelled') {
|
||
document.getElementById('status-text').textContent = '❌ 已取消';
|
||
addLog('任务已取消', '');
|
||
} else if (status === 'completed') {
|
||
document.getElementById('status-text').textContent = '✅ 全部完成';
|
||
addLog(`完成!成功:${success} 失败:${failed}`, '');
|
||
}
|
||
}
|
||
|
||
function cancelTask() {
|
||
if (cancelled || completed) return;
|
||
if (!taskId) { addLog('缺少任务号,无法取消', 'failed'); return; }
|
||
cancelled = true;
|
||
document.getElementById('cancel-btn').disabled = true;
|
||
document.getElementById('cancel-btn').textContent = '取消中...';
|
||
fetch(`/api/ring_cancel/${encodeURIComponent(taskId)}`, {
|
||
method: 'POST',
|
||
headers: authHeaders
|
||
})
|
||
.then(r => r.json())
|
||
.then(d => {
|
||
addLog(d.message || '取消请求已发送', d.rtn_code === 0 ? '' : 'failed');
|
||
})
|
||
.catch(() => addLog('取消请求失败', 'failed'));
|
||
}
|
||
|
||
function closeWindow() {
|
||
if (!completed && !cancelled) {
|
||
if (!confirm('任务还在运行,确定要关闭吗?')) return;
|
||
}
|
||
uiCloseWindow();
|
||
}
|
||
|
||
// SSE 连接:先用 Bearer 换一次性 ticket,再连 SSE(不把会话 token 拼进 URL)
|
||
let es = null;
|
||
function connectProgress() {
|
||
fetch('/api/ring_ticket', { headers: authHeaders })
|
||
.then(r => r.json())
|
||
.then(d => {
|
||
const ticket = (d && d.data && d.data.ticket) || '';
|
||
if (d.rtn_code !== 0 || !ticket) {
|
||
addLog(d.message || '获取进度凭证失败,请重新登录', 'failed');
|
||
return;
|
||
}
|
||
openStream(ticket);
|
||
})
|
||
.catch(() => addLog('获取进度凭证失败', 'failed'));
|
||
}
|
||
|
||
function openStream(ticket) {
|
||
es = new EventSource(`/api/ring_progress/${encodeURIComponent(taskId)}?ticket=${encodeURIComponent(ticket)}`);
|
||
|
||
es.onmessage = (e) => {
|
||
try {
|
||
const data = JSON.parse(e.data);
|
||
if (data.type === 'progress') {
|
||
updateUI(data);
|
||
} else if (data.type === 'done') {
|
||
es.close();
|
||
} else if (data.type === 'error') {
|
||
addLog(data.message, 'failed');
|
||
es.close();
|
||
}
|
||
} catch (err) {}
|
||
};
|
||
|
||
es.onerror = () => {
|
||
addLog('连接断开', 'failed');
|
||
if (es) es.close();
|
||
};
|
||
|
||
addLog('开始监听进度...', '');
|
||
}
|
||
|
||
if (!taskId) {
|
||
document.getElementById('status-text').textContent = '缺少任务号';
|
||
document.getElementById('cancel-btn').disabled = true;
|
||
addLog('缺少 task_id,请从主页面重新发起全车寻铃', 'failed');
|
||
} else if (!authToken) {
|
||
document.getElementById('status-text').textContent = '请先在主页面登录';
|
||
document.getElementById('cancel-btn').disabled = true;
|
||
addLog('未登录:请先在主页面登录后再查看寻车进度', 'failed');
|
||
} else {
|
||
connectProgress();
|
||
}
|
||
</script>
|
||
</body>
|
||
</html>
|