174 lines
5.3 KiB
HTML
174 lines
5.3 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>DRS9 查看器</title>
|
||
<style>
|
||
* {
|
||
margin: 0;
|
||
padding: 0;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
body {
|
||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||
background: #000;
|
||
overflow: hidden;
|
||
}
|
||
|
||
#viewer {
|
||
width: 100vw;
|
||
height: 100vh;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
|
||
#viewer iframe {
|
||
width: 100%;
|
||
height: 100%;
|
||
border: none;
|
||
}
|
||
|
||
#viewer img {
|
||
max-width: 100%;
|
||
max-height: 100%;
|
||
object-fit: contain;
|
||
}
|
||
|
||
#viewer video {
|
||
width: 100%;
|
||
height: 100%;
|
||
object-fit: contain;
|
||
}
|
||
|
||
.loading {
|
||
color: #fff;
|
||
font-size: 18px;
|
||
}
|
||
|
||
.error {
|
||
color: #f44;
|
||
text-align: center;
|
||
padding: 20px;
|
||
}
|
||
|
||
.info {
|
||
position: fixed;
|
||
top: 10px;
|
||
right: 10px;
|
||
background: rgba(0, 0, 0, 0.7);
|
||
color: #fff;
|
||
padding: 10px 20px;
|
||
border-radius: 5px;
|
||
font-size: 14px;
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div id="viewer">
|
||
<div class="loading">正在加载内容...</div>
|
||
</div>
|
||
|
||
<script>
|
||
const API_BASE = '/api/guest';
|
||
|
||
// 从 URL 获取设备 ID
|
||
const urlParams = new URLSearchParams(window.location.search);
|
||
const deviceId = urlParams.get('deviceId') || urlParams.get('d');
|
||
|
||
if (!deviceId) {
|
||
showError('请指定设备 ID:?deviceId=1 或 ?d=1');
|
||
} else {
|
||
loadContent(deviceId);
|
||
}
|
||
|
||
async function loadContent(deviceId) {
|
||
try {
|
||
// 先尝试获取播放列表
|
||
const playlistRes = await fetch(`${API_BASE}/playlist/${deviceId}`);
|
||
const playlistData = await playlistRes.json();
|
||
|
||
if (playlistData.success && playlistData.data.length > 0) {
|
||
showPlaylist(playlistData.data, playlistData.loopMode);
|
||
} else {
|
||
// 回退到直接获取内容
|
||
const contentRes = await fetch(`${API_BASE}/content/${deviceId}`);
|
||
const contentData = await contentRes.json();
|
||
|
||
if (contentData.success && contentData.data.length > 0) {
|
||
showContent(contentData.data);
|
||
} else {
|
||
showError('暂无内容');
|
||
}
|
||
}
|
||
|
||
// 显示设备信息
|
||
document.getElementById('viewer').innerHTML += `
|
||
<div class="info">设备 ${deviceId}</div>
|
||
`;
|
||
} catch (err) {
|
||
showError('加载失败:' + err.message);
|
||
}
|
||
}
|
||
|
||
function showPlaylist(items, loopMode) {
|
||
let currentIndex = 0;
|
||
|
||
const showItem = (index) => {
|
||
if (index >= items.length) {
|
||
if (loopMode === 'Loop') {
|
||
index = 0;
|
||
} else {
|
||
// Once 模式,结束
|
||
return;
|
||
}
|
||
}
|
||
|
||
const item = items[index];
|
||
const duration = item.duration * 1000;
|
||
|
||
if (item.applicationType === 'Video' || item.contentUrl.endsWith('.mp4')) {
|
||
document.getElementById('viewer').innerHTML = `
|
||
<video src="${item.contentUrl}" autoplay muted></video>
|
||
`;
|
||
const video = document.querySelector('video');
|
||
video.onended = () => showItem(index + 1);
|
||
} else if (item.applicationType === 'Image' || /\.(jpg|jpeg|png|gif|svg|webp)$/i.test(item.contentUrl)) {
|
||
document.getElementById('viewer').innerHTML = `
|
||
<img src="${item.contentUrl}" alt="${item.applicationName}">
|
||
`;
|
||
setTimeout(() => showItem(index + 1), duration);
|
||
} else {
|
||
// Web 内容
|
||
document.getElementById('viewer').innerHTML = `
|
||
<iframe src="${item.contentUrl}" sandbox="allow-scripts allow-same-origin allow-forms"></iframe>
|
||
`;
|
||
setTimeout(() => showItem(index + 1), duration);
|
||
}
|
||
|
||
currentIndex = index;
|
||
};
|
||
|
||
showItem(0);
|
||
}
|
||
|
||
function showContent(items) {
|
||
showPlaylist(items.map(item => ({
|
||
applicationName: item.applicationName,
|
||
applicationType: item.applicationType,
|
||
contentUrl: item.contentUrl,
|
||
duration: item.duration
|
||
})), 'Loop');
|
||
}
|
||
|
||
function showError(message) {
|
||
document.getElementById('viewer').innerHTML = `
|
||
<div class="error">${message}</div>
|
||
`;
|
||
}
|
||
</script>
|
||
</body>
|
||
</html>
|