feat:二级表格页面添加排序功能

This commit is contained in:
zhangyu
2020-07-21 10:03:31 +08:00
parent f26e72bbd7
commit b5311a5eb6
4 changed files with 163 additions and 9 deletions

View File

@@ -57,7 +57,10 @@
v-scrollBar:el-table="'normal'" v-scrollBar:el-table="'normal'"
:cell-class-name="labelsClassName" :cell-class-name="labelsClassName"
@selection-change="selectChange" @selection-change="selectChange"
style="width: 100%;"> style="width: 100%;"
@sort-change="tableDataSort"
v-loading="loading"
>
<el-table-column <el-table-column
:resizable="false" :resizable="false"
type="selection" type="selection"
@@ -73,6 +76,8 @@
:label="item.label" :label="item.label"
:show-overflow-tooltip="item.prop != 'labels'" :show-overflow-tooltip="item.prop != 'labels'"
min-width="110px" min-width="110px"
:sortable="sortableShow(item.prop)"
:prop="propTitle(item.prop)"
> >
<template slot-scope="scope" :column="item"> <template slot-scope="scope" :column="item">
<template v-if="item.prop == 'alertRule'"> <template v-if="item.prop == 'alertRule'">
@@ -158,7 +163,9 @@
v-scrollBar:el-table="'large'" v-scrollBar:el-table="'large'"
:cell-class-name="labelsClassName" :cell-class-name="labelsClassName"
@selection-change="selectChange" @selection-change="selectChange"
style="width: 100%;"> style="width: 100%;"
>
<el-table-column <el-table-column
:resizable="false" :resizable="false"
type="selection" type="selection"
@@ -327,6 +334,7 @@ export default {
pageSize: 50, pageSize: 50,
total: 0 total: 0
}, },
loading:false,// 表格数据加载loading
screenPageObj:{ screenPageObj:{
pageNo: 1, pageNo: 1,
pageSize: 50, pageSize: 50,
@@ -361,6 +369,7 @@ export default {
divFirstShow:false, divFirstShow:false,
searchTime: [new Date().setHours(new Date().getHours() - 1), new Date()],//全屏显示的时间 searchTime: [new Date().setHours(new Date().getHours() - 1), new Date()],//全屏显示的时间
oldSearchTime: [], oldSearchTime: [],
searchLabel:{},
tableTitle: [ tableTitle: [
{ {
label: 'ID', label: 'ID',
@@ -694,6 +703,7 @@ export default {
}, },
getAlertList: function (filterType,isPreview=false,chartInfo) { getAlertList: function (filterType,isPreview=false,chartInfo) {
this.resize(); this.resize();
this.loading=true;
this.isPreview = isPreview; this.isPreview = isPreview;
let queryParam={ let queryParam={
pageSize:this.pageObj.pageSize, pageSize:this.pageObj.pageSize,
@@ -729,6 +739,9 @@ export default {
queryParam.state=param.state; queryParam.state=param.state;
} }
} }
if(this.searchLabel.orderBy){
queryParam.orderBy=this.searchLabel.orderBy;
}
this.startLoading(filterType); this.startLoading(filterType);
this.$get('/alert/message', queryParam).then(response => { this.$get('/alert/message', queryParam).then(response => {
if (response.code == 200) { if (response.code == 200) {
@@ -759,6 +772,7 @@ export default {
this.divFirstShow = true; this.divFirstShow = true;
this.firstShow = true; // 展示操作按键 this.firstShow = true; // 展示操作按键
this.loading=false;
this.endLoading(filterType); this.endLoading(filterType);
}else{ }else{
this.isError = true; this.isError = true;
@@ -809,7 +823,6 @@ export default {
}, },
elementsetHide() { elementsetHide() {
//悬浮点击空白隐藏 //悬浮点击空白隐藏
console.log(11112)
this.$refs.elementset.elementsetHide(); this.$refs.elementset.elementsetHide();
}, },
tablelabelEmit(data) { tablelabelEmit(data) {
@@ -947,6 +960,43 @@ export default {
setData(chartItem, seriesItem, panelId, filter,area,errorMsg) { setData(chartItem, seriesItem, panelId, filter,area,errorMsg) {
console.info(chartItem,title) console.info(chartItem,title)
}, },
//是否需要排序
sortableShow(prop){
switch(prop){
case 'id':
case 'state':
case 'alertRule':
case 'severity':
case 'startAt':
case 'endAt':
return'custom';
default : return false;
}
},
// prop字段
propTitle(prop){
switch(prop){
case 'id': return'am.id';
case 'state': return'am.state';
case 'alertRule': return'ar.alert_name';
case 'severity': return'am.severity';
case 'startAt': return'am.start_at';
case 'endAt': return'am.end_at';
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.getAlertList();
},
}, },
mounted() { mounted() {

View File

@@ -36,7 +36,9 @@
:height="$tableHeight.openSubList.subList" :height="$tableHeight.openSubList.subList"
:cell-class-name="labelsClassName" :cell-class-name="labelsClassName"
@selection-change="selectChange" @selection-change="selectChange"
style="width: 100%;"> style="width: 100%;"
@sort-change="tableDataSort"
>
<el-table-column <el-table-column
:resizable="false" :resizable="false"
type="selection" type="selection"
@@ -53,6 +55,8 @@
:label="item.label" :label="item.label"
:show-overflow-tooltip="item.prop != 'labels'" :show-overflow-tooltip="item.prop != 'labels'"
min-width="110px" min-width="110px"
:sortable="sortableShow(item.prop)"
:prop="propTitle(item.prop)"
> >
<template slot-scope="scope" :column="item"> <template slot-scope="scope" :column="item">
<template v-if="item.prop == 'alertRule'"> <template v-if="item.prop == 'alertRule'">
@@ -698,6 +702,10 @@
}, },
search: function (searchObj) { search: function (searchObj) {
this.searchLabel = {}; this.searchLabel = {};
let orderBy='';
if(this.searchLabel.orderBy){
orderBy=this.searchLabel.orderBy
}
if (this.from == "alertRule") { if (this.from == "alertRule") {
this.searchLabel.ruleId = this.obj.id; this.searchLabel.ruleId = this.obj.id;
} else if (this.from == "asset") { } else if (this.from == "asset") {
@@ -709,6 +717,9 @@
this.$set(this.searchLabel, item, searchObj[item]); this.$set(this.searchLabel, item, searchObj[item]);
} }
} }
if(orderBy){
this.$set(this.searchLabel, 'orderBy', orderBy);
}
this.getAlertList(); this.getAlertList();
}, },
closeSubList() { closeSubList() {
@@ -721,7 +732,44 @@
this.viewAssetState = false this.viewAssetState = false
this.$refs['assetEditUnit'].tabView = false this.$refs['assetEditUnit'].tabView = false
} }
} },
//是否需要排序
sortableShow(prop){
switch(prop){
case 'id':
case 'state':
case 'alertRule':
case 'severity':
case 'startAt':
case 'endAt':
return'custom';
default : return false;
}
},
// prop字段
propTitle(prop){
switch(prop){
case 'id': return'am.id';
case 'state': return'am.state';
case 'alertRule': return'ar.alert_name';
case 'severity': return'am.severity';
case 'startAt': return'am.start_at';
case 'endAt': return'am.end_at';
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.getAlertList();
},
}, },
watch: { watch: {
obj: { obj: {

View File

@@ -34,7 +34,9 @@
:height="$tableHeight.noPagination" :height="$tableHeight.noPagination"
v-scrollBar:el-table="'large'" v-scrollBar:el-table="'large'"
ref="endpointTable" ref="endpointTable"
style="width: 100%;"> style="width: 100%;"
@sort-change="tableDataSort"
>
<el-table-column <el-table-column
:resizable="false" :resizable="false"
v-for="(item, index) in tablelable" v-for="(item, index) in tablelable"
@@ -43,6 +45,8 @@
:key="`col-${index}`" :key="`col-${index}`"
:label="item.label" :label="item.label"
min-width="110px" min-width="110px"
:sortable="sortableShow(item.prop)"
:prop="propTitle(item.prop)"
> >
<template slot-scope="scope" :column="item"> <template slot-scope="scope" :column="item">
<span v-if="item.prop == 'asset' && scope.row[item.prop]" class="link" @click="">{{scope.row[item.prop].host}}</span> <span v-if="item.prop == 'asset' && scope.row[item.prop]" class="link" @click="">{{scope.row[item.prop].host}}</span>
@@ -113,7 +117,9 @@
showTopBtn: false, //top按钮是否显示 showTopBtn: false, //top按钮是否显示
toTopBtnTop: this.$tableHeight.toTopBtnTop, //to-top按钮的top属性 toTopBtnTop: this.$tableHeight.toTopBtnTop, //to-top按钮的top属性
tableHover: false, //控制滚动条和top按钮同时出现 tableHover: false, //控制滚动条和top按钮同时出现
endpointSearchLabel:{
},
loading: false, loading: false,
tableTitle: [ tableTitle: [
{ {
@@ -201,7 +207,9 @@
}, },
getTableData() { getTableData() {
this.loading = true; this.loading = true;
this.$get('/endpoint?assetId=' + this.asset.id + 'pageSize=-1').then(response => { this.$set(this.endpointSearchLabel, "assetId", this.asset.id);
this.$set(this.endpointSearchLabel, "pageSize", '-1');
this.$get('/endpoint',this.endpointSearchLabel).then(response => {
this.loading = false; this.loading = false;
if (response.code === 200) { if (response.code === 200) {
this.tableData = response.data.list; this.tableData = response.data.list;
@@ -240,6 +248,20 @@
this.$set(this.searchLabel, item, searchObj[item]); this.$set(this.searchLabel, item, searchObj[item]);
} }
}*/ }*/
let orderBy='';
if(this.searchLabel.orderBy){
orderBy=this.searchLabel.orderBy
}
this.searchLabel={};
this.pageObj.pageNo = 1;
for (let item in searchObj) {
if (searchObj[item]) {
this.$set(this.searchLabel, item, searchObj[item]);
}
}
if(orderBy){
this.$set(this.searchLabel, 'orderBy', orderBy);
}
this.getTableData(); this.getTableData();
}, },
closeSubList() { closeSubList() {
@@ -321,6 +343,39 @@
} }
} }
}, },
//是否需要排序
sortableShow(prop){
switch(prop){
case 'id':
case 'asset':
case 'port':
// case 'path':
return 'custom';
default : return false;
}
},
// prop字段
propTitle(prop){
switch(prop){
case 'id': return'e.id';
case 'asset': return'a.host';
case 'port': return'e.port';
// case 'path': return'e.path';
default : return prop;
}
},
// 数据排序
tableDataSort(item){
let orderBy='';
if(item.order==='ascending'){
orderBy=item.prop;
}
if(item.order==='descending'){
orderBy='-'+item.prop;
}
this.$set(this.endpointSearchLabel, "orderBy", orderBy);
this.getTableData();
},
}, },
watch: { watch: {
obj: { obj: {
@@ -329,7 +384,9 @@
handler(n) { handler(n) {
if (n) { if (n) {
this.asset = JSON.parse(JSON.stringify(n)); this.asset = JSON.parse(JSON.stringify(n));
this.getTableData(); this.$nextTick(()=>{
this.getTableData();
})
} }
} }
} }

View File

@@ -997,7 +997,6 @@
getLeftMenuList(){ getLeftMenuList(){
this.$get('asset/filter').then(response => { this.$get('asset/filter').then(response => {
if (response.code === 200) { if (response.code === 200) {
console.log(response.data);
//dc //dc
this.checkListData = this.IDCOptionData = response.data.dc; this.checkListData = this.IDCOptionData = response.data.dc;
this.markOptionData(this.IDCOptionData); this.markOptionData(this.IDCOptionData);