Files
xbcr/templates/ring_progress.html

264 lines
8.8 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');
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;
cancelled = true;
document.getElementById('cancel-btn').disabled = true;
document.getElementById('cancel-btn').textContent = '取消中...';
fetch(`/api/ring_cancel/${taskId}`, { method: 'POST' })
.then(r => r.json())
.then(d => {
addLog(d.message || '取消请求已发送', '');
})
.catch(() => addLog('取消请求失败', 'failed'));
}
function closeWindow() {
if (!completed && !cancelled) {
if (!confirm('任务还在运行,确定要关闭吗?')) return;
}
uiCloseWindow();
}
// SSE 连接
const es = new EventSource(`/api/ring_progress/${taskId}`);
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');
es.close();
};
addLog('开始监听进度...', '');
</script>
</body>
</html>