feat: migrate Toast and Table with reviewed state focus and SSR contracts
This commit is contained in:
@@ -0,0 +1,164 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue";
|
||||
import {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
PaginationNext,
|
||||
PaginationNextIcon,
|
||||
PaginationPrevious,
|
||||
PaginationPreviousIcon,
|
||||
PaginationSummary,
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableColumn,
|
||||
TableContent,
|
||||
TableFooter,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
TableScrollContainer,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const columns = [
|
||||
{ id: "name", name: "姓名" },
|
||||
{ id: "role", name: "角色" },
|
||||
{ id: "status", name: "状态" },
|
||||
{ id: "email", name: "邮箱" },
|
||||
];
|
||||
|
||||
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: "在职",
|
||||
},
|
||||
{
|
||||
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: "在职",
|
||||
},
|
||||
];
|
||||
|
||||
const ROWS_PER_PAGE = 4;
|
||||
const page = ref(1);
|
||||
const totalPages = Math.ceil(users.length / ROWS_PER_PAGE);
|
||||
const pages = Array.from({ length: totalPages }, (_, i) => i + 1);
|
||||
|
||||
const paginatedItems = computed(() => {
|
||||
const start = (page.value - 1) * ROWS_PER_PAGE;
|
||||
return users.slice(start, start + ROWS_PER_PAGE);
|
||||
});
|
||||
const start = computed(() => (page.value - 1) * ROWS_PER_PAGE + 1);
|
||||
const end = computed(() => Math.min(page.value * ROWS_PER_PAGE, users.length));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Table>
|
||||
<TableScrollContainer>
|
||||
<TableContent aria-label="带分页的表格" class="min-w-[600px]">
|
||||
<TableHeader>
|
||||
<TableColumn
|
||||
v-for="column in columns"
|
||||
:key="column.id"
|
||||
:id="column.id"
|
||||
:is-row-header="column.id === 'name'"
|
||||
>
|
||||
{{ column.name }}
|
||||
</TableColumn>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<TableRow
|
||||
v-for="user in paginatedItems"
|
||||
:key="user.id"
|
||||
:row-key="String(user.id)"
|
||||
>
|
||||
<TableCell>{{ user.name }}</TableCell>
|
||||
<TableCell>{{ user.role }}</TableCell>
|
||||
<TableCell>{{ user.status }}</TableCell>
|
||||
<TableCell>{{ user.email }}</TableCell>
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
</TableContent>
|
||||
</TableScrollContainer>
|
||||
<TableFooter>
|
||||
<Pagination size="sm">
|
||||
<PaginationSummary>
|
||||
{{ start }}–{{ end }} / 共 {{ users.length }} 条
|
||||
</PaginationSummary>
|
||||
<PaginationContent>
|
||||
<PaginationItem>
|
||||
<PaginationPrevious
|
||||
:is-disabled="page === 1"
|
||||
@click="page = Math.max(1, page - 1)"
|
||||
>
|
||||
<PaginationPreviousIcon />
|
||||
上一页
|
||||
</PaginationPrevious>
|
||||
</PaginationItem>
|
||||
<PaginationItem v-for="p in pages" :key="p">
|
||||
<PaginationLink :is-active="p === page" @click="page = p">
|
||||
{{ p }}
|
||||
</PaginationLink>
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationNext
|
||||
:is-disabled="page === totalPages"
|
||||
@click="page = Math.min(totalPages, page + 1)"
|
||||
>
|
||||
下一页
|
||||
<PaginationNextIcon />
|
||||
</PaginationNext>
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
</TableFooter>
|
||||
</Table>
|
||||
</template>
|
||||
Reference in New Issue
Block a user