fix(admin): 390 档表格恢复横向滚动(DEF-04)

两个列表页的表格是 `w-full`,在 356px 容器里 7 列被压成逐字竖排;
外层虽有 `overflow-x-auto`,但表格自身没有最小宽度 ⇒ **没有东西可滚**,
于是「溢出容器」变成了「挤扁内容」。sweep 的 clipping 检测为 0
(单元格没有 overflow:hidden),这个缺陷只能靠截图发现。

改法:`min-w-[760px]` 让列宽由内容撑开,关键列(标题/Slug/状态/更新时间、
用户名/昵称/邮箱/角色/状态/创建时间)加 `whitespace-nowrap`。
复现口径:`scrollWidth 760 > clientWidth 356`。

判别性测试:断言 table 带 `min-w-[760px]`、其父级带 `overflow-x-auto`;
去掉 min-w ⇒ 转红。
This commit is contained in:
zhangxiang committed 2026-11-25 08:59:55 +08:00
1 parent cfd5079dd6
commit b8b7da975d
3 files changed
+37 -21

No files matched your search

@@ -151,4 +151,20 @@ describe('内容列表页:搜索请求节流', () => {
expect(screen.getByText('新查询结果')).toBeInTheDocument();
expect(screen.queryByText('慢查询结果')).toBeNull();
});
// ── DEF-04:390 档表格必须能横向滚动,而不是把 7 列挤成一条 ──
it('表格带最小宽度并被 overflow-x-auto 容器包住(390 档可横滚)', async () => {
nav.state.params = { modelCode: 'news' };
api.getItems.mockResolvedValue(rowsResult([row('一条内容')]));
const { container } = render(<ContentListPage />);
await waitFor(() => expect(screen.getByText('一条内容')).toBeInTheDocument());
const table = container.querySelector('table');
expect(table).not.toBeNull();
// 固定版式宽:列宽由 white-space:nowrap 撑开,容器才有东西可滚
expect(table!.className).toContain('min-w-[760px]');
// 外层必须真的允许横向滚动,否则 min-w 只是把内容溢出成裁剪
const scroller = table!.parentElement;
expect(scroller!.className).toContain('overflow-x-auto');
});
});
+10 -10
View File
@@ -177,14 +177,14 @@ export default function ContentListPage() {
{/* Table */}
<div className="bg-bg-primary rounded-lg border border-border-primary overflow-hidden">
<div className="overflow-x-auto">
<table className="w-full">
<table className="w-full min-w-[760px]">
<thead>
<tr className="border-b border-border-primary bg-bg-secondary">
<th className="text-left px-4 py-3 text-xs font-medium text-text-muted uppercase">标题</th>
<th className="text-left px-4 py-3 text-xs font-medium text-text-muted uppercase">Slug</th>
<th className="text-left px-4 py-3 text-xs font-medium text-text-muted uppercase">状态</th>
<th className="text-left px-4 py-3 text-xs font-medium text-text-muted uppercase">更新时间</th>
<th className="text-right px-4 py-3 text-xs font-medium text-text-muted uppercase">操作</th>
<th className="text-left px-4 py-3 text-xs font-medium text-text-muted uppercase whitespace-nowrap">标题</th>
<th className="text-left px-4 py-3 text-xs font-medium text-text-muted uppercase whitespace-nowrap">Slug</th>
<th className="text-left px-4 py-3 text-xs font-medium text-text-muted uppercase whitespace-nowrap">状态</th>
<th className="text-left px-4 py-3 text-xs font-medium text-text-muted uppercase whitespace-nowrap">更新时间</th>
<th className="text-right px-4 py-3 text-xs font-medium text-text-muted uppercase whitespace-nowrap">操作</th>
</tr>
</thead>
<tbody className="divide-y divide-border-light">
@@ -205,15 +205,15 @@ export default function ContentListPage() {
) : (
items.map((item) => (
<tr key={item.id} className="hover:bg-bg-secondary transition-colors">
<td className="px-4 py-3">
<td className="px-4 py-3 whitespace-nowrap">
<span className="text-sm font-medium text-text-primary">{item.title}</span>
</td>
<td className="px-4 py-3">
<td className="px-4 py-3 whitespace-nowrap">
<code className="text-xs text-text-muted bg-bg-hover px-1.5 py-0.5 rounded">
{item.slug || '-'}
</code>
</td>
<td className="px-4 py-3">
<td className="px-4 py-3 whitespace-nowrap">
<span
className={`inline-flex text-xs px-2 py-0.5 rounded-full font-medium ${
item.status === 'published'
@@ -226,7 +226,7 @@ export default function ContentListPage() {
{STATUS_LABELS[item.status] || item.status}
</span>
</td>
<td className="px-4 py-3 text-sm text-text-muted">
<td className="px-4 py-3 text-sm text-text-muted whitespace-nowrap">
{item.updatedAt ? new Date(item.updatedAt).toLocaleDateString('zh-CN') : '-'}
</td>
<td className="px-4 py-3">
+11 -11
View File
@@ -287,16 +287,16 @@ export default function UsersPage() {
{/* Users table */}
<div className="bg-bg-primary rounded-lg border border-border-primary overflow-hidden">
<div className="overflow-x-auto">
<table className="w-full text-sm">
<table className="w-full min-w-[760px] text-sm">
<thead>
<tr className="border-b border-border-primary bg-bg-secondary">
<th className="text-left px-4 py-3 font-medium text-text-tertiary">用户名</th>
<th className="text-left px-4 py-3 font-medium text-text-tertiary">昵称</th>
<th className="text-left px-4 py-3 font-medium text-text-tertiary">邮箱</th>
<th className="text-left px-4 py-3 font-medium text-text-tertiary">角色</th>
<th className="text-left px-4 py-3 font-medium text-text-tertiary">状态</th>
<th className="text-left px-4 py-3 font-medium text-text-tertiary">创建时间</th>
<th className="text-right px-4 py-3 font-medium text-text-tertiary">操作</th>
<th className="text-left px-4 py-3 font-medium text-text-tertiary whitespace-nowrap">用户名</th>
<th className="text-left px-4 py-3 font-medium text-text-tertiary whitespace-nowrap">昵称</th>
<th className="text-left px-4 py-3 font-medium text-text-tertiary whitespace-nowrap">邮箱</th>
<th className="text-left px-4 py-3 font-medium text-text-tertiary whitespace-nowrap">角色</th>
<th className="text-left px-4 py-3 font-medium text-text-tertiary whitespace-nowrap">状态</th>
<th className="text-left px-4 py-3 font-medium text-text-tertiary whitespace-nowrap">创建时间</th>
<th className="text-right px-4 py-3 font-medium text-text-tertiary whitespace-nowrap">操作</th>
</tr>
</thead>
<tbody>
@@ -318,14 +318,14 @@ export default function UsersPage() {
) : (
users.map((u) => (
<tr key={u.id} className="border-b border-border-light hover:bg-bg-secondary">
<td className="px-4 py-3">
<td className="px-4 py-3 whitespace-nowrap">
<div className="flex items-center gap-2">
<UserCog className="w-4 h-4 text-text-muted" />
<span className="font-medium text-text-primary">{u.username}</span>
</div>
</td>
<td className="px-4 py-3 text-text-tertiary">{u.nickname || '-'}</td>
<td className="px-4 py-3">
<td className="px-4 py-3 text-text-tertiary whitespace-nowrap">{u.nickname || '-'}</td>
<td className="px-4 py-3 whitespace-nowrap">
{u.email ? (
<a href={`mailto:${u.email}`} className="text-text-tertiary hover:text-text-primary flex items-center gap-1">
<Mail className="w-3 h-3" />