137 lines
4.2 KiB
Vue
137 lines
4.2 KiB
Vue
<script setup lang="ts">
|
|
import { ref, watch } from "vue";
|
|
import {
|
|
Table,
|
|
TableBody,
|
|
TableCell,
|
|
TableColumn,
|
|
TableColumnResizer,
|
|
TableContent,
|
|
TableHeader,
|
|
TableRow,
|
|
TableResizableContainer,
|
|
TableScrollContainer,
|
|
TableSortableColumnHeader,
|
|
} from "@heroui-vue/components";
|
|
|
|
/**
|
|
* HD-08 column width verification harness: managed `fr` widths share the
|
|
* remaining space by weight next to fixed/percent columns, min/max clamp the
|
|
* shares, container resizing re-shares, dragging freezes the touched column
|
|
* and RTL keeps geometry (only drag direction flips).
|
|
*/
|
|
const widths = [620, 900, 1400];
|
|
const hostWidth = ref(900);
|
|
const rtl = ref(false);
|
|
const dark = ref(false);
|
|
const layoutCase = ref("baseline");
|
|
const showRows = ref(true);
|
|
const extraColumn = ref(false);
|
|
watch(
|
|
dark,
|
|
(value) => {
|
|
document.documentElement.dataset.theme = value ? "dark" : "light";
|
|
},
|
|
{ immediate: true },
|
|
);
|
|
const rows = [
|
|
{ id: "1", email: "kate@acme.com", name: "Kate Moore", role: "首席执行官" },
|
|
{ id: "2", email: "john@acme.com", name: "John Smith", role: "首席技术官" },
|
|
{ id: "3", email: "sara@acme.com", name: "Sara Johnson", role: "首席营销官" },
|
|
];
|
|
</script>
|
|
|
|
<template>
|
|
<main style="padding: 24px; display: grid; gap: 16px">
|
|
<div style="display: flex; gap: 16px">
|
|
<label>
|
|
边界场景
|
|
<select v-model="layoutCase">
|
|
<option value="baseline">常规列宽</option>
|
|
<option value="fixed-max">固定列超出上限</option>
|
|
<option value="invalid-fr">无效 fr 回退</option>
|
|
</select>
|
|
</label>
|
|
<label>
|
|
容器宽度
|
|
<select v-model.number="hostWidth">
|
|
<option v-for="width in widths" :key="width" :value="width">
|
|
{{ width }}px
|
|
</option>
|
|
</select>
|
|
</label>
|
|
<label>
|
|
<input v-model="rtl" type="checkbox" />
|
|
RTL
|
|
</label>
|
|
<label>
|
|
<input v-model="dark" type="checkbox" />
|
|
深色主题
|
|
</label>
|
|
<label>
|
|
<input v-model="showRows" type="checkbox" />
|
|
显示数据
|
|
</label>
|
|
<label>
|
|
<input v-model="extraColumn" type="checkbox" />
|
|
增加列
|
|
</label>
|
|
</div>
|
|
<div
|
|
id="table-host"
|
|
:dir="rtl ? 'rtl' : 'ltr'"
|
|
:style="{ width: `${hostWidth}px` }"
|
|
>
|
|
<Table>
|
|
<TableResizableContainer>
|
|
<TableScrollContainer>
|
|
<TableContent aria-label="列宽验证表格">
|
|
<TableHeader>
|
|
<TableColumn
|
|
id="name"
|
|
allows-sorting
|
|
default-width="1fr"
|
|
:width="layoutCase === 'invalid-fr' ? 'oopsfr' : undefined"
|
|
:min-width="120"
|
|
>
|
|
<TableSortableColumnHeader>姓名</TableSortableColumnHeader>
|
|
<TableColumnResizer />
|
|
</TableColumn>
|
|
<TableColumn id="role" default-width="2fr" :min-width="100">
|
|
角色
|
|
<TableColumnResizer />
|
|
</TableColumn>
|
|
<TableColumn
|
|
id="status"
|
|
:width="180"
|
|
:max-width="layoutCase === 'fixed-max' ? 100 : undefined"
|
|
>
|
|
状态
|
|
</TableColumn>
|
|
<TableColumn id="email" width="20%" :max-width="240">
|
|
邮箱
|
|
</TableColumn>
|
|
<TableColumn v-if="extraColumn" id="extra">附加列</TableColumn>
|
|
</TableHeader>
|
|
<TableBody>
|
|
<TableRow
|
|
v-for="row in showRows ? rows : []"
|
|
:key="row.id"
|
|
:row-key="row.id"
|
|
>
|
|
<TableCell>{{ row.name }}</TableCell>
|
|
<TableCell>{{ row.role }}</TableCell>
|
|
<TableCell>在职</TableCell>
|
|
<TableCell>{{ row.email }}</TableCell>
|
|
<TableCell v-if="extraColumn">附加内容</TableCell>
|
|
</TableRow>
|
|
<template #empty>未找到结果</template>
|
|
</TableBody>
|
|
</TableContent>
|
|
</TableScrollContainer>
|
|
</TableResizableContainer>
|
|
</Table>
|
|
</div>
|
|
</main>
|
|
</template>
|