index.vue
2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<script setup lang="ts">
/**
* 分页
* @module Pagination
*/
import { computed } from "vue";
import { scrollTo } from "@/utils/scroll";
// TIP 每个属性都必传,不带默认值
// defineProps<{
// total: number;
// currentPage: number;
// pageSizes: number[];
// pageSize: number;
// }>();
/**
* @description 组件属性
* @prop {number} total 内容总条数
* @prop {number[] | null} pageSizes 每页显示个数选择器的选项设置
* @prop {number | null} pageSize 当前每页内容条数
* @prop {number | null} currentPage 当前页码
* @prop {string | null} tagName 标签
*/
// TIP 可以带默认值
interface Props {
total: number;
pageSizes?: number[];
pageSize?: number;
currentPage?: number;
tagName?: string;
}
const props = withDefaults(defineProps<Props>(), {
total: 0,
pageSizes:()=> [10, 20, 50, 100],
pageSize: 10,
currentPage: 1,
});
const emit = defineEmits<{
(e: "pageChange", curPage: number, curSize: number, tagName: string): void;
(e: "update:currentPage", val:number): void;
(e: "update:pageSize", val:number): void;
}>();
const currentPage = computed({
get: () => props.currentPage,
set: val => {
emit("update:currentPage", val);
}
})
const pageSize = computed({
get: () => props.pageSize,
set: val => {
emit("update:pageSize", val);
}
})
// /**
// * 监听当前分页改变
// */
// const updateCurrentPage = (val) => {
// console.log(val);
// emit("update:currentPage", val);
// };
// /**
// * 监听个数改变
// */
// const updatePageSize = (val) => {
// console.log(val);
// emit("update:pageSize", val);
// };
/**
* @method handleSizeChange
* @description 每页内容条数变化响应
*/
const handleSizeChange = (val) => {
scrollTo(0, 800);
emit("pageChange", props.currentPage, val, props.tagName);
};
/**
* @method handleCurrentChange
* @description 当前页码变化响应
*/
const handleCurrentChange = (val) => {
scrollTo(0, 800);
emit("pageChange", val, props.pageSize, props.tagName);
};
</script>
<template>
<div class="pagination-container">
<el-pagination
v-model:currentPage="currentPage"
v-model:pageSize="pageSize"
:page-sizes="props.pageSizes"
layout="total, sizes, prev, pager, next, jumper"
:total="total"
background
:onUpdate:currentPage="currentPage"
:onUpdate:pageSize="pageSize"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
>
</el-pagination>
</div>
</template>
<style scoped lang="scss">
.pagination-container {
padding: 10px;
}
.el-pagination {
margin-top: 30px;
text-align: right;
}
</style>