From a08e43462082620cdfa24f19e7910d64cbc66ed3 Mon Sep 17 00:00:00 2001
From: ClariS <1457715339@qq.com>
Date: Mon, 24 Oct 2022 13:17:43 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E5=B0=81=E8=A3=85=E5=85=A8=E5=B1=80?=
=?UTF-8?q?=E7=9A=84=E5=88=86=E9=A1=B5=20hook=20(#23)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/hooks/usePagination.ts | 43 +++++++++++++++++++++++
src/views/table/element-plus/index.vue | 47 ++++++++++++--------------
2 files changed, 64 insertions(+), 26 deletions(-)
create mode 100644 src/hooks/usePagination.ts
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 @@
@@ -159,7 +153,7 @@ getTableData()
-
+
@@ -181,7 +175,7 @@ getTableData()
禁用
-
+
修改
@@ -193,21 +187,22 @@ getTableData()
-
+