feat: migrate Pagination Header and InputOTP with field and event regressions

This commit is contained in:
maoyingjie
2026-10-23 13:49:44 +08:00
parent b2525bb04d
commit 1fa2929a24
72 changed files with 5784 additions and 16 deletions
+21
View File
@@ -0,0 +1,21 @@
<script setup lang="ts">
import { Header } from "@heroui-vue/components";
</script>
<template>
<div class="flex w-full max-w-sm flex-col gap-1 rounded-xl bg-surface p-2">
<Header>操作</Header>
<button
type="button"
class="rounded-lg px-2 py-1.5 text-start text-sm hover:bg-surface-secondary"
>
复制
</button>
<button
type="button"
class="rounded-lg px-2 py-1.5 text-start text-sm hover:bg-surface-secondary"
>
粘贴
</button>
</div>
</template>
+17
View File
@@ -0,0 +1,17 @@
<script setup lang="ts">
import { Header } from "@heroui-vue/components";
</script>
<template>
<div class="flex w-full max-w-sm flex-col gap-1 rounded-xl bg-surface p-2">
<Header class="text-xs font-semibold uppercase tracking-wide text-accent">
危险区域
</Header>
<button
type="button"
class="rounded-lg px-2 py-1.5 text-start text-sm text-danger hover:bg-danger-soft"
>
删除项目
</button>
</div>
</template>
+13
View File
@@ -0,0 +1,13 @@
<script setup lang="ts">
import { Header } from "@heroui-vue/components";
</script>
<template>
<section class="flex w-full max-w-md flex-col gap-2">
<Header>发票列表</Header>
<ul class="flex flex-col gap-1">
<li class="rounded-lg bg-surface px-3 py-2 text-sm">INV-1001</li>
<li class="rounded-lg bg-surface px-3 py-2 text-sm">INV-1002</li>
</ul>
</section>
</template>
+39
View File
@@ -0,0 +1,39 @@
<script setup lang="ts">
import {
InputOTP,
InputOTPGroup,
InputOTPSeparator,
InputOTPSlot,
Label,
Link,
} from "@heroui-vue/components";
import { useId } from "vue";
const otpLabelId = useId();
</script>
<template>
<div class="flex w-[280px] flex-col gap-2">
<div class="flex flex-col gap-1">
<Label :id="otpLabelId">验证账户</Label>
<p class="text-sm text-muted">我们已向 a****@gmail.com 发送验证码</p>
</div>
<InputOTP :aria-labelledby="otpLabelId" :max-length="6">
<InputOTPGroup>
<InputOTPSlot :index="0" />
<InputOTPSlot :index="1" />
<InputOTPSlot :index="2" />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot :index="3" />
<InputOTPSlot :index="4" />
<InputOTPSlot :index="5" />
</InputOTPGroup>
</InputOTP>
<div class="flex items-center gap-[5px] px-1 pt-1">
<p class="text-sm text-muted">没有收到验证码?</p>
<Link class="text-foreground underline" href="#">重新发送</Link>
</div>
</div>
</template>
+54
View File
@@ -0,0 +1,54 @@
<script setup lang="ts">
import { ref } from "vue";
import {
Description,
InputOTP,
InputOTPGroup,
InputOTPSeparator,
InputOTPSlot,
Label,
} from "@heroui-vue/components";
const value = ref("");
import { useId } from "vue";
const otpDescriptionId = useId();
const otpLabelId = useId();
</script>
<template>
<div class="flex w-[280px] flex-col gap-2">
<Label :id="otpLabelId">验证账户</Label>
<InputOTP
:aria-describedby="otpDescriptionId"
:aria-labelledby="otpLabelId"
v-model="value"
:max-length="6"
>
<InputOTPGroup>
<InputOTPSlot :index="0" />
<InputOTPSlot :index="1" />
<InputOTPSlot :index="2" />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot :index="3" />
<InputOTPSlot :index="4" />
<InputOTPSlot :index="5" />
</InputOTPGroup>
</InputOTP>
<Description :id="otpDescriptionId">
<template v-if="value.length > 0">
值:{{ value }} ({{ value.length }}/6) •
<button
class="font-medium text-foreground underline"
type="button"
@click="value = ''"
>
清空
</button>
</template>
<template v-else>请输入 6 位验证码</template>
</Description>
</div>
</template>
@@ -0,0 +1,36 @@
<script setup lang="ts">
import {
InputOTP,
InputOTPGroup,
InputOTPSeparator,
InputOTPSlot,
Label,
Link,
} from "@heroui-vue/components";
const slotClass =
"rounded-lg border-border/80 bg-default data-[active=true]:border-accent/40 data-[active=true]:bg-accent-soft";
import { useId } from "vue";
const otpLabelId = useId();
</script>
<template>
<div class="flex w-72 flex-col gap-2">
<Label :id="otpLabelId">验证账户</Label>
<InputOTP :aria-labelledby="otpLabelId" :max-length="6">
<InputOTPGroup>
<InputOTPSlot :class="slotClass" :index="0" />
<InputOTPSlot :class="slotClass" :index="1" />
<InputOTPSlot :class="slotClass" :index="2" />
</InputOTPGroup>
<InputOTPSeparator class="bg-border" />
<InputOTPGroup>
<InputOTPSlot :class="slotClass" :index="3" />
<InputOTPSlot :class="slotClass" :index="4" />
<InputOTPSlot :class="slotClass" :index="5" />
</InputOTPGroup>
</InputOTP>
<Link class="text-sm text-link" href="#">重新发送</Link>
</div>
</template>
+39
View File
@@ -0,0 +1,39 @@
<script setup lang="ts">
import {
Description,
InputOTP,
InputOTPGroup,
InputOTPSeparator,
InputOTPSlot,
Label,
} from "@heroui-vue/components";
import { useId } from "vue";
const otpDescriptionId = useId();
const otpLabelId = useId();
</script>
<template>
<div class="flex w-[280px] flex-col gap-2">
<Label :id="otpLabelId" is-disabled>验证账户</Label>
<Description :id="otpDescriptionId">验证码校验当前已禁用</Description>
<InputOTP
:aria-describedby="otpDescriptionId"
:aria-labelledby="otpLabelId"
is-disabled
:max-length="6"
>
<InputOTPGroup>
<InputOTPSlot :index="0" />
<InputOTPSlot :index="1" />
<InputOTPSlot :index="2" />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot :index="3" />
<InputOTPSlot :index="4" />
<InputOTPSlot :index="5" />
</InputOTPGroup>
</InputOTP>
</div>
</template>
@@ -0,0 +1,94 @@
<script setup lang="ts">
import { onBeforeUnmount, ref, useId } from "vue";
import {
Button,
Description,
FieldError,
Form,
InputOTP,
InputOTPGroup,
InputOTPSeparator,
InputOTPSlot,
Label,
Link,
Spinner,
} from "@heroui-vue/components";
const value = ref("");
const error = ref("");
const isSubmitting = ref(false);
const errorId = useId();
let timer: ReturnType<typeof setTimeout> | undefined;
onBeforeUnmount(() => clearTimeout(timer));
function handleSubmit(event: Event) {
event.preventDefault();
error.value = "";
if (value.value.length !== 6) {
error.value = "请输入全部 6 位数字";
return;
}
isSubmitting.value = true;
// Demo-only simulated verification; no external service is called.
timer = setTimeout(() => {
if (value.value === "123456") {
value.value = "";
} else {
error.value = "验证码无效,请重试。";
}
isSubmitting.value = false;
}, 1500);
}
function handleChange() {
error.value = "";
}
</script>
<template>
<Form class="flex w-[280px] flex-col gap-4" @submit="handleSubmit">
<InputOTP
v-model="value"
:is-invalid="!!error"
:max-length="6"
:validation-errors="error ? [error] : []"
style="flex-direction: column; align-items: stretch; gap: 0.5rem"
@update:model-value="handleChange"
>
<Label>双重身份验证</Label>
<Description>请输入身份验证器应用中的 6 位验证码</Description>
<div class="flex items-center gap-2">
<InputOTPGroup>
<InputOTPSlot :index="0" />
<InputOTPSlot :index="1" />
<InputOTPSlot :index="2" />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot :index="3" />
<InputOTPSlot :index="4" />
<InputOTPSlot :index="5" />
</InputOTPGroup>
</div>
<FieldError :id="errorId" />
</InputOTP>
<Button
class="w-full"
:is-disabled="value.length !== 6"
:is-pending="isSubmitting"
type="submit"
variant="primary"
>
<template v-if="isSubmitting">
<Spinner color="current" size="sm" />
验证中…
</template>
<template v-else>验证</template>
</Button>
<div class="flex items-center justify-center gap-1">
<p class="text-sm text-muted">遇到问题?</p>
<Link class="text-sm text-foreground underline" href="#">使用备用码</Link>
</div>
</Form>
</template>
+25
View File
@@ -0,0 +1,25 @@
<script setup lang="ts">
import {
InputOTP,
InputOTPGroup,
InputOTPSlot,
Label,
} from "@heroui-vue/components";
import { useId } from "vue";
const otpLabelId = useId();
</script>
<template>
<div class="flex w-[280px] flex-col gap-2">
<Label :id="otpLabelId">输入 PIN</Label>
<InputOTP :aria-labelledby="otpLabelId" :max-length="4">
<InputOTPGroup>
<InputOTPSlot :index="0" />
<InputOTPSlot :index="1" />
<InputOTPSlot :index="2" />
<InputOTPSlot :index="3" />
</InputOTPGroup>
</InputOTP>
</div>
</template>
+77
View File
@@ -0,0 +1,77 @@
<script setup lang="ts">
import { onBeforeUnmount, ref } from "vue";
import {
Button,
Form,
InputOTP,
InputOTPGroup,
InputOTPSeparator,
InputOTPSlot,
Label,
Spinner,
} from "@heroui-vue/components";
const value = ref("");
const isComplete = ref(false);
const isSubmitting = ref(false);
let timer: ReturnType<typeof setTimeout> | undefined;
onBeforeUnmount(() => clearTimeout(timer));
function handleComplete(code: string) {
isComplete.value = true;
// Demo-only: no network request.
console.log("Code complete:", code);
}
function handleSubmit(event: Event) {
event.preventDefault();
isSubmitting.value = true;
timer = setTimeout(() => {
isSubmitting.value = false;
value.value = "";
isComplete.value = false;
}, 2000);
}
import { useId } from "vue";
const otpLabelId = useId();
</script>
<template>
<Form class="flex w-[280px] flex-col gap-2" @submit="handleSubmit">
<Label :id="otpLabelId">验证账户</Label>
<InputOTP
:aria-labelledby="otpLabelId"
v-model="value"
:max-length="6"
@complete="handleComplete"
@update:model-value="isComplete = false"
>
<InputOTPGroup>
<InputOTPSlot :index="0" />
<InputOTPSlot :index="1" />
<InputOTPSlot :index="2" />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot :index="3" />
<InputOTPSlot :index="4" />
<InputOTPSlot :index="5" />
</InputOTPGroup>
</InputOTP>
<Button
class="mt-2 w-full"
:is-disabled="!isComplete"
:is-pending="isSubmitting"
type="submit"
variant="primary"
>
<template v-if="isSubmitting">
<Spinner color="current" size="sm" />
验证中…
</template>
<template v-else>验证验证码</template>
</Button>
</Form>
</template>
+40
View File
@@ -0,0 +1,40 @@
<script setup lang="ts">
import {
InputOTP,
InputOTPGroup,
InputOTPSeparator,
InputOTPSlot,
Label,
Link,
Surface,
} from "@heroui-vue/components";
import { useId } from "vue";
const otpLabelId = useId();
</script>
<template>
<Surface class="flex w-full flex-col gap-2 rounded-3xl p-6">
<div class="flex flex-col gap-1">
<Label :id="otpLabelId">验证账户</Label>
<p class="text-sm text-muted">我们已向 a****@gmail.com 发送验证码</p>
</div>
<InputOTP :aria-labelledby="otpLabelId" :max-length="6" variant="secondary">
<InputOTPGroup>
<InputOTPSlot :index="0" />
<InputOTPSlot :index="1" />
<InputOTPSlot :index="2" />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot :index="3" />
<InputOTPSlot :index="4" />
<InputOTPSlot :index="5" />
</InputOTPGroup>
</InputOTP>
<div class="flex items-center gap-[5px] px-1 pt-1">
<p class="text-sm text-muted">没有收到验证码?</p>
<Link class="text-foreground underline" href="#">重新发送</Link>
</div>
</Surface>
</template>
+58
View File
@@ -0,0 +1,58 @@
<script setup lang="ts">
import {
InputOTP,
InputOTPGroup,
InputOTPSeparator,
InputOTPSlot,
Label,
} from "@heroui-vue/components";
import { useId } from "vue";
const otpLabelId0 = useId();
const otpLabelId1 = useId();
</script>
<template>
<div class="flex flex-col gap-6">
<div class="flex flex-col gap-2">
<Label :id="otpLabelId0">主要变体</Label>
<InputOTP
:aria-labelledby="otpLabelId0"
:max-length="6"
variant="primary"
>
<InputOTPGroup>
<InputOTPSlot :index="0" />
<InputOTPSlot :index="1" />
<InputOTPSlot :index="2" />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot :index="3" />
<InputOTPSlot :index="4" />
<InputOTPSlot :index="5" />
</InputOTPGroup>
</InputOTP>
</div>
<div class="flex flex-col gap-2">
<Label :id="otpLabelId1">次要变体</Label>
<InputOTP
:aria-labelledby="otpLabelId1"
:max-length="6"
variant="secondary"
>
<InputOTPGroup>
<InputOTPSlot :index="0" />
<InputOTPSlot :index="1" />
<InputOTPSlot :index="2" />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot :index="3" />
<InputOTPSlot :index="4" />
<InputOTPSlot :index="5" />
</InputOTPGroup>
</InputOTP>
</div>
</div>
</template>
@@ -0,0 +1,40 @@
<script setup lang="ts">
import {
Description,
InputOTP,
InputOTPGroup,
InputOTPSeparator,
InputOTPSlot,
Label,
REGEXP_ONLY_CHARS,
} from "@heroui-vue/components";
import { useId } from "vue";
const otpDescriptionId = useId();
const otpLabelId = useId();
</script>
<template>
<div class="flex w-[280px] flex-col gap-2">
<Label :id="otpLabelId">输入验证码(仅字母)</Label>
<Description :id="otpDescriptionId">仅允许输入字母</Description>
<InputOTP
:aria-describedby="otpDescriptionId"
:aria-labelledby="otpLabelId"
:max-length="6"
:pattern="REGEXP_ONLY_CHARS"
>
<InputOTPGroup>
<InputOTPSlot :index="0" />
<InputOTPSlot :index="1" />
<InputOTPSlot :index="2" />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot :index="3" />
<InputOTPSlot :index="4" />
<InputOTPSlot :index="5" />
</InputOTPGroup>
</InputOTP>
</div>
</template>
@@ -0,0 +1,70 @@
<script setup lang="ts">
import { ref, useId } from "vue";
import {
Button,
Description,
FieldError,
Form,
InputOTP,
InputOTPGroup,
InputOTPSeparator,
InputOTPSlot,
Label,
} from "@heroui-vue/components";
const value = ref("");
const isInvalid = ref(false);
const errorId = useId();
function onSubmit(event: Event) {
event.preventDefault();
const form = event.target as HTMLFormElement;
const data = new FormData(form);
const code = data.get("code");
if (code !== "123456") {
isInvalid.value = true;
return;
}
isInvalid.value = false;
value.value = "";
alert("验证码校验成功!");
}
function handleChange() {
isInvalid.value = false;
}
</script>
<template>
<div class="flex w-[280px] flex-col gap-2">
<Form class="flex flex-col gap-2" @submit="onSubmit">
<InputOTP
v-model="value"
:is-invalid="isInvalid"
:max-length="6"
:validation-errors="isInvalid ? ['验证码无效,请重试。'] : []"
name="code"
style="flex-direction: column; align-items: stretch; gap: 0.5rem"
@update:model-value="handleChange"
>
<Label>验证账户</Label>
<Description>提示:验证码为 123456</Description>
<div class="flex items-center gap-2">
<InputOTPGroup>
<InputOTPSlot :index="0" />
<InputOTPSlot :index="1" />
<InputOTPSlot :index="2" />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot :index="3" />
<InputOTPSlot :index="4" />
<InputOTPSlot :index="5" />
</InputOTPGroup>
</div>
<FieldError :id="errorId" />
</InputOTP>
<Button :is-disabled="value.length !== 6" type="submit">提交</Button>
</Form>
</div>
</template>
+43
View File
@@ -0,0 +1,43 @@
<script setup lang="ts">
import { ref } from "vue";
import {
Pagination,
PaginationContent,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationNextIcon,
PaginationPrevious,
PaginationPreviousIcon,
} from "@heroui-vue/components";
const page = ref(1);
const totalPages = 3;
</script>
<template>
<Pagination class="justify-center">
<PaginationContent>
<PaginationItem>
<PaginationPrevious :is-disabled="page === 1" @click="page = page - 1">
<PaginationPreviousIcon />
<span>上一页</span>
</PaginationPrevious>
</PaginationItem>
<PaginationItem v-for="p in totalPages" :key="p">
<PaginationLink :is-active="p === page" @click="page = p">
{{ p }}
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationNext
:is-disabled="page === totalPages"
@click="page = page + 1"
>
<span>下一页</span>
<PaginationNextIcon />
</PaginationNext>
</PaginationItem>
</PaginationContent>
</Pagination>
</template>
+92
View File
@@ -0,0 +1,92 @@
<script setup lang="ts">
import { computed, ref } from "vue";
import {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationNextIcon,
PaginationPrevious,
PaginationPreviousIcon,
PaginationSummary,
} from "@heroui-vue/components";
const page = ref(1);
const totalPages = 12;
const itemsPerPage = 10;
const totalItems = 120;
const pages = computed(() => {
const list: (number | "ellipsis")[] = [];
if (totalPages <= 7) {
for (let i = 1; i <= totalPages; i++) {
list.push(i);
}
} else {
list.push(1);
if (page.value > 3) {
list.push("ellipsis");
}
const start = Math.max(2, page.value - 1);
const end = Math.min(totalPages - 1, page.value + 1);
for (let i = start; i <= end; i++) {
list.push(i);
}
if (page.value < totalPages - 2) {
list.push("ellipsis");
}
list.push(totalPages);
}
return list;
});
const startItem = computed(() => (page.value - 1) * itemsPerPage + 1);
const endItem = computed(() => Math.min(page.value * itemsPerPage, totalItems));
</script>
<template>
<Pagination>
<PaginationSummary>
显示第 {{ startItem }}–{{ endItem }} 条,共 {{ totalItems }} 条结果
</PaginationSummary>
<PaginationContent>
<PaginationItem>
<PaginationPrevious :is-disabled="page === 1" @click="page = page - 1">
<PaginationPreviousIcon />
<span>上一页</span>
</PaginationPrevious>
</PaginationItem>
<template
v-for="(p, i) in pages"
:key="p === 'ellipsis' ? `ellipsis-${i}` : p"
>
<PaginationItem v-if="p === 'ellipsis'">
<PaginationEllipsis />
</PaginationItem>
<PaginationItem v-else>
<PaginationLink :is-active="p === page" @click="page = p">
{{ p }}
</PaginationLink>
</PaginationItem>
</template>
<PaginationItem>
<PaginationNext
:is-disabled="page === totalPages"
@click="page = page + 1"
>
<span>下一页</span>
<PaginationNextIcon />
</PaginationNext>
</PaginationItem>
</PaginationContent>
</Pagination>
</template>
@@ -0,0 +1,48 @@
<script setup lang="ts">
import { ref } from "vue";
import { IconArrowLeft, IconArrowRight } from "@tabler/icons-vue";
import {
Pagination,
PaginationContent,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationNextIcon,
PaginationPrevious,
PaginationPreviousIcon,
} from "@heroui-vue/components";
const page = ref(1);
const totalPages = 3;
</script>
<template>
<Pagination class="justify-center">
<PaginationContent>
<PaginationItem>
<PaginationPrevious :is-disabled="page === 1" @click="page = page - 1">
<PaginationPreviousIcon>
<IconArrowLeft aria-hidden="true" :size="16" />
</PaginationPreviousIcon>
<span>返回</span>
</PaginationPrevious>
</PaginationItem>
<PaginationItem v-for="p in totalPages" :key="p">
<PaginationLink :is-active="p === page" @click="page = p">
{{ p }}
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationNext
:is-disabled="page === totalPages"
@click="page = page + 1"
>
<span>前进</span>
<PaginationNextIcon>
<IconArrowRight aria-hidden="true" :size="16" />
</PaginationNextIcon>
</PaginationNext>
</PaginationItem>
</PaginationContent>
</Pagination>
</template>
@@ -0,0 +1,51 @@
<script setup lang="ts">
import { ref } from "vue";
import {
Pagination,
PaginationContent,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationNextIcon,
PaginationPrevious,
PaginationPreviousIcon,
} from "@heroui-vue/components";
const page = ref(2);
const linkClass = "text-muted hover:bg-surface hover:text-foreground";
const activeClass = "bg-accent text-accent-foreground hover:bg-accent-hover";
</script>
<template>
<Pagination class="justify-center">
<PaginationContent class="gap-1 rounded-xl bg-default p-1">
<PaginationItem>
<PaginationPrevious
:class="linkClass"
:is-disabled="page === 1"
@click="page = page - 1"
>
<PaginationPreviousIcon />
</PaginationPrevious>
</PaginationItem>
<PaginationItem v-for="p in 3" :key="p">
<PaginationLink
:class="p === page ? activeClass : linkClass"
:is-active="p === page"
@click="page = p"
>
{{ p }}
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationNext
:class="linkClass"
:is-disabled="page === 3"
@click="page = page + 1"
>
<PaginationNextIcon />
</PaginationNext>
</PaginationItem>
</PaginationContent>
</Pagination>
</template>
+40
View File
@@ -0,0 +1,40 @@
<script setup lang="ts">
import { ref } from "vue";
import {
Pagination,
PaginationContent,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationNextIcon,
PaginationPrevious,
PaginationPreviousIcon,
} from "@heroui-vue/components";
const page = ref(1);
const totalPages = 3;
</script>
<template>
<Pagination class="justify-center">
<PaginationContent>
<PaginationItem>
<PaginationPrevious is-disabled @click="page = page - 1">
<PaginationPreviousIcon />
<span>上一页</span>
</PaginationPrevious>
</PaginationItem>
<PaginationItem v-for="p in totalPages" :key="p">
<PaginationLink :is-active="p === page" @click="page = p">
{{ p }}
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationNext is-disabled @click="page = page + 1">
<span>下一页</span>
<PaginationNextIcon />
</PaginationNext>
</PaginationItem>
</PaginationContent>
</Pagination>
</template>
@@ -0,0 +1,46 @@
<script setup lang="ts">
import { computed, ref } from "vue";
import {
Pagination,
PaginationContent,
PaginationItem,
PaginationNext,
PaginationNextIcon,
PaginationPrevious,
PaginationPreviousIcon,
PaginationSummary,
} from "@heroui-vue/components";
const page = ref(1);
const totalPages = 10;
const itemsPerPage = 5;
const totalItems = 50;
const startItem = computed(() => (page.value - 1) * itemsPerPage + 1);
const endItem = computed(() => Math.min(page.value * itemsPerPage, totalItems));
</script>
<template>
<Pagination class="w-full">
<PaginationSummary>
第 {{ startItem }}–{{ endItem }} 条,共 {{ totalItems }} 张发票
</PaginationSummary>
<PaginationContent>
<PaginationItem>
<PaginationPrevious :is-disabled="page === 1" @click="page = page - 1">
<PaginationPreviousIcon />
<span>上一页</span>
</PaginationPrevious>
</PaginationItem>
<PaginationItem>
<PaginationNext
:is-disabled="page === totalPages"
@click="page = page + 1"
>
<span>下一页</span>
<PaginationNextIcon />
</PaginationNext>
</PaginationItem>
</PaginationContent>
</Pagination>
</template>
+62
View File
@@ -0,0 +1,62 @@
<script setup lang="ts">
import { ref } from "vue";
import {
Pagination,
PaginationContent,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationNextIcon,
PaginationPrevious,
PaginationPreviousIcon,
} from "@heroui-vue/components";
const totalPages = 3;
const smPage = ref(1);
const mdPage = ref(1);
const lgPage = ref(1);
const groups = [
{ key: "sm", label: "小", page: smPage },
{ key: "md", label: "中", page: mdPage },
{ key: "lg", label: "大", page: lgPage },
] as const;
</script>
<template>
<div class="flex flex-col gap-6">
<div v-for="group in groups" :key="group.key" class="flex flex-col gap-2">
<span class="text-xs font-medium text-muted">{{ group.label }}</span>
<Pagination class="justify-center" :size="group.key">
<PaginationContent>
<PaginationItem>
<PaginationPrevious
:is-disabled="group.page.value === 1"
@click="group.page.value = group.page.value - 1"
>
<PaginationPreviousIcon />
<span>上一页</span>
</PaginationPrevious>
</PaginationItem>
<PaginationItem v-for="p in totalPages" :key="p">
<PaginationLink
:is-active="p === group.page.value"
@click="group.page.value = p"
>
{{ p }}
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationNext
:is-disabled="group.page.value === totalPages"
@click="group.page.value = group.page.value + 1"
>
<span>下一页</span>
<PaginationNextIcon />
</PaginationNext>
</PaginationItem>
</PaginationContent>
</Pagination>
</div>
</div>
</template>
@@ -0,0 +1,82 @@
<script setup lang="ts">
import { computed, ref } from "vue";
import {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationNextIcon,
PaginationPrevious,
PaginationPreviousIcon,
} from "@heroui-vue/components";
const page = ref(1);
const totalPages = 12;
const pages = computed(() => {
const list: (number | "ellipsis")[] = [];
list.push(1);
if (page.value > 3) {
list.push("ellipsis");
}
const start = Math.max(2, page.value - 1);
const end = Math.min(totalPages - 1, page.value + 1);
for (let i = start; i <= end; i++) {
list.push(i);
}
if (page.value < totalPages - 2) {
list.push("ellipsis");
}
list.push(totalPages);
return list;
});
</script>
<template>
<div class="w-full max-w-2xs overflow-x-auto sm:max-w-full">
<Pagination class="justify-center">
<PaginationContent>
<PaginationItem>
<PaginationPrevious
:is-disabled="page === 1"
@click="page = page - 1"
>
<PaginationPreviousIcon />
<span>上一页</span>
</PaginationPrevious>
</PaginationItem>
<template
v-for="(p, i) in pages"
:key="p === 'ellipsis' ? `ellipsis-${i}` : p"
>
<PaginationItem v-if="p === 'ellipsis'">
<PaginationEllipsis />
</PaginationItem>
<PaginationItem v-else>
<PaginationLink :is-active="p === page" @click="page = p">
{{ p }}
</PaginationLink>
</PaginationItem>
</template>
<PaginationItem>
<PaginationNext
:is-disabled="page === totalPages"
@click="page = page + 1"
>
<span>下一页</span>
<PaginationNextIcon />
</PaginationNext>
</PaginationItem>
</PaginationContent>
</Pagination>
</div>
</template>
@@ -0,0 +1,86 @@
<script setup lang="ts">
import { computed, ref } from "vue";
import {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationNextIcon,
PaginationPrevious,
PaginationPreviousIcon,
PaginationSummary,
} from "@heroui-vue/components";
const page = ref(1);
const totalPages = 12;
const itemsPerPage = 10;
const totalItems = 120;
const pages = computed(() => {
const list: (number | "ellipsis")[] = [];
list.push(1);
if (page.value > 3) {
list.push("ellipsis");
}
const start = Math.max(2, page.value - 1);
const end = Math.min(totalPages - 1, page.value + 1);
for (let i = start; i <= end; i++) {
list.push(i);
}
if (page.value < totalPages - 2) {
list.push("ellipsis");
}
list.push(totalPages);
return list;
});
const startItem = computed(() => (page.value - 1) * itemsPerPage + 1);
const endItem = computed(() => Math.min(page.value * itemsPerPage, totalItems));
</script>
<template>
<Pagination class="w-full">
<PaginationSummary>
显示第 {{ startItem }}–{{ endItem }} 条,共 {{ totalItems }} 条结果
</PaginationSummary>
<PaginationContent>
<PaginationItem>
<PaginationPrevious :is-disabled="page === 1" @click="page = page - 1">
<PaginationPreviousIcon />
<span>上一页</span>
</PaginationPrevious>
</PaginationItem>
<template
v-for="(p, i) in pages"
:key="p === 'ellipsis' ? `ellipsis-${i}` : p"
>
<PaginationItem v-if="p === 'ellipsis'">
<PaginationEllipsis />
</PaginationItem>
<PaginationItem v-else>
<PaginationLink :is-active="p === page" @click="page = p">
{{ p }}
</PaginationLink>
</PaginationItem>
</template>
<PaginationItem>
<PaginationNext
:is-disabled="page === totalPages"
@click="page = page + 1"
>
<span>下一页</span>
<PaginationNextIcon />
</PaginationNext>
</PaginationItem>
</PaginationContent>
</Pagination>
</template>