整合作业(前端)

This commit is contained in:
2026-11-03 13:29:01 +08:00
parent d710ee3283
commit 89138c5ce8
5 changed files with 199 additions and 145 deletions
+5
View File
@@ -0,0 +1,5 @@
shots/
before/
before.json
before.txt
compare.html
+1
View File
@@ -0,0 +1 @@
e91f9651
+27
View File
@@ -0,0 +1,27 @@
*, *::before, *::after { box-sizing: border-box; }
html, body { overflow-x: clip; }
html { scrollbar-color: var(--color-muted) var(--color-paper); scroll-padding-top: var(--space-3xl); }
body { margin: 0; background: var(--color-paper); color: var(--color-ink); font-family: var(--font-body); font-size: var(--text-md); line-height: 1.55; -webkit-font-smoothing: antialiased; caret-color: var(--color-accent); }
::selection { background: color-mix(in oklab, var(--color-accent) 22%, transparent); color: var(--color-ink); }
:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.16em; }
h1, h2, h3 { margin: 0; font-family: var(--font-display); font-weight: var(--display-weight, 700); font-synthesis: none; letter-spacing: var(--tracking-display); line-height: 1.05; overflow-wrap: break-word; min-width: 0; text-wrap: balance; }
h1 { max-width: 20ch; font-size: var(--text-display); } h2 { max-width: 30ch; font-size: var(--text-section); } h3 { max-width: 40ch; font-size: var(--text-title); line-height: 1.2; }
.lead { font-size: var(--text-lead); line-height: 1.45; max-width: 52ch; }
p { margin: 0; text-wrap: pretty; }
p:not([class]) { max-width: 65ch; }
img, video { max-width: 100%; height: auto; display: block; }
svg { display: block; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; }
.container { width: 100%; max-width: var(--container); margin-inline: auto; padding-inline: var(--gutter); box-sizing: border-box; }
.num, .figure, td.num { font-variant-numeric: tabular-nums; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
[data-slot] { position: relative; overflow: hidden; background: linear-gradient(160deg, var(--color-paper-2, var(--color-paper)), var(--color-paper-3, var(--color-paper))); }
[data-slot] > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; }
[data-slot]:has(> img) > :not(img):not([data-keep]) { display: none !important; }
@media (max-width: 60rem) { :root { --gutter: 24px; --section-gap-s: 80px; --section-gap: 96px; --section-gap-l: 120px; } }
@media (max-width: 40rem) { :root { --gutter: 16px; --section-gap-s: 56px; --section-gap: 72px; --section-gap-l: 96px; --gap-columns: 16px; } }
@media (prefers-reduced-motion: reduce) { *:not(.keep-motion), *:not(.keep-motion)::before, *:not(.keep-motion)::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; } }
/* photographs: muted sepia=8 */
[data-slot] > img { filter: saturate(0.65) contrast(0.97) sepia(0.08); }
+139 -145
View File
@@ -3,166 +3,159 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="商品列表——浏览、下载与删除商品,并查看删除日志。">
<title>商品列表</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: "Microsoft YaHei", Arial, sans-serif;
background: #f5f6fa;
min-height: 100vh;
padding: 30px 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: #fff;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0,0,0,0.08);
padding: 30px;
}
h1 { text-align: center; color: #2c3e50; margin-bottom: 20px; font-size: 28px; }
h2 { color: #2c3e50; font-size: 20px; margin: 30px 0 12px; }
.toolbar {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.toolbar .status { font-size: 14px; color: #7f8c8d; }
.btn {
padding: 8px 20px;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 14px;
transition: background 0.2s;
}
.btn-primary { background: #3498db; color: #fff; }
.btn-primary:hover { background: #2980b9; }
.btn-success { background: #2ecc71; color: #fff; }
.btn-success:hover { background: #27ae60; }
.btn-danger { background: #e74c3c; color: #fff; }
.btn-danger:hover { background: #c0392b; }
.btn-warning { background: #f39c12; color: #fff; }
.btn-warning:hover { background: #e67e22; }
table { width: 100%; border-collapse: collapse; margin-top: 10px; }
th, td {
padding: 12px 15px;
text-align: center;
border-bottom: 1px solid #ecf0f1;
}
th { background: #f8f9fa; color: #2c3e50; font-weight: 600; }
tr:hover { background: #fafafa; }
.product-image {
width: 80px; height: 80px;
object-fit: cover;
border-radius: 8px;
background: #f0f0f0;
display: flex;
align-items: center;
justify-content: center;
color: #999;
font-size: 12px;
margin: 0 auto;
overflow: hidden;
}
.product-image img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.empty { text-align: center; padding: 40px; color: #95a5a6; font-size: 16px; }
.error {
background: #fdedec; color: #e74c3c;
padding: 12px 20px; border-radius: 8px;
margin-bottom: 20px; display: none;
}
.modal-overlay {
display: none;
position: fixed;
top: 0; left: 0; width: 100%; height: 100%;
background: rgba(0,0,0,0.5);
z-index: 999;
justify-content: center;
align-items: center;
}
.modal {
background: #fff;
border-radius: 12px;
padding: 30px;
width: 360px;
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.modal h2 { margin-bottom: 20px; color: #2c3e50; }
.modal input {
width: 100%; padding: 10px 12px;
margin-bottom: 15px;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 14px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }
.login-status {
font-size: 14px;
padding: 6px 14px;
border-radius: 20px;
background: #ecf0f1;
}
.login-status.logged-in { background: #d5f5e3; color: #27ae60; }
/* Hallmark · shape: app screen · genre: modern-minimal · theme: Coral (deal 1/3, product-admin-screen-list-9604·e91f9651·2026-11-03·r0) · redesign: full
* nav: top bar, kept · signature: the product ledger (download and delete) · states: loading, empty, error, full
* axes: light/grotesk-sans/warm · posture: restrained · contrast: pass · v2.0.0 */
/* Hallmark · pre-emit critique: P4 H4 E3 S4 R5 V4 · weakest: E, contrast on muted labels; secondary text moved to ink-2 */
/* Hallmark · finish-review: subagent · 8 findings · 1 resolved 2 partial 5 listed · gap: focus trap, inline toasts and a loading skeleton are new behaviour, out of a redesign's scope */
@import url("./tokens.css");
@import url("./base.css");
.skip { position: absolute; left: var(--space-md); top: calc(-1 * var(--space-3xl)); z-index: var(--z-toast); padding: var(--space-xs) var(--space-md); background: var(--color-board); color: var(--color-board-type); border-radius: var(--radius-input); font-size: var(--text-sm); }
.skip:focus-visible { top: var(--space-md); }
.topbar { position: sticky; top: 0; z-index: var(--z-sticky-nav); background: var(--color-paper); border-bottom: 1px solid var(--color-rule); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; min-height: 56px; }
.brand { display: flex; align-items: center; gap: var(--space-2xs); }
.brand-mark { width: 10px; height: 10px; border-radius: 3px; background: var(--color-accent-2); }
.brand-title { font-size: var(--text-md); font-weight: 600; color: var(--color-ink); }
.topbar-actions { display: flex; align-items: center; gap: var(--space-2xs); }
.page { display: grid; gap: var(--space-xl); padding-block: var(--space-xl); }
.panel { background: var(--color-cotton); border: 1px solid var(--color-rule); border-radius: var(--radius-card); box-shadow: var(--cast-stock); overflow: hidden; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-md); padding: var(--space-md) var(--space-lg); border-bottom: 1px solid var(--color-rule); }
.panel-head h1, .panel-head h2 { font-size: var(--text-md); font-weight: 600; letter-spacing: 0; }
.status { font-size: var(--text-sm); color: var(--color-ink-2); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: var(--space-sm) var(--space-md); text-align: left; border-bottom: 1px solid var(--color-rule); font-size: var(--text-sm); vertical-align: middle; }
th { color: var(--color-ink-2); font-weight: 500; font-size: var(--text-xs); background: var(--color-paper-2); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--color-paper-2); }
#productTable th:nth-child(1), #productTable td:nth-child(1),
#productTable th:nth-child(5), #productTable td:nth-child(5),
#logTable th:nth-child(1), #logTable td:nth-child(1),
#logTable th:nth-child(3), #logTable td:nth-child(3) { text-align: right; font-variant-numeric: tabular-nums; }
#productTable th:nth-child(2), #productTable td:nth-child(2) { text-align: center; }
#productTable td:nth-child(6) { white-space: nowrap; }
#productTable td:nth-child(4) { color: var(--color-ink-2); }
.product-image { width: 48px; height: 48px; border-radius: var(--radius-input); background: var(--color-paper-3); overflow: hidden; display: inline-flex; align-items: center; justify-content: center; text-align: center; font-size: var(--text-xs); color: var(--color-ink-2); vertical-align: middle; }
.product-image img { width: 100%; height: 100%; object-fit: cover; display: block; }
.price { font-weight: 600; }
.btn { display: inline-block; min-height: 34px; padding: 0 var(--space-md); border: 1px solid transparent; border-radius: var(--radius-stock); font-size: var(--text-sm); font-weight: 500; line-height: 32px; white-space: nowrap; cursor: pointer; background: transparent; transition: background-color var(--dur-micro) var(--ease-out), color var(--dur-micro) var(--ease-out), border-color var(--dur-micro) var(--ease-out), transform var(--dur-micro) var(--ease-out); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary, .btn-success { background: var(--color-board); color: var(--color-board-type); box-shadow: var(--cast-stock); }
.btn-primary:hover, .btn-success:hover { background: var(--color-ink-2); }
.btn-warning { color: var(--color-ink); border-color: var(--color-accent-2); }
.btn-warning:hover { background: color-mix(in oklab, var(--color-accent) 12%, transparent); }
.btn-danger { color: var(--color-error-ink); border-color: color-mix(in oklab, var(--color-error) 45%, transparent); }
.btn-danger:hover { background: color-mix(in oklab, var(--color-error) 10%, transparent); }
.btn-ghost { color: var(--color-ink-2); border-color: var(--color-rule); }
.btn-ghost:hover { background: var(--color-paper-2); }
.login-status { display: inline-block; padding: var(--space-2xs) var(--space-sm); border-radius: var(--radius-pill); font-size: var(--text-xs); color: var(--color-ink-2); background: var(--color-paper-2); border: 1px solid var(--color-rule); }
.login-status.logged-in { color: var(--color-accent-ink); background: color-mix(in oklab, var(--color-accent) 16%, var(--color-paper)); border-color: color-mix(in oklab, var(--color-accent) 35%, transparent); }
.empty { padding: var(--space-xl); text-align: center; color: var(--color-ink-2); font-size: var(--text-sm); }
.error { display: none; padding: var(--space-sm) var(--space-lg); color: var(--color-error-ink); background: color-mix(in oklab, var(--color-error) 8%, var(--color-paper)); border-bottom: 1px solid color-mix(in oklab, var(--color-error) 25%, transparent); font-size: var(--text-sm); }
.modal-overlay { display: none; position: fixed; inset: 0; background: var(--color-scrim); z-index: var(--z-modal); align-items: center; justify-content: center; padding: var(--space-md); }
.modal { width: 360px; max-width: 100%; background: var(--color-cotton); border: 1px solid var(--color-rule); border-radius: var(--radius-card); padding: var(--space-lg); box-shadow: var(--shadow-card); }
.modal h2 { font-size: var(--text-md); font-weight: 600; letter-spacing: 0; margin-bottom: var(--space-md); }
.modal label { display: block; margin-bottom: var(--space-2xs); font-size: var(--text-sm); color: var(--color-ink-2); }
.modal input { width: 100%; min-height: 36px; padding: 0 var(--space-sm); margin-bottom: var(--space-sm); border: 1px solid var(--color-muted); border-radius: var(--radius-input); background: var(--color-paper); color: var(--color-ink); font-size: var(--text-sm); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--space-2xs); margin-top: var(--space-sm); }
@media (max-width: 40rem) {
.topbar-inner { padding-inline: var(--space-sm); }
.panel-head { padding: var(--space-sm) var(--space-md); }
}
</style>
</head>
<body>
<div class="container">
<h1>🛒 商品列表</h1>
<a class="skip" href="#main">跳到主要内容</a>
<div class="toolbar">
<div class="status" id="statusText">加载商品中...</div>
<div>
<span id="loginStatus" class="login-status">未登录</span>
<button id="loginBtn" class="btn btn-primary" style="margin-left:10px;">登录</button>
<button id="logoutBtn" class="btn btn-danger" style="margin-left:5px; display:none;">退出</button>
</div>
<header class="topbar">
<div class="topbar-inner container">
<div class="brand">
<span class="brand-mark" aria-hidden="true"></span>
<span class="brand-title">商品列表</span>
</div>
<div class="topbar-actions">
<span id="loginStatus" class="login-status">未登录</span>
<button id="loginBtn" class="btn btn-primary">登录</button>
<button id="logoutBtn" class="btn btn-danger" style="display:none;">退出</button>
</div>
</div>
</header>
<div class="error" id="errorBox"></div>
<table id="productTable" style="display:none;">
<main id="main" class="container page">
<section class="panel" aria-labelledby="products-heading">
<div class="panel-head">
<h1 id="products-heading">商品管理</h1>
<div class="status" id="statusText">加载商品中…</div>
</div>
<div class="error" id="errorBox" role="alert"></div>
<div class="table-wrap">
<table id="productTable" style="display:none;">
<thead>
<tr>
<th>ID</th>
<th>图片</th>
<th>名称</th>
<th>描述</th>
<th>价格</th>
<th>操作</th>
</tr>
<tr>
<th>ID</th>
<th>图片</th>
<th>名称</th>
<th>描述</th>
<th>价格</th>
<th>操作</th>
</tr>
</thead>
<tbody id="productBody"></tbody>
</table>
</table>
</div>
<div id="emptyBox" class="empty" style="display:none;">暂无商品</div>
</section>
<h2>删除日志</h2>
<table id="logTable" style="display:none;">
<section class="panel" aria-labelledby="logs-heading">
<div class="panel-head">
<h2 id="logs-heading">删除日志</h2>
</div>
<div class="table-wrap">
<table id="logTable" style="display:none;">
<thead>
<tr>
<th>ID</th>
<th>操作人</th>
<th>商品ID</th>
<th>删除时间</th>
</tr>
<tr>
<th>ID</th>
<th>操作人</th>
<th>商品ID</th>
<th>删除时间</th>
</tr>
</thead>
<tbody id="logBody"></tbody>
</table>
</table>
</div>
<div id="logEmpty" class="empty" style="display:none;">暂无日志</div>
</div>
</section>
</main>
<div class="modal-overlay" id="modalOverlay">
<div class="modal">
<h2>用户登录</h2>
<input type="text" id="usernameInput" placeholder="用户名">
<input type="password" id="passwordInput" placeholder="密码">
<div class="modal-actions">
<button class="btn" id="cancelLogin">取消</button>
<button class="btn btn-primary" id="confirmLogin">登录</button>
</div>
<div class="modal" role="dialog" aria-modal="true" aria-labelledby="loginTitle">
<h2 id="loginTitle">用户登录</h2>
<label for="usernameInput">用户名</label>
<input type="text" id="usernameInput" placeholder="请输入用户名">
<label for="passwordInput">密码</label>
<input type="password" id="passwordInput" placeholder="请输入密码">
<div class="modal-actions">
<button class="btn btn-ghost" id="cancelLogin">取消</button>
<button class="btn btn-primary" id="confirmLogin">登录</button>
</div>
</div>
</div>
<script>
@@ -186,7 +179,7 @@
// ========== 商品加载 ==========
async function loadProducts() {
$('statusText').textContent = '加载商品中...';
$('statusText').textContent = '加载商品中…';
$('errorBox').style.display = 'none';
try {
const res = await fetch(`${API}/prodect`);
@@ -260,8 +253,7 @@
const tdPrice = document.createElement('td');
const priceSpan = document.createElement('span');
priceSpan.style.color = '#e74c3c';
priceSpan.style.fontWeight = 'bold';
priceSpan.className = 'num price';
priceSpan.textContent = `¥${price.toFixed(2)}`;
tdPrice.appendChild(priceSpan);
tr.appendChild(tdPrice);
@@ -277,7 +269,6 @@
const delBtn = document.createElement('button');
delBtn.className = 'btn btn-danger';
delBtn.textContent = '删除';
delBtn.style.marginLeft = '6px';
delBtn.onclick = () => deleteProduct(p.id);
tdAction.appendChild(delBtn);
@@ -464,6 +455,9 @@
$('modalOverlay').onclick = e => {
if (e.target === $('modalOverlay')) hideLogin();
};
document.addEventListener('keydown', e => {
if (e.key === 'Escape' && $('modalOverlay').style.display === 'flex') hideLogin();
});
// ========== 初始化 ==========
updateLoginUI();
@@ -471,4 +465,4 @@
loadLogs();
</script>
</body>
</html>
</html>
+27
View File
@@ -0,0 +1,27 @@
:root {
color-scheme: light;
--space-3xs: 2px; --space-2xs: 4px; --space-xs: 8px; --space-sm: 12px; --space-md: 16px; --space-lg: 24px; --space-xl: 40px; --space-2xl: 64px; --space-3xl: 96px; --space-4xl: 144px;
--text-xs: 0.75rem; --text-sm: 0.875rem; --text-md: 1rem; --text-lg: 1.2rem; --text-xl: 1.44rem; --text-2xl: 1.728rem; --text-3xl: 2.074rem;
--text-display-s: 1.44rem; --text-display: 1.728rem; --text-section: 1.2rem; --text-title: 1rem; --text-lead: 1rem;
--ease-out: cubic-bezier(0.16, 1, 0.3, 1); --ease-in: cubic-bezier(0.7, 0, 0.84, 0); --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
--dur-micro: 120ms; --dur-short: 220ms; --dur-long: 420ms;
--color-error: oklch(52% 0.19 27); --color-error-ink: oklch(44% 0.17 27); --color-success: oklch(50% 0.12 150); --color-scrim: color-mix(in oklab, var(--color-ink) 48%, transparent);
--container: 1440px; --gutter: 64px; --gap-columns: 32px; --section-gap-s: 120px; --section-gap: 144px; --section-gap-l: 176px;
--z-base: 1; --z-raised: 10; --z-dropdown: 100; --z-sticky: 200; --z-sticky-nav: 300; --z-modal: 400; --z-toast: 500; --z-tooltip: 600;
--color-paper: oklch(97% 0.006 55); --color-paper-2: oklch(94.5% 0.007 55); --color-paper-3: oklch(91.5% 0.009 55);
--color-ink: oklch(21% 0.012 38); --color-ink-2: oklch(29% 0.013 40); --color-muted: oklch(47% 0.013 45);
--color-rule: oklch(87% 0.009 55); --color-rule-2: oklch(81% 0.011 55);
--color-accent: oklch(74% 0.125 30); --color-accent-ink: oklch(21% 0.012 38); --color-accent-2: oklch(54% 0.165 29); --color-focus: oklch(54% 0.17 30);
--color-cotton: oklch(98.8% 0.0045 80); --color-desk: oklch(94.3% 0.008 64); --color-print: oklch(23% 0.012 38);
--color-board: oklch(22% 0.011 40); --color-board-type: oklch(96.5% 0.006 70); --color-paid: oklch(55.5% 0.15 33);
--tex-cotton: url("cotton.svg"); --tex-desk: url("felt.svg");
--shade: 32% 0.03 50; --lit: 100% 0.005 80; --deep: 7% 0.01 40;
--font-display: "PingFang SC", "Microsoft YaHei", ui-sans-serif, system-ui, sans-serif; --font-body: var(--font-display);
--font-outlier: ui-monospace, "SFMono-Regular", "Consolas", "Liberation Mono", monospace;
--radius-card: 8px; --radius-input: 6px; --radius-pill: 999px; --radius-stock: 8px; --rule-hair: 1px;
--shadow-card: 0 1px 2px oklch(20% 0.01 35 / 0.05);
--edge-stock: inset 0 1px 0 oklch(var(--lit) / 0.9), inset 0 -1px 0 oklch(var(--shade) / 0.07), 0 0 0 0.5px oklch(var(--shade) / 0.22), 0 1px 0 oklch(var(--shade) / 0.12);
--cast-stock: 6px 5px 10px -6px oklch(var(--shade) / 0.3); --cast-stock-lift: 12px 10px 18px -8px oklch(var(--shade) / 0.3);
--press-groove: inset 1px 1.5px 2px oklch(var(--shade) / 0.16), inset -1px -1px 0 oklch(var(--lit) / 0.9), 0 0 0 0.5px oklch(var(--shade) / 0.2);
--tracking-display: -0.03em; --display-weight: 600;
}