Skip to content

Commit b25955d

Browse files
committed
feat: 增加 FaPagination 组件
1 parent a476217 commit b25955d

17 files changed

Lines changed: 653 additions & 0 deletions

File tree

apps/example/src/router/modules/component.example.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ const routes: RouteRecordRaw = {
190190
title: '内容块',
191191
},
192192
},
193+
{
194+
path: 'pagination',
195+
name: 'componentExamplePagination',
196+
component: () => import('@/views/component_example/pagination/index.vue'),
197+
meta: {
198+
title: '分页',
199+
},
200+
},
193201
{
194202
path: 'password_strength',
195203
name: 'componentExamplePasswordStrength',
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script setup lang="ts">
2+
const page = ref(1)
3+
const size = ref(10)
4+
const total = ref(100)
5+
</script>
6+
7+
<template>
8+
<FaPagination :page="page" :size="size" :total="total" />
9+
</template>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script setup lang="ts">
2+
const page = ref(1)
3+
const size = ref(10)
4+
const total = ref(100)
5+
</script>
6+
7+
<template>
8+
<FaPagination :page="page" :size="size" :total="total" layout="jumper, pager, ->, total, sizes" />
9+
<div class="my-4 border-t" />
10+
<FaPagination :page="page" :size="size" :total="total" layout="pager" />
11+
</template>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<script setup lang="ts">
2+
import Demo1 from './_demo1.vue'
3+
import Demo2 from './_demo2.vue'
4+
</script>
5+
6+
<template>
7+
<div>
8+
<FaPageHeader title="分页" description="FaPagination" />
9+
<FaPageMain main-class="p-0">
10+
<div class="p-4">
11+
<Demo1 />
12+
</div>
13+
</FaPageMain>
14+
<FaPageMain title="布局" main-class="p-0">
15+
<div class="p-4">
16+
<Demo2 />
17+
</div>
18+
</FaPageMain>
19+
</div>
20+
</template>

packages/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export { default as FaModal } from './src/modal/index.vue'
2727
export { default as FaNumberField } from './src/number-field/index.vue'
2828
export { default as FaPageHeader } from './src/page-header/index.vue'
2929
export { default as FaPageMain } from './src/page-main/index.vue'
30+
export { default as FaPagination } from './src/pagination/index.vue'
3031
export { default as FaPasswordStrength } from './src/password-strength/index.vue'
3132
export { default as FaPopover } from './src/popover/index.vue'
3233
export { default as FaProgress } from './src/progress/index.vue'

packages/components/resolver.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const COMPONENT_NAMES = [
3030
'FaNumberField',
3131
'FaPageHeader',
3232
'FaPageMain',
33+
'FaPagination',
3334
'FaPasswordStrength',
3435
'FaPopover',
3536
'FaProgress',
Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
# FaPagination 分页组件
2+
3+
功能完整的分页组件,支持总条数显示、每页条数选择、页码跳转和自定义布局。
4+
5+
## 基础用法
6+
7+
```vue
8+
<script setup lang="ts">
9+
const page = ref(1)
10+
const size = ref(10)
11+
const total = ref(100)
12+
</script>
13+
14+
<template>
15+
<FaPagination v-model:page="page" v-model:size="size" :total="total" />
16+
</template>
17+
```
18+
19+
## Props
20+
21+
| 属性 | 类型 | 默认值 | 说明 |
22+
|------|------|--------|------|
23+
| `total` | `number` | **必需** | 数据总条数 |
24+
| `sizes` | `number[]` | `[10, 20, 30, 40, 50, 100]` | 每页条数选项 |
25+
| `layout` | `string` | `'total, sizes, ->, pager, jumper'` | 布局配置 |
26+
| `page` | `number` | **必需** | 当前页码(支持 v-model) |
27+
| `size` | `number` | **必需** | 每页条数(支持 v-model) |
28+
29+
## Events
30+
31+
| 事件名 | 参数 | 说明 |
32+
|--------|------|------|
33+
| `pageChange` | `page: number` | 页码变化时触发 |
34+
| `sizeChange` | `size: number` | 每页条数变化时触发 |
35+
36+
## Slots
37+
38+
39+
40+
## 示例
41+
42+
### 基础分页
43+
44+
```vue
45+
<script setup lang="ts">
46+
const page = ref(1)
47+
const total = ref(100)
48+
</script>
49+
50+
<template>
51+
<FaPagination v-model:page="page" :total="total" />
52+
</template>
53+
```
54+
55+
### 带每页条数选择
56+
57+
```vue
58+
<script setup lang="ts">
59+
const page = ref(1)
60+
const size = ref(10)
61+
const total = ref(500)
62+
</script>
63+
64+
<template>
65+
<FaPagination v-model:page="page" v-model:size="size" :total="total" />
66+
</template>
67+
```
68+
69+
### 自定义每页条数选项
70+
71+
```vue
72+
<script setup lang="ts">
73+
const page = ref(1)
74+
const size = ref(20)
75+
const total = ref(500)
76+
</script>
77+
78+
<template>
79+
<FaPagination
80+
v-model:page="page"
81+
v-model:size="size"
82+
:total="total"
83+
:sizes="[20, 50, 100, 200]"
84+
/>
85+
</template>
86+
```
87+
88+
### 自定义布局(仅页码)
89+
90+
```vue
91+
<script setup lang="ts">
92+
const page = ref(1)
93+
const total = ref(100)
94+
</script>
95+
96+
<template>
97+
<FaPagination v-model:page="page" :total="total" layout="pager" />
98+
</template>
99+
```
100+
101+
### 自定义布局(总条数 + 页码)
102+
103+
```vue
104+
<template>
105+
<FaPagination
106+
v-model:page="page"
107+
:total="total"
108+
layout="total, ->, pager"
109+
/>
110+
</template>
111+
```
112+
113+
### 完整布局
114+
115+
```vue
116+
<script setup lang="ts">
117+
const page = ref(1)
118+
const size = ref(10)
119+
const total = ref(1000)
120+
</script>
121+
122+
<template>
123+
<FaPagination
124+
v-model:page="page"
125+
v-model:size="size"
126+
:total="total"
127+
layout="total, sizes, ->, pager, jumper"
128+
/>
129+
</template>
130+
```
131+
132+
### 监听分页变化
133+
134+
```vue
135+
<script setup lang="ts">
136+
const page = ref(1)
137+
const size = ref(10)
138+
const total = ref(100)
139+
140+
function onPageChange(newPage: number) {
141+
console.log('页码变为:', newPage)
142+
// 加载新页面数据
143+
}
144+
145+
function onSizeChange(newSize: number) {
146+
console.log('每页条数变为:', newSize)
147+
page.value = 1 // 重置页码
148+
// 加载新数据
149+
}
150+
</script>
151+
152+
<template>
153+
<FaPagination
154+
v-model:page="page"
155+
v-model:size="size"
156+
:total="total"
157+
@page-change="onPageChange"
158+
@size-change="onSizeChange"
159+
/>
160+
</template>
161+
```
162+
163+
### 在表格中使用
164+
165+
```vue
166+
<script setup lang="ts">
167+
const page = ref(1)
168+
const size = ref(10)
169+
const total = ref(100)
170+
const data = ref([])
171+
172+
// 加载数据
173+
function loadData() {
174+
// API 调用获取数据
175+
}
176+
177+
watch([page, size], loadData)
178+
</script>
179+
180+
<template>
181+
<div>
182+
<table>
183+
<thead>
184+
<tr>
185+
<th>姓名</th>
186+
<th>邮箱</th>
187+
</tr>
188+
</thead>
189+
<tbody>
190+
<tr v-for="item in data" :key="item.id">
191+
<td>{{ item.name }}</td>
192+
<td>{{ item.email }}</td>
193+
</tr>
194+
</tbody>
195+
</table>
196+
<FaPagination v-model:page="page" v-model:size="size" :total="total" />
197+
</div>
198+
</template>
199+
```
200+
201+
## 布局配置说明
202+
203+
`layout` 属性控制分页组件的布局和元素顺序,支持以下元素:
204+
205+
| 元素 | 说明 |
206+
|------|------|
207+
| `total` | 显示总条数 |
208+
| `sizes` | 每页条数选择器 |
209+
| `pager` | 页码按钮组 |
210+
| `jumper` | 页码跳转输入框 |
211+
| `->` | 弹性占位符(将后续元素推到右侧) |
212+
213+
### 布局示例
214+
215+
```vue
216+
<!-- 左侧总条数,中间页码,右侧跳转 -->
217+
<FaPagination layout="total, ->, pager, jumper" />
218+
219+
<!-- 仅显示页码 -->
220+
<FaPagination layout="pager" />
221+
222+
<!-- 总条数 + 每页条数 + 分页器 -->
223+
<FaPagination layout="total, sizes, pager" />
224+
```
225+
226+
## 注意事项
227+
228+
1. **必需属性**`total``page``size` 为必需属性
229+
2. **双向绑定**`page``size` 支持 `v-model` 双向绑定
230+
3. **页码范围**:跳转页码会自动限制在有效范围内
231+
4. **自动聚焦**:跳转输入框获得焦点时会自动选中文本
232+
5. **回车跳转**:在跳转输入框中按回车键可触发跳转
233+
234+
## 典型使用场景
235+
236+
- 数据列表分页
237+
- 表格分页
238+
- 搜索结果分页
239+
- 文章列表分页
240+
- 评论列表分页

0 commit comments

Comments
 (0)