long
2021-07-16 54e0b4ee48a281810bb910691b7d076f0c88204c
提交 | 用户 | age
2a61f6 1 <template>
L 2   <div :class="{'hidden':hidden}" class="pagination-container">
3     <el-pagination
4       :background="background"
5       :current-page.sync="currentPage"
6       :page-size.sync="pageSize"
7       :layout="layout"
8       :page-sizes="pageSizes"
9       :total="total"
10       v-bind="$attrs"
11       @size-change="handleSizeChange"
12       @current-change="handleCurrentChange"
13     />
14   </div>
15 </template>
16
17 <script>
18 import { scrollTo } from '@/utils/scroll-to'
19
20 export default {
21   name: 'Pagination',
22   props: {
23     total: {
24       required: true,
25       type: Number
26     },
27     page: {
28       type: Number,
29       default: 1
30     },
31     limit: {
32       type: Number,
33       default: 20
34     },
35     pageSizes: {
36       type: Array,
37       default() {
38         return [10, 20, 30, 50]
39       }
40     },
41     layout: {
42       type: String,
43       default: 'total, sizes, prev, pager, next, jumper'
44     },
45     background: {
46       type: Boolean,
47       default: true
48     },
49     autoScroll: {
50       type: Boolean,
51       default: true
52     },
53     hidden: {
54       type: Boolean,
55       default: false
56     }
57   },
58   computed: {
59     currentPage: {
60       get() {
61         return this.page
62       },
63       set(val) {
64         this.$emit('update:page', val)
65       }
66     },
67     pageSize: {
68       get() {
69         return this.limit
70       },
71       set(val) {
72         this.$emit('update:limit', val)
73       }
74     }
75   },
76   methods: {
77     handleSizeChange(val) {
78       this.$emit('pagination', { page: this.currentPage, limit: val })
79       if (this.autoScroll) {
80         scrollTo(0, 800)
81       }
82     },
83     handleCurrentChange(val) {
84       this.$emit('pagination', { page: val, limit: this.pageSize })
85       if (this.autoScroll) {
86         scrollTo(0, 800)
87       }
88     }
89   }
90 }
91 </script>
92
93 <style scoped>
94 .pagination-container {
95   background: #fff;
96   padding: 32px 16px;
97 }
98 .pagination-container.hidden {
99   display: none;
100 }
101 </style>