liuyu
6 小时以前 82a74ba0402ab546ba524d23ce62198c4d00d2f7
1
2
3
4
5
6
7
export function moveListItem<T>(list: T[], oldIndex?: null | number, newIndex?: null | number) {
  if (oldIndex == null || newIndex == null || oldIndex === newIndex || oldIndex < 0 || newIndex < 0 || oldIndex >= list.length || newIndex >= list.length) {
    return;
  }
  const [item] = list.splice(oldIndex, 1);
  if (item !== undefined) list.splice(newIndex, 0, item);
}