解决switch拖拽,拖拽改成插入

This commit is contained in:
cw 2019-08-05 17:23:38 +08:00
parent 8e4d5b88e8
commit d067cce97b
11 changed files with 177424 additions and 172484 deletions

View File

@ -230,7 +230,16 @@ var Table = function (_Component) {
};
_this.swapArray = function (arr, index1, index2) {
arr[index1] = arr.splice(index2, 1, arr[index1])[0];
var value1 = arr[index1];
arr.splice(index1, 1);
if (index1 < index2) {
console.log('向下拖');
arr.splice(index2, 0, value1);
} else {
console.log('向上拖');
arr.splice(index2 + 1, 0, value1);
}
// arr[index1] = arr.splice(index2, 1, arr[index1])[0];
return arr;
};

View File

@ -165,6 +165,10 @@ var TableRow = function (_Component) {
var event = _utils.Event.getEvent(e),
_target = _utils.Event.getTarget(event),
target = _target.parentNode;
while (target.tagName != 'TR') {
target = target.parentNode;
}
_this.currentIndex = target.getAttribute("data-row-key");
onDragRowStart && onDragRowStart(_this.currentIndex);

2
dist/demo.css.map vendored

File diff suppressed because one or more lines are too long

343055
dist/demo.js vendored

File diff suppressed because one or more lines are too long

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -617,7 +617,17 @@ class Table extends Component {
* @param {number} index2 删除项目的位置
*/
swapArray = (arr, index1, index2) => {
arr[index1] = arr.splice(index2, 1, arr[index1])[0];
var value1 = arr[index1]
arr.splice(index1,1)
if(index1<index2){
console.log('向下拖')
arr.splice(index2,0,value1)
}else {
console.log('向上拖')
arr.splice(index2+1,0,value1)
}
return arr;
}

View File

@ -198,6 +198,10 @@ class TableRow extends Component{
let event = Event.getEvent(e) ,
_target = Event.getTarget(event),
target = _target.parentNode;
while (target.tagName != 'TR') {
target = target.parentNode
}
this.currentIndex = target.getAttribute("data-row-key");
onDragRowStart && onDragRowStart(this.currentIndex);