This commit is contained in:
mjz
2026-11-01 16:51:06 +08:00
commit 93ef302df6
4 changed files with 294 additions and 0 deletions
+211
View File
@@ -0,0 +1,211 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>酒店查询 - 成功/失败条数</title>
<style>
* { box-sizing: border-box; }
body {
margin: 0;
padding: 24px;
font-family: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
background: #f4f6f9;
color: #1f2937;
}
.wrap { max-width: 860px; margin: 0 auto; }
h1 { font-size: 20px; margin: 0 0 16px; font-weight: 600; }
.toolbar {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
background: #fff;
padding: 16px;
border-radius: 10px;
box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.toolbar label { font-size: 14px; color: #4b5563; }
input[type=date] {
padding: 8px 10px;
font-size: 14px;
border: 1px solid #d1d5db;
border-radius: 6px;
outline: none;
}
input[type=date]:focus { border-color: #2563eb; }
button {
padding: 9px 22px;
font-size: 14px;
border: none;
border-radius: 6px;
background: #2563eb;
color: #fff;
cursor: pointer;
}
button:hover:not(:disabled) { background: #1d4ed8; }
button:disabled { background: #93b4ee; cursor: not-allowed; }
.hint { font-size: 12px; color: #9ca3af; margin-left: auto; }
.cards { display: flex; gap: 16px; margin-top: 16px; flex-wrap: wrap; }
.card {
flex: 1 1 160px;
background: #fff;
border-radius: 10px;
padding: 16px;
box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.card .label { font-size: 13px; color: #6b7280; }
.card .value { font-size: 28px; font-weight: 600; margin-top: 6px; font-variant-numeric: tabular-nums; }
.card.success .value { color: #059669; }
.card.reject .value { color: #dc2626; }
.card.fail .value { color: #d97706; }
#status { margin-top: 16px; font-size: 13px; min-height: 18px; color: #6b7280; }
#status.error { color: #dc2626; }
table {
width: 100%;
margin-top: 8px;
border-collapse: collapse;
background: #fff;
border-radius: 10px;
overflow: hidden;
box-shadow: 0 1px 3px rgba(0,0,0,.08);
opacity: 0;
transition: opacity .2s;
}
table.show { opacity: 1; }
th, td { padding: 10px 14px; font-size: 14px; text-align: left; border-bottom: 1px solid #eef1f5; }
th { background: #f9fafb; color: #6b7280; font-weight: 500; }
td.num { font-variant-numeric: tabular-nums; }
td.num.reject { color: #dc2626; }
tr:last-child td { border-bottom: none; }
tr.failed td { color: #d97706; background: #fffbeb; }
</style>
</head>
<body>
<div class="wrap">
<h1>酒店查询 · 成功/失败条数</h1>
<div class="toolbar">
<label for="date">查询日期</label>
<input type="date" id="date">
<button id="btn" type="button">查询</button>
<span class="hint" id="hint">并发 8 线程,逐城市汇总</span>
</div>
<div class="cards">
<div class="card success">
<div class="label">总成功条数</div>
<div class="value" id="totalSuccess">-</div>
</div>
<div class="card reject">
<div class="label">总失败条数</div>
<div class="value" id="totalReject">-</div>
</div>
<div class="card fail">
<div class="label">请求失败城市</div>
<div class="value" id="failedCount">-</div>
</div>
</div>
<div id="status"></div>
<table id="table">
<thead>
<tr><th>城市</th><th>成功</th><th>失败</th></tr>
</thead>
<tbody></tbody>
</table>
</div>
<script>
const dateInput = document.getElementById('date');
const btn = document.getElementById('btn');
const statusEl = document.getElementById('status');
const table = document.getElementById('table');
const tbody = table.querySelector('tbody');
// 默认今天
const now = new Date();
const pad = n => String(n).padStart(2, '0');
dateInput.value = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
function setStatus(text, isError) {
statusEl.textContent = text;
statusEl.className = isError ? 'error' : '';
}
function fmt(n) {
return n === null || n === undefined ? '-' : Number(n).toLocaleString('zh-CN');
}
function render(data) {
tbody.innerHTML = '';
data.items.forEach(item => {
const tr = document.createElement('tr');
if (item.error) tr.className = 'failed';
const cityTd = document.createElement('td');
cityTd.textContent = item.city;
tr.appendChild(cityTd);
['success', 'reject'].forEach(key => {
const td = document.createElement('td');
td.className = 'num' + (key === 'reject' && item.reject ? ' reject' : '');
if (item.error) {
td.textContent = '请求失败';
} else {
td.textContent = fmt(item[key]);
}
tr.appendChild(td);
});
tr.title = item.error || '';
tbody.appendChild(tr);
});
document.getElementById('totalSuccess').textContent = fmt(data.total_success);
document.getElementById('totalReject').textContent = fmt(data.total_reject);
document.getElementById('failedCount').textContent = fmt(data.failed_cities.length);
table.classList.add('show');
let text = `date=${data.date},共 ${data.items.length} 个城市`;
if (data.failed_cities.length) {
text += `,请求失败:${data.failed_cities.join('、')}`;
}
setStatus(text, data.failed_cities.length > 0);
}
async function query() {
const value = dateInput.value;
if (!value) {
setStatus('请先选择日期', true);
return;
}
const statDate = value; // 原样传 2026-11-01
btn.disabled = true;
btn.textContent = '查询中…';
setStatus(`正在查询 ${statDate} …`);
try {
const resp = await fetch(`/api/stats?date=${encodeURIComponent(statDate)}`);
const data = await resp.json();
if (!resp.ok) {
setStatus(data.error || `请求失败 HTTP ${resp.status}`, true);
return;
}
render(data);
} catch (e) {
setStatus(`请求异常:${e.message}`, true);
} finally {
btn.disabled = false;
btn.textContent = '查询';
}
}
btn.addEventListener('click', query);
dateInput.addEventListener('keydown', e => {
if (e.key === 'Enter') query();
});
</script>
</body>
</html>