Refactored the bidding application by reorganizing the file structure and extracting CSS into separate files. - The monolithic `control.html` and `display.html` files have been moved into dedicated `controls/` and `display/` directories. - All inline CSS has been extracted into component-specific `style.css` files. - A new `common/style.css` has been created to hold shared styles, promoting reusability and reducing duplication. These changes improve the project's modularity, separation of concerns (HTML/CSS), and long-term maintainability without affecting external behavior.
230 lines
7.5 KiB
HTML
230 lines
7.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<title>Auction Display</title>
|
|
<link
|
|
rel="stylesheet"
|
|
href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap"
|
|
/>
|
|
<link rel="stylesheet" href="../common/style.css" />
|
|
<link rel="stylesheet" href="style.css" />
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<!-- 初次加载提示 -->
|
|
<div id="guide" class="card center visible">
|
|
<h1>拍卖展示系统</h1>
|
|
<p>
|
|
请将此窗口拖曳到大屏幕并按下
|
|
<span class="highlight">F11</span> 进入全屏展示模式
|
|
</p>
|
|
<p>使用控制端链接进行远程操作:</p>
|
|
<a href="#" class="control-link">
|
|
<svg
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
width="20"
|
|
height="20"
|
|
viewBox="0 0 24 24"
|
|
fill="none"
|
|
stroke="currentColor"
|
|
stroke-width="2"
|
|
stroke-linecap="round"
|
|
stroke-linejoin="round"
|
|
>
|
|
<path
|
|
d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"
|
|
></path>
|
|
<path
|
|
d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"
|
|
></path>
|
|
</svg>
|
|
<span id="controlLink"></span>
|
|
</a>
|
|
</div>
|
|
|
|
<!-- Splash Screen -->
|
|
<div id="splash" class="card center hidden">
|
|
<div class="splash-logo">
|
|
<img
|
|
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiNmZmZmZmYiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48Y2lyY2xlIGN4PSIxMiIgY3k9IjEyIiByPSIxMCI+PC9jaXJjbGU+PHBhdGggZD0iTTE2IDhsLTQgNC04LTgiPjwvcGF0aD48L3N2Zz4="
|
|
alt="Logo"
|
|
/>
|
|
</div>
|
|
<div class="splash-text">Studio Name</div>
|
|
<p>拍卖即将开始</p>
|
|
</div>
|
|
|
|
<!-- 标品展示 -->
|
|
<div id="itemView" class="card center hidden">
|
|
<div class="itemMedia"></div>
|
|
<div class="name"></div>
|
|
<div class="remark"></div>
|
|
<div class="price-container">
|
|
<div class="price">
|
|
<span class="currency">¥</span><span class="price-value">0</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 成交界面 -->
|
|
<div id="dealView" class="card center hidden">
|
|
<div class="deal-icon">🎉</div>
|
|
<div class="deal">成交!</div>
|
|
<div class="finalPrice"></div>
|
|
<div class="winner"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 总金额 -->
|
|
<div class="footer">
|
|
<svg
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
width="20"
|
|
height="20"
|
|
viewBox="0 0 24 24"
|
|
fill="none"
|
|
stroke="currentColor"
|
|
stroke-width="2"
|
|
stroke-linecap="round"
|
|
stroke-linejoin="round"
|
|
>
|
|
<line x1="12" y1="1" x2="12" y2="23"></line>
|
|
<path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"></path>
|
|
</svg>
|
|
总金额: <span id="totalAmount">0</span> 元
|
|
</div>
|
|
|
|
<script>
|
|
// 获取或生成频道 ID
|
|
function getOrCreateDisplayId() {
|
|
const urlParams = new URLSearchParams(location.search);
|
|
let id = urlParams.get("display");
|
|
if (!id) {
|
|
id =
|
|
Math.random().toString(36).slice(2, 12) + Date.now().toString(36);
|
|
location.href = location.pathname + "?display=" + id;
|
|
}
|
|
return id;
|
|
}
|
|
|
|
const displayId = getOrCreateDisplayId();
|
|
const channel = new BroadcastChannel("auction-" + displayId);
|
|
|
|
// DOM 元素
|
|
const guide = document.getElementById("guide")
|
|
const controlLinkA = document.getElementsByClassName("control-link")[0];
|
|
const controlLink = document.getElementById("controlLink");
|
|
const splash = document.getElementById("splash");
|
|
const itemView = document.getElementById("itemView");
|
|
const dealView = document.getElementById("dealView");
|
|
const totalAmountEl = document.getElementById("totalAmount");
|
|
|
|
const itemMedia = itemView.querySelector(".itemMedia");
|
|
const itemName = itemView.querySelector(".name");
|
|
const itemRemark = itemView.querySelector(".remark");
|
|
const itemPrice = itemView.querySelector(".price-value");
|
|
|
|
const dealPrice = dealView.querySelector(".finalPrice");
|
|
const dealWinner = dealView.querySelector(".winner");
|
|
|
|
let currentPrice = 0;
|
|
let targetPrice = 0;
|
|
let totalAmount = 0;
|
|
|
|
// 设置控制端链接
|
|
controlLink.innerText =
|
|
location.origin + "/bidding/controls/?display=" + displayId;
|
|
controlLinkA.href =
|
|
location.origin + "/bidding/controls/?display=" + displayId;
|
|
|
|
// 视图切换函数
|
|
function showView(view) {
|
|
// 隐藏所有视图
|
|
[guide, splash, itemView, dealView].forEach((v) => {
|
|
v.classList.remove("visible");
|
|
v.classList.add("hidden");
|
|
});
|
|
|
|
// 显示指定视图
|
|
setTimeout(() => {
|
|
view.classList.remove("hidden");
|
|
setTimeout(() => {
|
|
view.classList.add("visible");
|
|
}, 50);
|
|
}, 300);
|
|
}
|
|
|
|
// 展示 Splash
|
|
setTimeout(() => {
|
|
showView(splash);
|
|
setTimeout(() => {
|
|
// splash 展示后不自动隐藏,等待消息
|
|
}, 2000);
|
|
}, 3000);
|
|
|
|
// 动态价格更新 (Lerp)
|
|
function animatePrice() {
|
|
if (Math.abs(targetPrice - currentPrice) > 1) {
|
|
currentPrice += (targetPrice - currentPrice) * 0.1;
|
|
itemPrice.textContent = Math.round(currentPrice);
|
|
requestAnimationFrame(animatePrice);
|
|
} else {
|
|
currentPrice = targetPrice;
|
|
itemPrice.textContent = currentPrice;
|
|
}
|
|
}
|
|
|
|
// 监听消息
|
|
channel.onmessage = (ev) => {
|
|
const msg = ev.data;
|
|
if (msg.type === "showItem") {
|
|
showView(itemView);
|
|
|
|
// 更新标品信息
|
|
itemName.textContent = msg.name;
|
|
itemRemark.textContent = msg.remark || "";
|
|
if (msg.media) {
|
|
if (msg.media.endsWith(".mp4")) {
|
|
itemMedia.innerHTML = `<video src="${msg.media}" autoplay loop muted></video>`;
|
|
} else {
|
|
itemMedia.innerHTML = `<img src="${msg.media}" alt="${msg.name}">`;
|
|
}
|
|
} else {
|
|
itemMedia.innerHTML = "";
|
|
}
|
|
|
|
currentPrice = 0;
|
|
targetPrice = msg.basePrice || 0;
|
|
itemPrice.textContent = currentPrice;
|
|
animatePrice();
|
|
}
|
|
|
|
if (msg.type === "updatePrice") {
|
|
targetPrice = msg.price;
|
|
itemPrice.parentElement.classList.add("price-update");
|
|
setTimeout(() => {
|
|
itemPrice.parentElement.classList.remove("price-update");
|
|
}, 500);
|
|
animatePrice();
|
|
}
|
|
|
|
if (msg.type === "deal") {
|
|
showView(dealView);
|
|
dealPrice.textContent = "成交价: ¥" + msg.price;
|
|
dealWinner.textContent = "得标者: " + (msg.winner || "兴 旺 发");
|
|
totalAmount += msg.price;
|
|
totalAmountEl.textContent = totalAmount;
|
|
|
|
// 添加庆祝效果
|
|
const dealIcon = document.querySelector(".deal-icon");
|
|
dealIcon.style.animation = "none";
|
|
setTimeout(() => {
|
|
dealIcon.style.animation = "celebrate 1s ease-out";
|
|
}, 10);
|
|
}
|
|
};
|
|
</script>
|
|
</body>
|
|
</html>
|