diff --git a/src/hooks/usePagination.ts b/src/hooks/usePagination.ts new file mode 100644 index 0000000..9edd1f3 --- /dev/null +++ b/src/hooks/usePagination.ts @@ -0,0 +1,43 @@ +import { reactive } from "vue" + +interface IDefaultPaginationData { + total: number + currentPage: number + pageSizes: number[] + pageSize: number + layout: string +} + +interface IPaginationData { + total?: number + currentPage?: number + pageSizes?: number[] + pageSize?: number + layout?: string +} + +/** 默认的分页参数 */ +const defaultPaginationData: IDefaultPaginationData = { + total: 0, + currentPage: 1, + pageSizes: [10, 20, 50], + pageSize: 10, + layout: "total, sizes, prev, pager, next, jumper" +} + +export const usePagination = (_paginationData: IPaginationData = {}) => { + /** 合并分页参数 */ + const paginationData = reactive(Object.assign({ ...defaultPaginationData }, _paginationData)) + + /** 改变当前页码 */ + const handleCurrentChange = (value: number) => { + paginationData.currentPage = value + } + + /** 改变页面大小 */ + const handleSizeChange = (value: number) => { + paginationData.pageSize = value + } + + return { paginationData, handleCurrentChange, handleSizeChange } +} diff --git a/src/views/table/element-plus/index.vue b/src/views/table/element-plus/index.vue index 6ea722d..f26b5ff 100644 --- a/src/views/table/element-plus/index.vue +++ b/src/views/table/element-plus/index.vue @@ -1,10 +1,12 @@ - +