refactor(bidding): extract CSS and reorganize file structure
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.
This commit is contained in:
280
bidding/controls/index.html
Normal file
280
bidding/controls/index.html
Normal file
@@ -0,0 +1,280 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Auction Control</title>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap"
|
||||
/>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"
|
||||
/>
|
||||
<link rel="stylesheet" href="../common/style.css" />
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<header>
|
||||
<h1><i class="fas fa-sliders-h"></i> 拍卖控制台</h1>
|
||||
<div class="channel-info">
|
||||
当前频道 ID: <span class="channel-id" id="displayId"></span>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="grid">
|
||||
<!-- 上传 CSV -->
|
||||
<div class="card">
|
||||
<div class="card-title">
|
||||
<i class="fas fa-file-csv"></i>
|
||||
<span>上传标品列表</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="file-upload">
|
||||
<div class="file-upload-btn">
|
||||
<i class="fas fa-cloud-upload-alt"></i> 选择 CSV 文件
|
||||
</div>
|
||||
<input type="file" id="csvUpload" accept=".csv" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="itemSelect">选择标品</label>
|
||||
<select id="itemSelect">
|
||||
<option value="">请先上传CSV文件</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 标品信息 -->
|
||||
<div class="card">
|
||||
<div class="card-title">
|
||||
<i class="fas fa-info-circle"></i>
|
||||
<span>标品信息</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="itemName">名称</label>
|
||||
<input type="text" id="itemName" placeholder="输入标品名称" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="itemBasePrice">底价</label>
|
||||
<input type="number" id="itemBasePrice" value="0" min="0" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="itemRemark">备注</label>
|
||||
<input type="text" id="itemRemark" placeholder="输入标品备注信息" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="itemMedia">图片/影片链接</label>
|
||||
<input type="text" id="itemMedia" placeholder="输入媒体文件URL" />
|
||||
</div>
|
||||
<button id="startAuction" class="success">
|
||||
<i class="fas fa-gavel"></i> 开始竞拍
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 竞价控制 -->
|
||||
<div class="card">
|
||||
<div class="card-title">
|
||||
<i class="fas fa-exchange-alt"></i>
|
||||
<span>竞价控制</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="currentPrice">当前价格</label>
|
||||
<input type="number" id="currentPrice" value="0" min="0" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="winnerName">得标者</label>
|
||||
<input
|
||||
type="text"
|
||||
id="winnerName"
|
||||
placeholder="留空则显示 兴 旺 发"
|
||||
/>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<button id="updatePrice">
|
||||
<i class="fas fa-sync-alt"></i> 更新价格
|
||||
</button>
|
||||
<button id="dealItem" class="success">
|
||||
<i class="fas fa-handshake"></i> 成交
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 成交历史 -->
|
||||
<div class="card">
|
||||
<div class="card-title">
|
||||
<i class="fas fa-history"></i>
|
||||
<span>成交历史</span>
|
||||
</div>
|
||||
<div class="total-amount">
|
||||
<span>总金额:</span>
|
||||
<span class="amount"><span id="totalAmount">0</span> 元</span>
|
||||
</div>
|
||||
<div class="history-container">
|
||||
<table id="historyTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>标品名称</th>
|
||||
<th>成交价</th>
|
||||
<th>得标者</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 获取 displayId
|
||||
const urlParams = new URLSearchParams(location.search);
|
||||
const displayId = urlParams.get("display");
|
||||
if (!displayId) {
|
||||
alert("缺少 display 参数!请从 display.html 获取正确链接");
|
||||
}
|
||||
document.getElementById("displayId").textContent = displayId;
|
||||
|
||||
const channel = new BroadcastChannel("auction-" + displayId);
|
||||
|
||||
const itemSelect = document.getElementById("itemSelect");
|
||||
const itemName = document.getElementById("itemName");
|
||||
const itemBasePrice = document.getElementById("itemBasePrice");
|
||||
const itemRemark = document.getElementById("itemRemark");
|
||||
const itemMedia = document.getElementById("itemMedia");
|
||||
const currentPrice = document.getElementById("currentPrice");
|
||||
const winnerName = document.getElementById("winnerName");
|
||||
const totalAmountEl = document.getElementById("totalAmount");
|
||||
const historyTable = document
|
||||
.getElementById("historyTable")
|
||||
.querySelector("tbody");
|
||||
|
||||
let totalAmount = 0;
|
||||
let csvItems = [];
|
||||
|
||||
// 解析 CSV
|
||||
document.getElementById("csvUpload").addEventListener("change", (e) => {
|
||||
const file = e.target.files[0];
|
||||
if (!file) return;
|
||||
|
||||
const reader = new FileReader();
|
||||
reader.onload = (ev) => {
|
||||
const lines = ev.target.result.split(/\r?\n/).filter((l) => l.trim());
|
||||
csvItems = lines.map((l) => {
|
||||
const [name, basePrice, remark, media] = l.split(",");
|
||||
return { name, basePrice: Number(basePrice), remark, media };
|
||||
});
|
||||
refreshItemSelect();
|
||||
|
||||
// 更新文件上传按钮文本
|
||||
const uploadBtn = document.querySelector(".file-upload-btn");
|
||||
uploadBtn.innerHTML = `<i class="fas fa-check-circle"></i> ${file.name}`;
|
||||
uploadBtn.style.borderColor = "var(--accent-green)";
|
||||
uploadBtn.style.background = "rgba(0, 200, 83, 0.1)";
|
||||
};
|
||||
reader.readAsText(file);
|
||||
});
|
||||
|
||||
function refreshItemSelect() {
|
||||
itemSelect.innerHTML = "";
|
||||
csvItems.forEach((it, idx) => {
|
||||
const opt = document.createElement("option");
|
||||
opt.value = idx;
|
||||
opt.textContent = it.name;
|
||||
itemSelect.appendChild(opt);
|
||||
});
|
||||
}
|
||||
|
||||
itemSelect.addEventListener("change", () => {
|
||||
const idx = itemSelect.value;
|
||||
if (csvItems[idx]) {
|
||||
const it = csvItems[idx];
|
||||
itemName.value = it.name;
|
||||
itemBasePrice.value = it.basePrice;
|
||||
itemRemark.value = it.remark;
|
||||
itemMedia.value = it.media;
|
||||
currentPrice.value = it.basePrice;
|
||||
}
|
||||
});
|
||||
|
||||
// 开始竞拍
|
||||
document.getElementById("startAuction").addEventListener("click", () => {
|
||||
if (!itemName.value) {
|
||||
alert("请输入标品名称");
|
||||
return;
|
||||
}
|
||||
|
||||
const msg = {
|
||||
type: "showItem",
|
||||
name: itemName.value,
|
||||
basePrice: Number(itemBasePrice.value),
|
||||
remark: itemRemark.value,
|
||||
media: itemMedia.value,
|
||||
};
|
||||
channel.postMessage(msg);
|
||||
currentPrice.value = itemBasePrice.value;
|
||||
|
||||
// 添加视觉反馈
|
||||
const btn = document.getElementById("startAuction");
|
||||
btn.innerHTML = '<i class="fas fa-check"></i> 已开始';
|
||||
btn.style.background = "var(--accent-green)";
|
||||
setTimeout(() => {
|
||||
btn.innerHTML = '<i class="fas fa-gavel"></i> 开始竞拍';
|
||||
btn.style.background = "var(--primary)";
|
||||
}, 2000);
|
||||
});
|
||||
|
||||
// 更新价格
|
||||
document.getElementById("updatePrice").addEventListener("click", () => {
|
||||
const msg = {
|
||||
type: "updatePrice",
|
||||
price: Number(currentPrice.value),
|
||||
};
|
||||
channel.postMessage(msg);
|
||||
|
||||
// 添加视觉反馈
|
||||
const btn = document.getElementById("updatePrice");
|
||||
btn.innerHTML = '<i class="fas fa-check"></i> 已更新';
|
||||
setTimeout(() => {
|
||||
btn.innerHTML = '<i class="fas fa-sync-alt"></i> 更新价格';
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
// 成交
|
||||
document.getElementById("dealItem").addEventListener("click", () => {
|
||||
const price = Number(currentPrice.value);
|
||||
const winner = winnerName.value || "";
|
||||
const msg = { type: "deal", price, winner };
|
||||
channel.postMessage(msg);
|
||||
|
||||
// 保存历史
|
||||
const tr = document.createElement("tr");
|
||||
tr.innerHTML = `
|
||||
<td>${itemName.value}</td>
|
||||
<td>¥${price}</td>
|
||||
<td>${winner || "兴 旺 发"}</td>
|
||||
`;
|
||||
historyTable.appendChild(tr);
|
||||
|
||||
totalAmount += price;
|
||||
totalAmountEl.textContent = totalAmount;
|
||||
|
||||
// 添加视觉反馈
|
||||
const btn = document.getElementById("dealItem");
|
||||
btn.innerHTML = '<i class="fas fa-check"></i> 已成交';
|
||||
setTimeout(() => {
|
||||
btn.innerHTML = '<i class="fas fa-handshake"></i> 成交';
|
||||
}, 2000);
|
||||
|
||||
// 清空当前标品信息
|
||||
itemName.value = "";
|
||||
itemBasePrice.value = "0";
|
||||
itemRemark.value = "";
|
||||
itemMedia.value = "";
|
||||
currentPrice.value = "0";
|
||||
winnerName.value = "";
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
266
bidding/controls/style.css
Normal file
266
bidding/controls/style.css
Normal file
@@ -0,0 +1,266 @@
|
||||
.container {
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 2rem;
|
||||
padding-bottom: 1rem;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2.2rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.channel-info {
|
||||
background: var(--dark-3);
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: var(--radius);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.channel-id {
|
||||
color: var(--accent);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
|
||||
gap: 1.5rem;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
transform: translateY(-5px);
|
||||
box-shadow: 0 15px 30px -10px rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.card-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 1.2rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 1.5rem;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.card-title i {
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 1.2rem;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 0.5rem;
|
||||
font-weight: 500;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
input,
|
||||
select,
|
||||
textarea,
|
||||
button {
|
||||
width: 100%;
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: var(--radius);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
background: var(--dark-3);
|
||||
color: var(--text-primary);
|
||||
font-family: "Inter", sans-serif;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
input:focus,
|
||||
select:focus,
|
||||
textarea:focus {
|
||||
outline: none;
|
||||
border-color: var(--primary);
|
||||
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
|
||||
}
|
||||
|
||||
button {
|
||||
background: var(--primary);
|
||||
color: white;
|
||||
border: none;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.9rem 1.5rem;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background: var(--primary-dark);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
button.secondary {
|
||||
background: var(--dark-3);
|
||||
}
|
||||
|
||||
button.secondary:hover {
|
||||
background: var(--dark-2);
|
||||
}
|
||||
|
||||
button.success {
|
||||
background: var(--accent-green);
|
||||
}
|
||||
|
||||
button.success:hover {
|
||||
background: #00b34d;
|
||||
}
|
||||
|
||||
.btn-group {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 0.8rem;
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
.file-upload {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.file-upload-btn {
|
||||
background: var(--dark-3);
|
||||
color: var(--text-primary);
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: var(--radius);
|
||||
border: 1px dashed rgba(255, 255, 255, 0.2);
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.file-upload-btn:hover {
|
||||
border-color: var(--primary);
|
||||
background: rgba(37, 99, 235, 0.1);
|
||||
}
|
||||
|
||||
.file-upload input[type="file"] {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
opacity: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.history-container {
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
margin-top: 1rem;
|
||||
border-radius: var(--radius);
|
||||
background: var(--dark-3);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
padding: 0.75rem 1rem;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
th {
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
tr:last-child td {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
tr:hover {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
.total-amount {
|
||||
margin-top: 1.5rem;
|
||||
padding: 1rem;
|
||||
background: rgba(0, 200, 83, 0.1);
|
||||
border-radius: var(--radius);
|
||||
border: 1px solid rgba(0, 200, 83, 0.2);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.amount {
|
||||
color: var(--accent);
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 768px) {
|
||||
.grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
header {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.btn-group {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
/* 动画 */
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(10px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.card {
|
||||
animation: fadeIn 0.5s ease-out;
|
||||
}
|
||||
|
||||
.card:nth-child(1) {
|
||||
animation-delay: 0.1s;
|
||||
}
|
||||
.card:nth-child(2) {
|
||||
animation-delay: 0.2s;
|
||||
}
|
||||
.card:nth-child(3) {
|
||||
animation-delay: 0.3s;
|
||||
}
|
||||
.card:nth-child(4) {
|
||||
animation-delay: 0.4s;
|
||||
}
|
||||
Reference in New Issue
Block a user