table.vue
4 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<template>
<div class="glsx_table_box">
<el-table class="el_table" :data="tableData" border :size="size" v-loading="loading">
<el-table-column v-for="(item,index) in column" :key="index" :label="item.label" :prop="item.prop" :formatter="item.formatter" :align="item.align" :fixed="item.fixed" :width="item.width" show-overflow-tooltip>
<template slot-scope="{row}">{{row[item.prop]||'--'}}</template>
</el-table-column>
<el-table-column label="操作" v-if="this.$scopedSlots.operate" width="120px">
<template slot-scope="scope">
<slot name="operate" :scope="scope.row"></slot>
</template>
</el-table-column>
</el-table>
<div class="pagination_list">
<el-pagination background layout="sizes, total,prev, pager, next, jumper" :total="pageTotal" :page-size.sync="pageSize" :page-sizes="pageSizes" :current-page.sync="currentPage" @current-change="getList" @size-change="changePageSize" />
</div>
</div>
</template>
<script>
/**
* request: 接口方法
* list: 表格数据
* border:是否带边框
* size:表格尺寸
* column: 列数据
* layout:分页展示数据
* pageSizes: 默认展示多少页列表
* pageSize: 当前展示页条数
* params: 外部查询参数
*/
export default {
name: "GlsxTable",
props: {
request: {
type: Function,
},
list: {
type: Array,
default: function () {
return [];
},
},
column: {
type: Array,
default: function () {
return [];
},
},
border: {
type: Boolean,
default: true,
},
size: {
type: String,
default: "small",
},
layout: {
type: String,
default: "sizes, total,prev, pager, next, jumper",
},
pageSizes: {
type: Array,
default: function () {
return [10, 20, 30, 40];
},
},
params: {
type: Object,
default: function () {
return {};
},
},
},
data() {
return {
currentPage: 1,
pageSize: 10,
pageTotal: 0,
tableData: [],
loading: false,
};
},
watch: {
params: {
handler: function (n, o) {
if (n) {
console.log(n);
this.getList();
}
},
immediate: true,
},
},
created() {},
mounted() {
// if (this.request) {
// this.getList();
// }
},
methods: {
/**
* 每页展示
*/
changePageSize: function (e) {
this.pageSize = e;
this.currentPage = 1;
this.getList();
},
// 获取参数
getParams(current) {
console.log(this.params);
let oParams = { ...this.params };
if (current || oParams.current) {
this.currentPage = current || oParams.current;
}
oParams.pageSize = this.pageSize;
oParams.pageNumber = current || oParams.current || this.currentPage;
delete oParams.current;
return oParams;
},
// 获取列表
getList(current) {
let request = this.request;
let oParams = this.getParams(current);
console.log(oParams);
this.loading = true;
request(oParams)
.then((res) => {
this.loading = false;
if (res.code != 200) {
return false;
}
let {
data: { list, totalElements },
} = res;
this.tableData = list || [];
this.pageTotal = totalElements;
})
.catch((error) => {
this.loading = false;
});
},
// 重置
rest() {
this.pageSize = 10;
this.currentPage = 1;
this.getList();
},
// 重置分页参数
restParams() {
// this.pageSize = 10;
this.currentPage = 1;
this.pageSize = 10
},
},
};
</script>
<style lang="scss">
.el_table {
thead {
th {
//background: rgba(197, 197, 197, 0.1);
background: #f5f7fa;
}
}
}
</style>
<style lang="scss" scoped>
.glsx_table_box {
margin: 10px 0;
}
.pagination_list {
text-align: right;
padding: 10px 0;
}
</style>