Files
CC-StationBroadcast/CloudServer/public/infoboard.html
T

599 lines
22 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>车站广播系统 - 实时信息板</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap"
rel="stylesheet">
<style>
:root {
--bg-body: #09090b;
--bg-panel: #18181b;
--bg-hover: #27272a;
--bg-border: #27272a;
--text-primary: #e4e4e7;
--text-muted: #71717a;
--accent: #fafafa;
--danger: #ef4444;
--success: #10b981;
--warning: #f59e0b;
--radius: 8px;
--font-ui: 'Inter', -apple-system, sans-serif;
--font-mono: 'JetBrains Mono', monospace;
}
* {
box-sizing: border-box;
}
body {
font-family: var(--font-ui);
background-color: var(--bg-body);
color: var(--text-primary);
margin: 0;
padding: 24px;
height: 100vh;
display: flex;
flex-direction: column;
overflow: hidden;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 24px;
padding-bottom: 16px;
border-bottom: 1px solid var(--bg-border);
}
h1 {
margin: 0;
font-size: 1.5rem;
font-weight: 600;
letter-spacing: -0.025em;
}
.header-meta {
display: flex;
gap: 20px;
align-items: center;
font-size: 0.85rem;
color: var(--text-muted);
}
.status-badge {
display: flex;
align-items: center;
gap: 8px;
font-weight: 600;
}
.main-grid {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 24px;
flex: 1;
overflow: hidden;
}
.card {
background: var(--bg-panel);
border: 1px solid var(--bg-border);
border-radius: var(--radius);
display: flex;
flex-direction: column;
overflow: hidden;
}
.card-header {
padding: 16px 20px;
background: rgba(255, 255, 255, 0.02);
border-bottom: 1px solid var(--bg-border);
display: flex;
justify-content: space-between;
align-items: center;
}
.card-title {
font-size: 0.85rem;
font-weight: 600;
color: var(--text-muted);
text-transform: uppercase;
letter-spacing: 0.05em;
}
.card-content {
flex: 1;
overflow-y: auto;
padding: 0;
}
/* Status Styles */
.status-list {
list-style: none;
margin: 0;
padding: 0;
}
.status-item {
padding: 12px 20px;
border-bottom: 1px solid var(--bg-border);
display: flex;
justify-content: space-between;
align-items: center;
}
.status-item:last-child {
border-bottom: none;
}
.item-info {
display: flex;
flex-direction: column;
gap: 2px;
}
.item-title {
font-weight: 500;
font-size: 0.95rem;
}
.item-sub {
font-size: 0.75rem;
color: var(--text-muted);
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--bg-border);
}
.dot-online {
background: var(--success);
box-shadow: 0 0 8px rgba(16, 185, 129, 0.4);
}
.dot-offline {
background: var(--danger);
}
.dot-broadcasting {
background: #3b82f6;
box-shadow: 0 0 8px rgba(59, 130, 246, 0.6);
animation: pulse 1s infinite;
}
@keyframes pulse {
0% { opacity: 1; transform: scale(1); }
50% { opacity: 0.5; transform: scale(1.5); }
100% { opacity: 1; transform: scale(1); }
}
/* Train Specifics */
.train-item {
cursor: pointer;
transition: background 0.1s;
}
.train-item:hover {
background: var(--bg-hover);
}
.train-details {
display: none;
background: rgba(0, 0, 0, 0.2);
padding: 12px 20px;
font-size: 0.8rem;
color: var(--text-muted);
border-top: 1px solid var(--bg-border);
}
.train-details.open {
display: block;
}
.trip-log {
display: grid;
grid-template-columns: 80px 1fr auto;
gap: 12px;
padding: 4px 0;
border-bottom: 1px dashed var(--bg-border);
}
.trip-log:last-child {
border-bottom: none;
}
/* Statistics & Messages */
.log-list {
padding: 8px;
margin: 0;
list-style: none;
display: flex;
flex-direction: column;
gap: 8px;
}
.log-item {
padding: 12px 16px;
background: rgba(255, 255, 255, 0.03);
border: 1px solid var(--bg-border);
border-radius: 6px;
font-size: 0.85rem;
line-height: 1.5;
display: flex;
align-items: flex-start;
gap: 12px;
animation: slideInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1);
transition: all 0.2s;
}
.log-item:hover {
background: rgba(255, 255, 255, 0.05);
border-color: #3f3f46;
}
@keyframes slideInRight {
from { opacity: 0; transform: translateX(20px); }
to { opacity: 1; transform: translateX(0); }
}
.log-icon {
width: 20px;
height: 20px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 4px;
flex-shrink: 0;
margin-top: 2px;
}
.log-body {
flex: 1;
display: flex;
flex-direction: column;
gap: 2px;
}
.log-time {
font-family: var(--font-mono);
font-size: 0.7rem;
color: var(--text-muted);
font-weight: 500;
}
.log-content {
color: var(--text-primary);
word-break: break-all;
}
/* Message Types */
.log-info .log-icon { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.log-arrival .log-icon { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.log-departure .log-icon { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.log-broadcast .log-icon { background: rgba(139, 92, 246, 0.15); color: #a78bfa; }
.log-important { border-left: 3px solid #3b82f6; }
.log-broadcast {
background: rgba(139, 92, 246, 0.05);
border-color: rgba(139, 92, 246, 0.2);
}
/* Scrollbar */
::-webkit-scrollbar {
width: 6px;
}
::-webkit-scrollbar-track {
background: transparent;
}
::-webkit-scrollbar-thumb {
background: var(--bg-hover);
border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
background: #52525b;
}
@media (max-width: 1024px) {
.main-grid {
grid-template-columns: 1fr;
overflow-y: auto;
}
body {
overflow-y: auto;
height: auto;
}
}
</style>
</head>
<body>
<header>
<h1>实时信息板 - 全局概览</h1>
<div class="header-meta">
<div id="clock" style="font-family: var(--font-mono); font-weight: 500;">00:00:00</div>
<div class="status-badge">
<div id="conn-dot" class="status-dot dot-offline"></div>
<span id="conn-status" style="color: var(--danger)">未连接</span>
</div>
</div>
</header>
<div class="main-grid">
<!-- 车站状态 -->
<div class="card">
<div class="card-header">
<div class="card-title">活动车站</div>
<div id="station-count" style="font-size: 0.75rem; color: var(--text-muted);">0</div>
</div>
<div class="card-content">
<div class="status-list" id="station-list">
<div style="padding:40px; text-align:center; color:var(--text-muted); font-style:italic;">正在加载车站信息...</div>
</div>
</div>
</div>
<!-- 列车状态 -->
<div class="card">
<div class="card-header">
<div class="card-title">活跃列车</div>
<div id="train-count" style="font-size: 0.75rem; color: var(--text-muted);">0</div>
</div>
<div class="card-content">
<div class="status-list" id="train-list">
<div style="padding:40px; text-align:center; color:var(--text-muted); font-style:italic;">正在加载列车信息...</div>
</div>
</div>
</div>
<!-- 最新消息 -->
<div class="card">
<div class="card-header">
<div class="card-title">最新消息</div>
</div>
<div class="card-content">
<div class="log-list" id="message-list">
<div style="padding:40px; text-align:center; color:var(--text-muted); font-style:italic;">暂无消息数据</div>
</div>
</div>
</div>
</div>
<script>
// --- Icons (SVG) ---
const ICONS = {
chevronDown: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>`,
chevronUp: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="18 15 12 9 6 15"/></svg>`,
info: `<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>`,
arrival: `<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M7 10l5 5 5-5"/><path d="M12 3v12"/></svg>`,
departure: `<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M17 14l-5-5-5 5"/><path d="M12 21V9"/></svg>`,
broadcast: `<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/></svg>`
};
// --- State ---
let expandedTrains = new Set();
let stationCodeMap = {};
let broadcastingStations = new Set();
let messageLog = [];
const MAX_MESSAGES = 50;
// --- Clock ---
function updateClock() {
const now = new Date();
document.getElementById('clock').textContent = now.toLocaleTimeString();
}
setInterval(updateClock, 1000);
updateClock();
// --- WebSocket ---
const connStatus = document.getElementById('conn-status');
const connDot = document.getElementById('conn-dot');
let ws;
function connect() {
const wsProto = window.location.protocol === 'https:' ? 'wss' : 'ws';
ws = new WebSocket(`${wsProto}://${window.location.host}`);
ws.onopen = () => {
connStatus.textContent = '已连接';
connStatus.style.color = 'var(--success)';
connDot.className = 'status-dot dot-online';
ws.send(JSON.stringify({ type: 'console_connect' }));
};
ws.onclose = () => {
connStatus.textContent = '已断开 (重连中...)';
connStatus.style.color = 'var(--danger)';
connDot.className = 'status-dot dot-offline';
setTimeout(connect, 3000);
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
if (data.type === 'init_state' || data.type === 'state_update') {
updateState(data);
if (data.logs && data.type === 'init_state') {
data.logs.forEach(l => addMessage(l));
}
} else if (data.type === 'log') {
addMessage(data.data);
} else if (data.type === 'stream_start') {
broadcastingStations.add(data.station);
updateStationDots();
} else if (data.type === 'stream_end') {
broadcastingStations.delete(data.station);
updateStationDots();
}
};
}
function addMessage(msg) {
const time = new Date().toLocaleTimeString();
let type = 'log-info';
let icon = ICONS.info;
let important = false;
if (msg.includes('Arrived') || msg.includes('arrival')) {
type = 'log-arrival';
icon = ICONS.arrival;
important = true;
} else if (msg.includes('Departed') || msg.includes('departure')) {
type = 'log-departure';
icon = ICONS.departure;
important = true;
} else if (msg.includes('Broadcast') || msg.includes('Stream')) {
type = 'log-broadcast';
icon = ICONS.broadcast;
}
messageLog.unshift({ time, content: msg, type, icon, important });
if (messageLog.length > MAX_MESSAGES) messageLog.pop();
renderMessages();
}
function renderMessages() {
const container = document.getElementById('message-list');
if (messageLog.length === 0) {
container.innerHTML = '<div style="padding:40px; text-align:center; color:var(--text-muted); font-style:italic;">暂无消息数据</div>';
return;
}
container.innerHTML = messageLog.map(m => `
<div class="log-item ${m.type} ${m.important ? 'log-important' : ''}">
<div class="log-icon">${m.icon}</div>
<div class="log-body">
<span class="log-time">${m.time}</span>
<span class="log-content">${m.content}</span>
</div>
</div>
`).join('');
}
function updateState(state) {
if (state.stations) {
const list = document.getElementById('station-list');
list.innerHTML = '';
const stList = Array.isArray(state.stations) ? state.stations : Object.values(state.stations);
document.getElementById('station-count').textContent = stList.length;
stList.forEach(st => {
stationCodeMap[st.name] = st.code;
});
if (stList.length === 0) {
list.innerHTML = '<div style="padding:40px;text-align:center;color:var(--text-muted);font-size:0.8rem">暂无活动车站</div>';
} else {
stList.forEach(st => {
const isOnline = (Date.now() - st.lastSeen) < 60000;
const isBroadcasting = broadcastingStations.has(st.name);
const dotClass = isBroadcasting ? 'dot-broadcasting' : (isOnline ? 'dot-online' : 'dot-offline');
const hasCC = Array.isArray(st.tags) && st.tags.includes('CC');
const div = document.createElement('div');
div.className = 'status-item';
div.innerHTML = `
<div class="item-info">
<div class="item-title">
${st.name}
${hasCC ? '<span style="font-size:0.65rem; background:rgba(16, 185, 129, 0.1); color:#34d399; padding:1px 5px; border-radius:4px; margin-left:6px; font-weight:normal; border:1px solid rgba(16, 185, 129, 0.2)">CC</span>' : ''}
</div>
<div class="item-sub">${st.code}${st.platform ? ` - 站台 ${st.platform}` : ''}</div>
</div>
<div class="status-dot ${dotClass}" id="station-dot-${st.name.replace(/[^a-zA-Z0-9]/g, '_')}" data-online="${isOnline}" data-name="${st.name}"></div>
`;
list.appendChild(div);
});
}
}
if (state.activeTrains) {
const list = document.getElementById('train-list');
list.innerHTML = '';
document.getElementById('train-count').textContent = state.activeTrains.length;
if (!state.activeTrains || state.activeTrains.length === 0) {
list.innerHTML = '<div style="padding:40px;text-align:center;color:var(--text-muted);font-size:0.8rem">暂无活跃列车</div>';
} else {
state.activeTrains.forEach(tr => {
const isExpanded = expandedTrains.has(tr.trainId);
const div = document.createElement('div');
div.className = 'status-item train-item';
div.onclick = () => toggleTrain(tr.trainId);
let detailsHtml = '';
if (tr.tripLogs && tr.tripLogs.length > 0) {
detailsHtml = tr.tripLogs.slice().reverse().map(log => {
const time = new Date(log.time).toLocaleTimeString();
const stCode = stationCodeMap[log.station] || log.station;
return `
<div class="trip-log">
<span>${time}</span>
<span style="color:var(--text-primary)">${stCode}</span>
<span style="color:${log.action === 'Arrival' ? 'var(--success)' : 'var(--warning)'}">${log.action === 'Arrival' ? '到达' : '出发'}</span>
</div>
`;
}).join('');
} else {
detailsHtml = '<div style="font-style:italic">暂无运行历史</div>';
}
const currentStCode = stationCodeMap[tr.currentStation] || tr.currentStation || '-';
const statusColor = tr.status === 'At Station' ? 'var(--success)' : 'var(--warning)';
div.innerHTML = `
<div style="width:100%">
<div style="display:flex; justify-content:space-between; align-items:center;">
<div class="item-info">
<div class="item-title">${tr.trainId} <span style="font-size:0.7rem; color:var(--text-muted); font-weight:normal; margin-left:8px;">${tr.destination || '未知终点'}</span></div>
<div class="item-sub">${currentStCode} <span style="color:${statusColor}; margin-left:8px;">${tr.status === 'At Station' ? '在站' : '运行中'}</span></div>
</div>
<div style="color:var(--text-muted)">${isExpanded ? ICONS.chevronUp : ICONS.chevronDown}</div>
</div>
<div class="train-details ${isExpanded ? 'open' : ''}" id="details-${tr.trainId}">
<div style="margin-bottom:8px;font-weight:600;font-size:0.7rem;text-transform:uppercase;color:var(--text-muted)">运行日志 (Trip Logs)</div>
${detailsHtml}
</div>
</div>
`;
list.appendChild(div);
});
}
}
}
function toggleTrain(id) {
if (expandedTrains.has(id)) expandedTrains.delete(id);
else expandedTrains.add(id);
const details = document.getElementById(`details-${id}`);
if (details) {
details.classList.toggle('open');
}
}
function updateStationDots() {
const dots = document.querySelectorAll('[id^="station-dot-"]');
dots.forEach(dot => {
const name = dot.getAttribute('data-name');
const isOnline = dot.getAttribute('data-online') === 'true';
const isBroadcasting = broadcastingStations.has(name);
dot.className = 'status-dot ' + (isBroadcasting ? 'dot-broadcasting' : (isOnline ? 'dot-online' : 'dot-offline'));
});
}
connect();
</script>
</body>
</html>