NEZ-354 feat :表格添加根据字段排序的功能

This commit is contained in:
zhangyu
2020-07-15 18:32:25 +08:00
parent 514b907c97
commit 78dfc11028
11 changed files with 495 additions and 21 deletions

View File

@@ -53,7 +53,9 @@
v-loading="loading"
v-scrollBar:el-table="'large'"
:cell-class-name="messageStyle"
style="width: 100%;">
style="width: 100%;"
@sort-change="tableDataSort"
>
<el-table-column
:resizable="false"
v-for="(item, index) in tablelable"
@@ -61,6 +63,8 @@
:width="item.width"
:key="`col-${index}`"
:label="item.label"
:sortable="sortableShow(item.prop)"
:prop="propTitle(item.prop)"
>
<template slot-scope="scope" :column="item">
<span v-if="item.prop == 'time'">
@@ -313,6 +317,10 @@
this.getTableData();
},
search: function (searchObj) {
let orderBy='';
if(this.searchLabel.orderBy){
orderBy=this.searchLabel.orderBy
}
this.searchLabel = {};
this.pageObj.pageNo = 1;
for (let item in searchObj) {
@@ -320,8 +328,50 @@
this.$set(this.searchLabel, item, searchObj[item]);
}
}
if(orderBy){
this.$set(this.searchLabel, 'orderBy', orderBy);
}
this.getTableData();
}
},
//是否需要排序
sortableShow(prop){
switch(prop){
case 'id':
case 'username':
case 'ip':
case 'operation':
case 'type':
case 'createDate':
case 'time':
return'custom';
default : return false;
}
},
// prop字段
propTitle(prop){
switch(prop){
case 'id': return 'sl.id';
case 'username': return 'sl.username';
case 'ip': return 'sl.ip';
case 'operation': return 'sl.operation';
case 'type': return 'sl.type';
case 'createDate': return 'sl.create_date';
case 'time': return 'sl.time';
default : return prop;
}
},
// 数据排序
tableDataSort(item){
let orderBy='';
if(item.order==='ascending'){
orderBy=item.prop;
}
if(item.order==='descending'){
orderBy='-'+item.prop;
}
this.$set(this.searchLabel, "orderBy", orderBy);
this.getTableData();
},
},
computed: {
isCurrentUser() {