feat: migrate Toast and Table with reviewed state focus and SSR contracts

This commit is contained in:
maoyingjie
2026-10-24 07:19:26 +08:00
parent 0cfe7b6195
commit ed41af5294
95 changed files with 9358 additions and 8 deletions
+126
View File
@@ -0,0 +1,126 @@
<script setup lang="ts">
import { computed, ref } from "vue";
import {
Checkbox,
CheckboxContent,
CheckboxControl,
CheckboxIndicator,
Table,
type TableKey,
TableBody,
TableCell,
TableColumn,
TableContent,
TableHeader,
TableRow,
TableScrollContainer,
} from "@heroui-vue/components";
const users = [
{
email: "kate@acme.com",
id: "1",
name: "Kate Moore",
role: "首席执行官",
status: "在职",
},
{
email: "john@acme.com",
id: "2",
name: "John Smith",
role: "首席技术官",
status: "在职",
},
{
email: "sara@acme.com",
id: "3",
name: "Sara Johnson",
role: "首席营销官",
status: "休假",
},
{
email: "michael@acme.com",
id: "4",
name: "Michael Brown",
role: "首席财务官",
status: "在职",
},
];
const selectedKeys = ref<TableKey[]>([]);
const allChecked = computed(
() => users.length > 0 && selectedKeys.value.length === users.length,
);
function toggleAll() {
selectedKeys.value = allChecked.value ? [] : users.map((u) => u.id);
}
function toggleOne(id: string) {
selectedKeys.value = selectedKeys.value.includes(id)
? selectedKeys.value.filter((k) => k !== id)
: [...selectedKeys.value, id];
}
</script>
<template>
<div class="flex flex-col gap-3">
<Table>
<TableScrollContainer>
<TableContent
aria-label="带选择的表格"
class="min-w-[600px]"
selection-mode="multiple"
:selected-keys="selectedKeys"
@update:selected-keys="(k: TableKey[]) => (selectedKeys = k)"
>
<TableHeader>
<TableColumn class="pe-0">
<Checkbox
aria-label="全选"
:is-selected="allChecked"
@update:checked="toggleAll"
>
<CheckboxContent>
<CheckboxControl>
<CheckboxIndicator />
</CheckboxControl>
</CheckboxContent>
</Checkbox>
</TableColumn>
<TableColumn is-row-header>姓名</TableColumn>
<TableColumn>角色</TableColumn>
<TableColumn>状态</TableColumn>
<TableColumn>邮箱</TableColumn>
</TableHeader>
<TableBody>
<TableRow v-for="user in users" :key="user.id" :row-key="user.id">
<TableCell class="pe-0">
<Checkbox
:aria-label="`选择 ${user.name}`"
variant="secondary"
:is-selected="selectedKeys.includes(user.id)"
@update:checked="() => toggleOne(user.id)"
>
<CheckboxContent>
<CheckboxControl>
<CheckboxIndicator />
</CheckboxControl>
</CheckboxContent>
</Checkbox>
</TableCell>
<TableCell>{{ user.name }}</TableCell>
<TableCell>{{ user.role }}</TableCell>
<TableCell>{{ user.status }}</TableCell>
<TableCell>{{ user.email }}</TableCell>
</TableRow>
</TableBody>
</TableContent>
</TableScrollContainer>
</Table>
<p class="text-sm text-muted">
已选:
<span class="font-medium">
{{ selectedKeys.length > 0 ? selectedKeys.join(", ") : "无" }}
</span>
</p>
</div>
</template>