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
+191
View File
@@ -0,0 +1,191 @@
<script setup lang="ts">
import { computed, onBeforeUnmount, ref } from "vue";
import {
Chip,
Spinner,
Table,
TableBody,
TableCell,
TableColumn,
TableContent,
TableHeader,
TableRow,
TableScrollContainer,
TableLoadMoreItem,
TableLoadMoreContent,
} from "@heroui-vue/components";
interface User {
id: number;
name: string;
role: string;
status: string;
email: string;
}
const statusColorMap: Record<string, "success" | "danger" | "warning"> = {
休假: "warning",
在职: "success",
未激活: "danger",
};
const allUsers: User[] = [
{
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: "在职",
},
{
email: "emily@acme.com",
id: 5,
name: "Emily Davis",
role: "产品经理",
status: "未激活",
},
{
email: "davis@acme.com",
id: 6,
name: "Davis Wilson",
role: "首席设计师",
status: "在职",
},
{
email: "olivia@acme.com",
id: 7,
name: "Olivia Martinez",
role: "前端工程师",
status: "在职",
},
{
email: "james@acme.com",
id: 8,
name: "James Taylor",
role: "后端工程师",
status: "在职",
},
{
email: "sophia@acme.com",
id: 9,
name: "Sophia Anderson",
role: "测试工程师",
status: "休假",
},
{
email: "liam@acme.com",
id: 10,
name: "Liam Thomas",
role: "DevOps 工程师",
status: "在职",
},
{
email: "lucas@acme.com",
id: 11,
name: "Lucas Martinez",
role: "产品经理",
status: "在职",
},
{
email: "emma@acme.com",
id: 12,
name: "Emma Johnson",
role: "前端工程师",
status: "在职",
},
];
const ITEMS_PER_PAGE = 6;
const columns = [
{ id: "name", name: "姓名" },
{ id: "role", name: "角色" },
{ id: "status", name: "状态" },
{ id: "email", name: "邮箱" },
];
const items = ref<User[]>(allUsers.slice(0, ITEMS_PER_PAGE));
const isLoading = ref(false);
const hasMore = computed(() => items.value.length < allUsers.length);
let timer: ReturnType<typeof setTimeout> | undefined;
onBeforeUnmount(() => clearTimeout(timer));
function loadMore() {
if (!hasMore.value || isLoading.value) return;
isLoading.value = true;
// Demo-only simulated fetch.
timer = setTimeout(() => {
items.value = allUsers.slice(0, items.value.length + ITEMS_PER_PAGE);
isLoading.value = false;
}, 1500);
}
</script>
<template>
<Table>
<TableScrollContainer class="h-[280px] overflow-y-auto">
<TableContent aria-label="异步加载表格" class="min-w-[600px]">
<TableHeader class="sticky top-0 z-10 bg-surface-secondary">
<TableColumn
v-for="col in columns"
:key="col.id"
:id="col.id"
:is-row-header="col.id === 'name'"
>
{{ col.name }}
</TableColumn>
</TableHeader>
<TableBody>
<TableRow
v-for="user in items"
:key="user.id"
:row-key="String(user.id)"
>
<TableCell>{{ user.name }}</TableCell>
<TableCell>{{ user.role }}</TableCell>
<TableCell>
<Chip
:color="statusColorMap[user.status]"
size="sm"
variant="soft"
>
{{ user.status }}
</Chip>
</TableCell>
<TableCell>{{ user.email }}</TableCell>
</TableRow>
<TableLoadMoreItem
v-if="hasMore"
:is-loading="isLoading"
:scroll-offset="0"
@load-more="loadMore"
>
<TableLoadMoreContent>
<Spinner size="md" />
</TableLoadMoreContent>
</TableLoadMoreItem>
</TableBody>
</TableContent>
</TableScrollContainer>
</Table>
</template>