const el = this. r e f s . s i n g l e T a b l e . refs.singleTable. refs.singleTable.el.querySelectorAll(‘.el-table__body-wrapper > table > tbody’)[0]
this.sortable = Sortable.create(el, {
ghostClass: ‘sortable-ghost’,
setData: function (dataTransfer) {
dataTransfer.setData(‘Text’, ‘’)
},
onEnd: e => {
// e.oldIndex为拖动一行原来的位置,e.newIndex为拖动后新的位置
const targetRow = this.tableDatas.splice(e.oldIndex, 1)[0];
this.tableDatas.splice(e.newIndex, 0, targetRow);
let selectLine = this.tableDatas[e.newIndex].id;//拖动行的id
let beforeId,afterId
// 拖动行的前一行
if( this.tableDatas[e.newIndex-1]){
beforeId = this.tableDatas[e.newIndex-1].id;
}else {
beforeId = “”
}
// 拖动行的后一行
if( this.tableDatas[e.newIndex+1]){
afterId = this.tableDatas[e.newIndex+1].id;
}else {
afterId = “”
}
this.postRequest({
url: “接口路径”,
data: {
“selectLineId”: selectLineId,
“beforeId”: beforeId,
“afterId”: afterId ,
},
success: (result) => {
if (result) {
this.$message({
message: “排序成功!”,
type: “success”,
})
}else {
this.$message({
message: “排序失败!”,
type: “error”
});
}
}
})
}
})
},
}
};