下边就是最关键的方法部分了 两天才出来的效果,网上的很多分用在我们的项目中一直不能实现,可能是由于数据请求的关系
toggleSelection(rows) {
if (rows) {
rows.forEach(row => {
console.log(row);
this.KaTeX parse error: Expected 'EOF', got '}' at position 45: …(row); }̲); } else…refs.table.clearSelection();
}
},
// 设置选中的方法
setSelectRow(data) {
console.log(data);
if(data&&data.length>0){
var d = this.tableData;
for(var i=0;i<data.length;i++){
var index = data[i].personId;
this.$refs.table.toggleRowSelection(this.tableData[index], true);
}
}
},
// 记忆选择核心方法
changePageCoreRecordData() {
// 标识当前行的唯一键的名称
let idKey = this.idKey;
let that = this;
// 如果总记忆中还没有选择的数据,那么就直接取当前页选中的数据,不需要后面一系列计算
if (this.multipleSelectionAll.length <= 0) {
this.multipleSelectionAll = this.multipleSelection;
return;
}
// 总选择里面的key集合
let selectAllIds = [];
this.multipleSelectionAll.forEach(row => {
selectAllIds.push(row[idKey]);
});
let selectIds = [];
// 获取当前页选中的id
this.multipleSelection.forEach(row => {
selectIds.push(row[idKey]);
// 如果总选择里面不包含当前页选中的数据,那么就加入到总选择集合里
if (selectAllIds.indexOf(row[idKey]) < 0) {
that.multipleSelectionAll.push(row);
}
});
let noSelectIds = [];
// 得到当前页没有选中的id
this.tableData.forEach(row => {
if (selectIds.indexOf(row[idKey]) < 0) {
noSelectIds.push(row[idKey]);
}
});
noSelectIds.forEach(id => {
if (selectAllIds.indexOf(id) >= 0) {
for (let i = 0; i < that.multipleSelectionAll.length; i++) {
if (that.multipleSelectionAll[i][idKey] == id) {
// 如果总选择中有未被选中的,那么就删除这条
that.multipleSelectionAll.splice(i, 1);
break;
}
}
}
});
},
currentChange(val) {
this.nextPageFlag = true;
// 改变页的时候调用一次
this.changePageCoreRecordData();
this.pagination.pageNumber = val;
this.queryData();
},
sizeChange(val) {
// 改变每页显示条数的时候调用一次
this.changePageCoreRecordData();
this.pagination.pageSize = val;
this.queryData();
},
handleSelectionChange(val) {
var key = this.pagination.pageNumber;
if(val.length>0){
this.checkedObj[key]= val;
}
if(val.length==0&&!this.nextPageFlag){
this.checkedObj[key]= val;
}
this.nextPageFlag = false;
},
queryData() {
var that = this;
that.tableData = [];
var state = that.$route.query;
var rotate = that.$route.query;
var data = {
startTime: that.$store.state.time.startTime * 1000,
stopTime: that.$store.state.time.stopTime * 1000,
linkCard:parseInt(rotate.linkCard) || parseInt(that.$store.state.linkCard),
currentPage: that.pagination.pageNumber,
pageSize: that.pagination.pageSize
};
filesService.getFiles(data).then(function(res) {
if (res.status == 200) {
var arr = res.data.dataInfo;
that.pagination.totalRows = res.data.total;
var fileDataArr = [];
for (var i = 0; i < arr.length; i++) {
var fileData = {};
fileData.fileName = arr[i]._source.fileName;
fileData.cardId = arr[i]._source.cardId;
fileData.startTime = arr[i]._source.startTime;
fileData.endTime = arr[i]._source.endTime;
fileData.personId = i;
fileDataArr.push(fileData);
}
that.tableData = fileDataArr;
setTimeout(() => {
that.setSelectRow(that.checkedObj[that.pagination.pageNumber]);
}, 100);
console.log(that.checkedObj);
}
});
},