feat: migrate Pagination Header and InputOTP with field and event regressions
This commit is contained in:
@@ -70,13 +70,16 @@ const groups = [
|
||||
{ title: "EmptyState 空状态", url: "/components/empty-state" },
|
||||
{ title: "FieldError 字段错误", url: "/components/field-error" },
|
||||
{ title: "Fieldset 字段组", url: "/components/fieldset" },
|
||||
{ title: "Header 标题", url: "/components/header" },
|
||||
{ title: "Input 输入框", url: "/components/input" },
|
||||
{ title: "InputOTP 验证码输入", url: "/components/input-otp" },
|
||||
{ title: "InputGroup 输入框组", url: "/components/input-group" },
|
||||
{ title: "Kbd 键盘按键", url: "/components/kbd" },
|
||||
{ title: "Label 标签", url: "/components/label" },
|
||||
{ title: "Link 链接", url: "/components/link" },
|
||||
{ title: "Meter 计量条", url: "/components/meter" },
|
||||
{ title: "Modal 模态框", url: "/components/modal" },
|
||||
{ title: "Pagination 分页", url: "/components/pagination" },
|
||||
{ title: "Popover 弹出框", url: "/components/popover" },
|
||||
{ title: "ProgressBar 进度条", url: "/components/progress-bar" },
|
||||
{
|
||||
|
||||
@@ -52,3 +52,7 @@ description: 已迁移组件及文档
|
||||
- [Toolbar 工具栏](./components/toolbar)
|
||||
- [ToggleButton 切换按钮](./components/toggle-button)
|
||||
- [ToggleButtonGroup 切换按钮组](./components/toggle-button-group)
|
||||
|
||||
- [Pagination 分页](./components/pagination)
|
||||
- [Header 标题](./components/header)
|
||||
- [InputOTP 验证码输入](./components/input-otp)
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
---
|
||||
title: Header 标题
|
||||
description: 集合或分组的区块标题部件,用于菜单、列表等结构中的分组说明。
|
||||
component: header
|
||||
group: 组件
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { Header } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Header>操作</Header>
|
||||
</template>
|
||||
```
|
||||
|
||||
<ComponentPreview name="header-basic" />
|
||||
|
||||
> **说明:** 固定 HeroUI 基线没有独立的 Header 中文组件页或专属演示目录。本页与下方示例为自编,用于说明语义、默认样式与自定义方式;不是官方文案的完整复刻。
|
||||
|
||||
## 组件结构
|
||||
|
||||
`Header` 是集合/分组标题部件,不是带 Logo、导航和用户菜单的应用顶栏。固定基线的 React Aria Components `Header` 渲染原生 `<header>` 元素(不是任意 heading 级别),常出现在 Dropdown、ListBox、ComboBox、Autocomplete 的分组中。
|
||||
|
||||
Vue 版导出 `Header` 与 `HeaderRoot`(同一实现)。菜单 / ListBox 尚未迁移时,可用语义容器解释组合边界,例如在分组列表或表单分区前放置标题:
|
||||
|
||||
<ComponentPreview name="header-semantic" />
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { Header } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section>
|
||||
<Header>发票列表</Header>
|
||||
<ul>
|
||||
<li>INV-1001</li>
|
||||
</ul>
|
||||
</section>
|
||||
</template>
|
||||
```
|
||||
|
||||
## 示例
|
||||
|
||||
### 自定义 class
|
||||
|
||||
<ComponentPreview name="header-custom-class" />
|
||||
|
||||
`class` 合并到 `<header>` 根元素,可覆盖字号、颜色与间距。
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-header {
|
||||
@apply text-sm font-semibold text-foreground;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
类名前缀为 `hv-`。
|
||||
|
||||
### CSS 类
|
||||
|
||||
- `.hv-header` - 根元素(`w-full px-2 pt-1.5 pb-1 text-start text-xs font-medium text-muted`)
|
||||
|
||||
## API 参考
|
||||
|
||||
### Header / HeaderRoot
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ---------- | ---------------- |
|
||||
| `as` | `string` | `'header'` | 自定义根元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | - | 标题内容 |
|
||||
|
||||
根元素同时接收其余 `$attrs`(`aria-*`、`data-*`、`id`、`style`、事件等)。本组件没有业务值,不提供 `v-model`、表单提交或焦点状态。
|
||||
|
||||
### 上游差异
|
||||
|
||||
| 上游 React 能力 | Vue 实现 |
|
||||
| --------------------------- | ------------------------------------------ |
|
||||
| `Header.Root` 对象子部件 | 独立具名导出 `Header` / `HeaderRoot` |
|
||||
| RAC Collection 叶子节点 | 语义 HTML 封装;集合上下文由未来菜单族提供 |
|
||||
| `className` / `children` | `class` / 默认插槽 |
|
||||
| `render` / `DOMRenderProps` | `as` 更换元素,属性直接透传 |
|
||||
|
||||
## 无障碍
|
||||
|
||||
- 默认渲染原生 `<header>`,与固定基线 RAC Header 一致;不强制 heading 级别。
|
||||
- 不自动附加 `role` 或 `aria-level`;分组语义由所在集合(Menu / ListBox 等)提供。需要文档标题层级时,请在应用侧使用真正的 `h1`–`h6` 或 `aria-labelledby`。
|
||||
- 真实读屏表现未在本轮验证。
|
||||
|
||||
## 相关组件
|
||||
|
||||
- [Typography 排版](./typography)
|
||||
- [EmptyState 空状态](./empty-state)
|
||||
@@ -0,0 +1,192 @@
|
||||
---
|
||||
title: InputOTP 验证码输入
|
||||
description: 一次性验证码输入:分格槽位、分组分隔、模式过滤与完成事件。
|
||||
component: input-otp
|
||||
group: 组件
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSeparator,
|
||||
InputOTPSlot,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<InputOTP :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>
|
||||
</template>
|
||||
```
|
||||
|
||||
<ComponentPreview name="input-otp-basic" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
上游交互来自 React 的 `input-otp` 包(单隐藏 input)。Vue 版以安装版 **Reka PinInput** 为底座(多 input),内部 DOM 与上游不同,但可感知行为、表单值与可访问名称按基线验收。公开值为**字符串**;内部为**按索引的字符数组**,空位保留原索引,后续字符不会左移。
|
||||
|
||||
导出 `InputOTP`(即 `InputOTPRoot`)、`InputOTPGroup`、`InputOTPSlot`、`InputOTPSeparator`,以及正则常量 `REGEXP_ONLY_DIGITS`、`REGEXP_ONLY_CHARS`、`REGEXP_ONLY_DIGITS_AND_CHARS`。
|
||||
|
||||
### 字符串与字符数组的转换规则
|
||||
|
||||
- 槽位 `i` 对应字符串下标 `i`:`value[i]` 显示在 `InputOTPSlot :index="i"`。
|
||||
- 内部数组长度为 `maxLength`,空槽为 `""`;删除中间槽位时后续字符仍在原索引,UI 不左移。
|
||||
- 序列化为公开字符串时按索引 `join("")`,空槽在字符串中被省略(字符串紧凑)。槽位 UI 始终读数组,不从紧凑字符串反推,因此中间空位不会把后面的字符拉到前面。
|
||||
- 父组件回写我们发出的同一字符串时保留内部数组(含中间空位);父组件写入**不同**字符串时按左到右密排展开。
|
||||
|
||||
## 示例
|
||||
|
||||
### 尺寸变体
|
||||
|
||||
<ComponentPreview name="input-otp-variants" />
|
||||
|
||||
### Surface 上的次要变体
|
||||
|
||||
<ComponentPreview name="input-otp-on-surface" />
|
||||
|
||||
### 禁用
|
||||
|
||||
<ComponentPreview name="input-otp-disabled" />
|
||||
|
||||
### 四位 PIN
|
||||
|
||||
<ComponentPreview name="input-otp-four-digits" />
|
||||
|
||||
### 受控
|
||||
|
||||
<ComponentPreview name="input-otp-controlled" />
|
||||
|
||||
`v-model` 为字符串。父级拒绝更新时实际输入会恢复。
|
||||
|
||||
### 完成事件
|
||||
|
||||
<ComponentPreview name="input-otp-on-complete" />
|
||||
|
||||
`@complete` 在**首次填满**时触发一次;替换已满值、重复同值或父级同步同一值不会重复触发。示例使用模拟验证(定时器),不发送真实验证码。
|
||||
|
||||
### 表单示例
|
||||
|
||||
<ComponentPreview name="input-otp-form-example" />
|
||||
|
||||
表单提交一份完整字符串值(`name` 映射)。模拟校验 `123456`;卸载时清理定时器。
|
||||
|
||||
### 模式过滤
|
||||
|
||||
<ComponentPreview name="input-otp-with-pattern" />
|
||||
|
||||
`pattern` 过滤单字符输入,可使用导出的正则常量。
|
||||
|
||||
### 表单验证
|
||||
|
||||
<ComponentPreview name="input-otp-with-validation" />
|
||||
|
||||
### 自定义样式
|
||||
|
||||
<ComponentPreview name="input-otp-custom-styles" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
`inputClassName` 落在真实 `<input>` 上;视觉槽位用 `class` 落在 `InputOTPSlot` 根节点。二者不会合并到同一节点。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-input-otp__slot {
|
||||
@apply rounded-lg border-accent;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
类名前缀为 `hv-`。
|
||||
|
||||
- `.hv-input-otp` / `.hv-input-otp--primary` / `.hv-input-otp--secondary`
|
||||
- `.hv-input-otp__group` / `.hv-input-otp__slot` / `.hv-input-otp__slot-value`
|
||||
- `.hv-input-otp__caret` / `.hv-input-otp__separator` / `.hv-input-otp__input`
|
||||
|
||||
状态:`data-active`、`data-filled`、`data-disabled`、`data-invalid`、`data-complete`。
|
||||
|
||||
## API 参考
|
||||
|
||||
### InputOTP / InputOTPRoot
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------------ | -------------------------- | ----------- | ---------------------------------------------------------------- |
|
||||
| `modelValue` | `string` | - | 受控字符串值;下标对应槽位 |
|
||||
| `defaultValue` | `string` | `''` | 非受控初始值 |
|
||||
| `maxLength` | `number` | 必填 | 槽位数量 / 最大长度 |
|
||||
| `variant` | `'primary' \| 'secondary'` | `'primary'` | 外观变体 |
|
||||
| `isDisabled` | `boolean` | `false` | 禁用 |
|
||||
| `isInvalid` | `boolean` | `false` | 无效展示状态 |
|
||||
| `validationErrors` | `string[]` | `[]` | 校验错误消息 |
|
||||
| `inputClassName` | `string` | - | 附加到真实 input 的类 |
|
||||
| `name` | `string` | - | 表单字段名(隐藏 input 提交一份完整值) |
|
||||
| `required` | `boolean` | `false` | 原生必填 |
|
||||
| `pattern` | `string \| RegExp` | - | 字符过滤正则 |
|
||||
| `mask` | `boolean` | `false` | 密码样式(Reka `mask`) |
|
||||
| `otp` | `boolean` | `false` | 一次性验证码自动填充(`autocomplete="one-time-code"`) |
|
||||
| `placeholder` | `string` | `''` | 空位占位符 |
|
||||
| `id` | `string` | 自动 | 提交桥 id;真实输入派生为 id-slot-index,内部 Label 自动关联首格 |
|
||||
|
||||
事件:`update:modelValue` / `change`(字符串)、`complete`(首次填满)。
|
||||
|
||||
### InputOTPGroup / InputOTPSeparator
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | -------- | ------ | ----------- |
|
||||
| `class` | `string` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | - | Slot 或内容 |
|
||||
|
||||
### InputOTPSlot
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------- | -------- | ------ | -------------------- |
|
||||
| `index` | `number` | 必填 | 槽位索引,从 0 开始 |
|
||||
| `class` | `string` | - | 附加到视觉槽位根节点 |
|
||||
|
||||
### 上游差异
|
||||
|
||||
| 上游 React 能力 | Vue 实现 |
|
||||
| ----------------------------- | ------------------------------------------ |
|
||||
| `input-otp` 单隐藏 input | Reka PinInput 多 input + 隐藏提交 input |
|
||||
| `value` / `onChange` 字符串 | `v-model` / `update:modelValue` / `change` |
|
||||
| `onComplete` 跨过长度阈值 | `complete` 仅在首次填满触发 |
|
||||
| `pattern` 整串校验 | 单字符过滤(同样接受导出常量) |
|
||||
| `render` / `OTPInputContext` | 具名插槽部件;槽位状态经上下文 |
|
||||
| `pushPasswordManagerStrategy` | 未提供;`otp` 覆盖 one-time-code 自动填充 |
|
||||
|
||||
## 字段与表单
|
||||
|
||||
- 复用既有 `fieldContextKey`:Label `for` 指向控件 id,Description / FieldError 可关联;`isInvalid` / `validationErrors` 驱动展示。
|
||||
- 不复制第二套字段、错误或 reset 内核。真实 `FormData` 只有一份完整字符串值;禁用时省略。
|
||||
- 受控 reset 保留父级值;非受控恢复初始值。取消原生 reset 保留当前值;专项回归断言真实 input 与唯一 FormData 值。
|
||||
|
||||
Slot 的 keydown/paste 用户处理器在底座编辑前的 capture 边界协调取消,事件阶段与普通 div 的 bubble 处理存在差异;其他 DOM 事件正常透传。
|
||||
|
||||
## 无障碍
|
||||
|
||||
- 每个槽位是真实 `<input>`,`autocomplete="one-time-code"`(或 `otp` 时更完整);隐藏 input 供表单提交,`aria-hidden`。
|
||||
- Label 通过 `for` 关联首格,并通过 `aria-labelledby` 给所有实际输入命名;外置标签使用显式 `aria-labelledby`。底座默认名称不会覆盖字段名称。
|
||||
- 真实设备上的短信/密码管理器自动填充、IME 与触屏行为**未在本轮验证**,不能按属性存在宣布验收。
|
||||
- 读屏表现未验证。
|
||||
|
||||
## 相关组件
|
||||
|
||||
- [TextField 文本输入框](./text-field)
|
||||
- [Label 标签](./label)
|
||||
- [FieldError 字段错误](./field-error)
|
||||
@@ -0,0 +1,296 @@
|
||||
---
|
||||
title: Pagination 分页
|
||||
description: 分页导航:可组合的页码链接、上一页/下一页按钮与省略号指示器。
|
||||
component: pagination
|
||||
group: 组件
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Pagination>
|
||||
<PaginationContent>
|
||||
<PaginationItem>
|
||||
<PaginationLink is-active>1</PaginationLink>
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
</template>
|
||||
```
|
||||
|
||||
<ComponentPreview name="pagination-basic" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
导入 Pagination 各具名组件后组合使用。根组件同时以 `Pagination` 与 `PaginationRoot` 导出,二者是同一实现。
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationEllipsis,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
PaginationNext,
|
||||
PaginationNextIcon,
|
||||
PaginationPrevious,
|
||||
PaginationPreviousIcon,
|
||||
PaginationSummary,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Pagination>
|
||||
<PaginationSummary>显示第 1–10 条,共 100 条结果</PaginationSummary>
|
||||
<PaginationContent>
|
||||
<PaginationItem>
|
||||
<PaginationPrevious>
|
||||
<PaginationPreviousIcon />
|
||||
<span>上一页</span>
|
||||
</PaginationPrevious>
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationLink is-active>1</PaginationLink>
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationEllipsis />
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationLink>10</PaginationLink>
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationNext>
|
||||
<span>下一页</span>
|
||||
<PaginationNextIcon />
|
||||
</PaginationNext>
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
</template>
|
||||
```
|
||||
|
||||
根 `Pagination` 渲染为带 `aria-label="pagination"` 与 `role="navigation"` 的 `nav`,`Content` 为 `ul`,`Item` 为 `li`。根组件是组合式导航容器,不管理 `total` / `page` 状态;受控示例的页码由示例自身维护。
|
||||
|
||||
`Link` / `Previous` / `Next` 在固定基线使用 React Aria Button(原生 `button`,默认 `type="button"`),不是 `a`。名字叫 Link 但语义是按钮。
|
||||
|
||||
## 示例
|
||||
|
||||
### 尺寸
|
||||
|
||||
<ComponentPreview name="pagination-sizes" />
|
||||
|
||||
### 禁用
|
||||
|
||||
<ComponentPreview name="pagination-disabled" />
|
||||
|
||||
`isDisabled` 禁用按钮的原生激活与点击;页码链接仍可单独控制。
|
||||
|
||||
### 简化(上一页 / 下一页)
|
||||
|
||||
<ComponentPreview name="pagination-simple-prev-next" />
|
||||
|
||||
### 受控组件
|
||||
|
||||
<ComponentPreview name="pagination-controlled" />
|
||||
|
||||
页码列表、省略号与摘要区间由示例根据 `page` 计算;组件根不额外实现分页状态机。
|
||||
|
||||
### 带省略号
|
||||
|
||||
<ComponentPreview name="pagination-with-ellipsis" />
|
||||
|
||||
### 带摘要
|
||||
|
||||
<ComponentPreview name="pagination-with-summary" />
|
||||
|
||||
### 自定义图标
|
||||
|
||||
可通过向 `PreviousIcon` 与 `NextIcon` 传入默认插槽替换默认 chevron 图标。空插槽回退到基线 SVG;图标包裹层始终 `aria-hidden="true"`。
|
||||
|
||||
<ComponentPreview name="pagination-custom-icons" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="pagination-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
若要自定义组件类,可使用 `@layer components` 指令。[了解更多](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes)。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-pagination {
|
||||
@apply gap-8;
|
||||
}
|
||||
|
||||
.hv-pagination__link {
|
||||
@apply rounded-md;
|
||||
}
|
||||
|
||||
.hv-pagination__summary {
|
||||
@apply text-xs font-semibold;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
||||
|
||||
### CSS 类
|
||||
|
||||
Pagination 使用以下 CSS 类:
|
||||
|
||||
#### 基础与布局类 [!toc]
|
||||
|
||||
- `.hv-pagination` - 根导航容器(flex 布局)
|
||||
- `.hv-pagination__summary` - 左侧信息文本容器
|
||||
- `.hv-pagination__content` - 分页项容器
|
||||
- `.hv-pagination__item` - 单个分页项包裹层
|
||||
- `.hv-pagination__link` - 页码按钮(ghost 按钮样式)
|
||||
- `.hv-pagination__link--nav` - 导航按钮修饰符(Previous/Next)
|
||||
- `.hv-pagination__ellipsis` - 省略号指示器
|
||||
|
||||
#### 尺寸类 [!toc]
|
||||
|
||||
- `.hv-pagination--sm` - 小尺寸变体
|
||||
- `.hv-pagination--md` - 中尺寸变体(默认)
|
||||
- `.hv-pagination--lg` - 大尺寸变体
|
||||
|
||||
### 交互状态
|
||||
|
||||
组件同时支持 CSS 伪类与 data 属性,便于灵活定制:
|
||||
|
||||
- **Active page**:`[data-active="true"]` 或 `[aria-current="page"]`
|
||||
- **Hover**:`:hover` 或 `[data-hovered="true"]`
|
||||
- **Focus**:`:focus-visible` 或 `[data-focus-visible="true"]`
|
||||
- **Disabled**:`:disabled` 或 `[aria-disabled="true"]`
|
||||
- **Pressed**:`:active` 或 `[data-pressed="true"]`
|
||||
|
||||
## API 参考
|
||||
|
||||
### Pagination / PaginationRoot
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------- | ------------------------------- |
|
||||
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | 分页控件的尺寸 |
|
||||
| `as` | `string` | `'nav'` | 自定义根元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
| 默认插槽 | - | - | 分页部件(Summary、Content 等) |
|
||||
|
||||
根元素同时接收其余 `$attrs`(`aria-*`、`data-*`、事件等)。未显式传入时默认 `aria-label="pagination"` 与 `role="navigation"`;显式属性优先。
|
||||
|
||||
### PaginationSummary
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------- | -------------------------------------------- |
|
||||
| `as` | `string` | `'div'` | 自定义元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | - | 摘要内容(例如 “显示第 1–10 条,共 120 条”) |
|
||||
|
||||
默认 `dir="auto"`,按摘要自身文本检测方向,避免 RTL 祖先重排数字/中英混排;显式传入 `dir` 时覆盖。
|
||||
|
||||
### PaginationContent
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------ | -------------- |
|
||||
| `as` | `string` | `'ul'` | 自定义元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | - | 分页项 |
|
||||
|
||||
### PaginationItem
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------ | -------------------------------- |
|
||||
| `as` | `string` | `'li'` | 自定义元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | - | Link、Previous、Next 或 Ellipsis |
|
||||
|
||||
### PaginationLink
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------ | --------------------------- | ---------- | ---------------------------------------------------------------- |
|
||||
| `isActive` | `boolean` | `false` | 是否为当前页;输出 `aria-current="page"` 与 `data-active="true"` |
|
||||
| `isDisabled` | `boolean` | `false` | 是否禁用按钮 |
|
||||
| `type` | `string` | `'button'` | 原生按钮 type |
|
||||
| `asChild` | `boolean` | `false` | 将属性合并到唯一子元素 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | - | 页码内容 |
|
||||
|
||||
激活状态取消时移除 `aria-current` 与 `data-active`。显式传入的 `aria-current` 等 ARIA 在未激活时保留调用方值;激活时组件写入 `aria-current="page"`。
|
||||
|
||||
### PaginationPrevious / PaginationNext
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------ | --------------------------- | ---------- | ------------------------------------------- |
|
||||
| `isDisabled` | `boolean` | `false` | 是否禁用按钮 |
|
||||
| `type` | `string` | `'button'` | 原生按钮 type |
|
||||
| `asChild` | `boolean` | `false` | 将属性合并到唯一子元素 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | - | 按钮内容(可与 PreviousIcon/NextIcon 组合) |
|
||||
|
||||
两者附加 `hv-pagination__link--nav` 修饰类,不带入普通 Button 的 variant 类。
|
||||
|
||||
### PaginationPreviousIcon / PaginationNextIcon
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ---------------- | ----------------------------- |
|
||||
| `as` | `string` | `'span'` | 自定义包裹元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | 默认 chevron SVG | 替换默认 chevron 的自定义图标 |
|
||||
|
||||
包裹层始终 `aria-hidden="true"`。默认图标从 HeroUI `icons.tsx`(Apache-2.0)移植。
|
||||
|
||||
### PaginationEllipsis
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------- | --------------------------- | -------- | -------------- |
|
||||
| `as` | `string` | `'span'` | 自定义元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
|
||||
始终渲染 `…`,带 `aria-hidden="true"`,与上游一致不接受自定义子内容。
|
||||
|
||||
### 上游差异
|
||||
|
||||
| 上游 React 能力 | Vue 实现 |
|
||||
| ---------------------------- | -------------------------------------------------- |
|
||||
| `Pagination.Link` 对象子部件 | 独立具名导出 `PaginationLink` 等 |
|
||||
| `onPress` | 原生 `@click`;原生 button 的 Enter/Space 单次激活 |
|
||||
| `className` / `children` | `class` / 默认插槽 |
|
||||
| `render` / `DOMRenderProps` | `as` 更换元素,属性直接透传 |
|
||||
| 根 `v-model` / 自动页码计算 | 无;固定基线是组合式 nav 容器,页码由示例维护 |
|
||||
|
||||
## 说明
|
||||
|
||||
- 上游 Pagination 按钮使用 React Aria 的 `onPress`。Vue 版使用原生 `button` 与 `@click`:Enter/Space 触发一次原生 click,禁用时不激活,调用方可用 `preventDefault` / `stopPropagation` / 处理器数组 / `stopImmediatePropagation` 控制事件,组件不再手动重复模拟 click。
|
||||
- 分页按钮不复用共享 Button 的 variant 类,只使用 `hv-pagination__link` 族样式,避免带入无关默认外观。
|
||||
|
||||
## 无障碍
|
||||
|
||||
- 语义化 `<nav>` 元素,包含 `aria-label="pagination"` 与 `role="navigation"`(均可被显式属性覆盖)
|
||||
- 当前页链接使用 `aria-current="page"` 与 `data-active="true"`
|
||||
- Tab 键在全部可交互元素间导航(原生按钮)
|
||||
- 键盘激活时通过 `:focus-visible` 显示焦点环
|
||||
- 省略号与图标使用 `aria-hidden="true"`,避免干扰屏幕阅读器
|
||||
- 通过 `isDisabled` / 原生 `disabled` 向辅助技术正确传达禁用状态
|
||||
|
||||
真实键盘激活与焦点环在浏览器验证;jsdom 测试只覆盖 DOM/ARIA 与事件合并,不冒充浏览器已验收。
|
||||
|
||||
## 相关组件
|
||||
|
||||
- [Button 按钮](./button)
|
||||
- [Breadcrumbs 面包屑](./breadcrumbs)
|
||||
- [Separator 分隔符](./separator)
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user