初始提交
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
<!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;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.user-icon {
|
||||
position: absolute;
|
||||
right: 20px;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 50%;
|
||||
background: #f0f0f0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.user-icon:hover {
|
||||
background: #e0e0e0;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.image-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 30px;
|
||||
}
|
||||
|
||||
.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>
|
||||
let currentGroupIndex = 0;
|
||||
let groups = [];
|
||||
let timer = null;
|
||||
|
||||
function checkLogin() {
|
||||
if (!localStorage.getItem('token')) {
|
||||
window.location.href = '/login';
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', loadDisplay);
|
||||
|
||||
async function loadDisplay() {
|
||||
try {
|
||||
const res = await fetch('/api/display');
|
||||
const data = await res.json();
|
||||
|
||||
if (!data.enabled || data.groups.length === 0) {
|
||||
document.getElementById('empty').style.display = 'block';
|
||||
return;
|
||||
}
|
||||
|
||||
document.getElementById('empty').style.display = 'none';
|
||||
groups = data.groups;
|
||||
showGroup(0);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
function showGroup(index) {
|
||||
if (index >= groups.length) index = 0;
|
||||
currentGroupIndex = index;
|
||||
|
||||
const group = groups[index];
|
||||
const grid = document.getElementById('imageGrid');
|
||||
grid.innerHTML = '';
|
||||
|
||||
group.images.forEach(img => {
|
||||
const div = document.createElement('div');
|
||||
div.className = 'image-item';
|
||||
|
||||
const imgEl = document.createElement('img');
|
||||
imgEl.src = '/uploads/' + img.filename;
|
||||
imgEl.loading = 'lazy';
|
||||
|
||||
let pressTimer;
|
||||
imgEl.addEventListener('touchstart', function() {
|
||||
pressTimer = setTimeout(function() {
|
||||
saveImage('/uploads/' + img.filename, img.original_name);
|
||||
}, 1000);
|
||||
});
|
||||
imgEl.addEventListener('touchend', function() { clearTimeout(pressTimer); });
|
||||
imgEl.addEventListener('touchmove', function() { clearTimeout(pressTimer); });
|
||||
|
||||
div.appendChild(imgEl);
|
||||
grid.appendChild(div);
|
||||
});
|
||||
|
||||
startTimer(group.display_seconds);
|
||||
}
|
||||
|
||||
function startTimer(seconds) {
|
||||
if (timer) clearInterval(timer);
|
||||
timer = setInterval(function() {
|
||||
showGroup(currentGroupIndex + 1);
|
||||
}, seconds * 1000);
|
||||
}
|
||||
|
||||
function saveImage(url, name) {
|
||||
var a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = name || 'image.jpg';
|
||||
a.click();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user