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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
| <template>
| <div class="mt-4 mb-2">
| <el-table
| :data="showList"
| table-layout="auto"
| stripe
| :empty-text="emptyText"
| style="width: 100%"
| >
| <el-table-column v-if="selectionFlag" type="selection" width="55" />
| <el-table-column
| v-for="(item,index) in headers" :key="index"
| :prop="item.value"
| :label="item.label"
| :width="item.width"
| :align="item.align || 'center'"
| :sortable="item.sortable"
| >
| <template v-if="$slots[item.value]" #default="scope">
| <slot :name="item.value" v-bind="scope"></slot>
| </template>
| </el-table-column>
| </el-table>
| <el-row class="mt-4" align="middle" justify="end" v-if="paginator">
| <el-pagination
| v-model:current-page="page"
| v-model:page-size="size"
| :page-sizes="pageSize"
| background
| :layout="layout"
| :total="totalCount || list.length"
| @size-change="handleSizeChange"
| @current-change="handleCurrentChange"
| />
| </el-row>
| </div>
| </template>
|
| <script>
|
| export default {
| data() {
| return {
| pageSize: [12, 24, 36, 48],
| page: 1,
| size: 12,
| showList: [],
| }
| },
| props: {
| filter: {
| type: Object,
| default: () => { return { pageNo: 1, pageSize: 12 } }
| },
| headers: {
| type: Array,
| default: () => []
| },
| list: {
| type: Array,
| default: () => []
| },
| totalCount: {
| type: Number,
| default: 0
| },
| layout: {
| type: String,
| default: 'total, sizes, prev, pager, next, jumper'
| },
| selectionFlag: {
| type: Boolean,
| default: false
| },
| emptyText: {
| type: String,
| default: '暂无数据'
| },
| paginator: {
| type: Boolean,
| default: true
| }
| },
| watch: {
| list: {
| handler() {
| this.updateShowList()
| },
| immediate: true
| },
| 'filter.page': function(val) {
| this.page = val
| },
| 'filter.size': function(val) {
| this.size = val
| }
| },
| methods: {
| handleSizeChange() {
| this.$emit('update:filter', {
| ...this.filter,
| size: this.size
| })
| this.updateShowList()
| },
| handleCurrentChange() {
| this.$emit('update:filter', {
| ...this.filter,
| page: this.page,
| })
| this.updateShowList()
| },
| updateShowList() {
| if (this.paginator) {
| this.showList = this.list.slice((this.page - 1) * this.size, this.page * this.size)
| } else {
| this.showList = this.list
| }
|
| }
| }
| }
|
| </script>
|
| <style>
| .el-table th.el-table__cell {
| padding: 12px 0;
| background-color: #fafafa;
| }
| </style>
|
|