Files
showpic/public/index.html
T
2026-07-17 09:00:02 +08:00

102 lines
2.8 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>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #fff; }
.header {
display: flex;
justify-content: center;
align-items: center;
padding: 16px 20px;
font-size: 18px;
font-weight: 500;
border-bottom: 1px solid #eee;
}
.content { padding: 30px; }
.image-grid {
display: flex;
flex-wrap: wrap;
gap: 30px;
justify-content: center;
}
.image-item {
width: 140px; height: 140px;
background: #e8e8e8;
flex-shrink: 0;
}
.image-item img {
width: 100%; height: 100%;
object-fit: cover;
display: block;
}
.empty {
text-align: center;
color: #999;
padding: 80px 0;
}
</style>
</head>
<body>
<div class="header">首页</div>
<div class="content">
<div class="image-grid" id="imageGrid"></div>
<div class="empty" id="empty">暂无图片</div>
</div>
<script>
var ws;
function connectWS() {
var protocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
ws = new WebSocket(protocol + '//' + location.host);
ws.onmessage = function(e) {
try {
var data = JSON.parse(e.data);
if (data.type === 'state') renderState(data);
} catch(err) {}
};
ws.onclose = function() {
setTimeout(connectWS, 3000);
};
}
function renderState(state) {
var grid = document.getElementById('imageGrid');
var empty = document.getElementById('empty');
if (!state.playing || state.images.length === 0) {
grid.innerHTML = '';
empty.style.display = 'block';
return;
}
empty.style.display = 'none';
grid.innerHTML = '';
state.images.forEach(function(img) {
var div = document.createElement('div');
div.className = 'image-item';
var imgEl = document.createElement('img');
imgEl.src = '/uploads/' + img.filename;
imgEl.loading = 'lazy';
div.appendChild(imgEl);
grid.appendChild(div);
});
}
connectWS();
</script>
</body>
</html>