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
| <template>
| <div class="c-table-template">
| <div class="c-table-template__toolbar">
| <slot name="toolbar"></slot>
| </div>
| <div class="c-table-template__content">
| <el-table
| :data="data"
| :row-key="rowKey"
| default-expand-all
| @selection-change="handleSelectionChange"
| >
| <el-table-column
| v-if="selection"
| type="selection"
| width="55">
| </el-table-column>
| <slot name="columns"></slot>
| </el-table>
| </div>
| <div class="c-table-template__footer">
| <el-pagination
| v-if="!noPage"
| @size-change="handleSizeChange"
| @current-change="handleCurrentChange"
| background
| layout="total, sizes, prev, pager, next,jumper"
| :page-sizes="[10, 25, 50]"
| :total="total">
| </el-pagination>
| </div>
| </div>
| </template>
|
| <script>
| export default {
| name: "TableTemplate",
| props: {
| data: {
| type: Array,
| default: () => ([])
| },
| fetchData: {
| type: Function,
| default: () => ([])
| },
| total: {
| type: Number,
| default: 0
| },
| selection: {
| type: Boolean,
| default: false
| },
| rowKey: {
| type: String,
| default: ""
| },
| noPage: {
| type: Boolean,
| default: false
| }
| },
| data() {
| return {
| currentPageSize: 10
| };
| },
| methods: {
| handleSizeChange(pageSize) {
| this.currentPageSize = pageSize;
| this.$emit("page-change", {
| pageNum: 1,
| pageSize
| })
|
| },
| handleCurrentChange(pageNum) {
| this.$emit("page-change", {
| pageNum,
| pageSize: this.currentPageSize
| })
| },
| handleSelectionChange(selection) {
| this.$emit("selection-change", selection)
| }
| }
| };
| </script>
|
| <style scoped>
| .c-table-template {
| padding: 8px;
| }
| .c-table-template__toolbar {
| margin-bottom: 8px;
| }
| .c-table-template__footer {
| margin-top: 8px;
| }
| .el-pagination {
| text-align: right;
| }
| </style>
|
|