const onDragFalg = (dragResult: any, list: any[]) => {
  //目前只有move 需求
 
  const { moved } = dragResult;
  if (moved) {

    const { newIndex, oldIndex } = moved;
    if (newIndex == oldIndex) {
      return false;
    }
    let arr = applyDrag(list, dragResult);
    return arr;
  } else
    return false;
}


/**
    * 拖拽切换位置
    * @param {*} list 原始数据
    * @param {*} dragResult 处理后数据
    */
function applyDrag(list: any[], dragResult: any) {
  const { newIndex, oldIndex, element } = dragResult;
  if (!newIndex && !oldIndex) return list;
  const result = [...list];
  let itemToAdd = element;

  if (oldIndex !== null) {
    itemToAdd = result.splice(oldIndex, 1)[0];
  }

  if (newIndex !== null) {
    result.splice(newIndex, 0, itemToAdd);
  }

  return result;
}


export {
  onDragFalg
}