Skip to content

Commit 6c76e3f

Browse files
committed
feat(element-plus): 新增 Pagination 组件用于集成 usePaginationElPagination
1 parent a409d7d commit 6c76e3f

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import type {
2+
PaginationEmits as ElPaginationEmits,
3+
PaginationProps as ElPaginationProps,
4+
} from 'element-plus'
5+
import type { FunctionalComponent } from 'vue'
6+
import type { ComponentSlots } from 'vue-component-type-helpers'
7+
import type { UsePaginationReturn } from '@/shared/use-pagination'
8+
import { ElPagination } from 'element-plus'
9+
import { mergeProps } from 'vue'
10+
11+
export interface PaginationRenderProps
12+
extends Partial<
13+
Omit<ElPaginationProps, 'currentPage' | 'pageSize' | 'pageCount' | 'total'>
14+
> {
15+
/**
16+
* 通过 `usePaginationReturn` 创建的控制器
17+
*/
18+
pagination: UsePaginationReturn
19+
}
20+
21+
export interface PaginationRenderEmits extends ElPaginationEmits {}
22+
23+
export interface PaginationRenderSlots
24+
extends ComponentSlots<typeof ElPagination> {}
25+
26+
export const PaginationRender: FunctionalComponent<
27+
PaginationRenderProps,
28+
PaginationRenderEmits,
29+
PaginationRenderSlots
30+
> & {
31+
defaultProps?: Partial<
32+
Pick<
33+
ElPaginationProps,
34+
| 'background' |
35+
'layout' |
36+
'pagerCount' |
37+
'pageSizes' |
38+
'hideOnSinglePage' |
39+
'nextIcon' |
40+
'nextText' |
41+
'prevIcon' |
42+
'prevText'
43+
>
44+
>
45+
} = ({ pagination, ...props }, { attrs, slots }) => {
46+
const { currentPage, currentPageSize, pageCount, total } = pagination
47+
48+
const finalProps: Partial<ElPaginationProps> = mergeProps(
49+
PaginationRender.defaultProps || {},
50+
51+
// 需要与 attrs 内的事件名保持一致
52+
{
53+
'onUpdate:currentPage': (v: number) => {
54+
currentPage.value = v
55+
},
56+
'onUpdate:pageSize': (v: number) => {
57+
currentPageSize.value = v
58+
},
59+
},
60+
61+
attrs,
62+
props,
63+
64+
{
65+
currentPage: currentPage.value,
66+
pageSize: currentPageSize.value,
67+
pageCount: pageCount.value,
68+
total: total.value,
69+
},
70+
)
71+
72+
return <ElPagination {...finalProps}>{slots}</ElPagination>
73+
}
74+
75+
PaginationRender.props = {
76+
pagination: {
77+
type: Object,
78+
required: true,
79+
},
80+
}

0 commit comments

Comments
 (0)