上移
const moveUp = async () => {
if (eleData.choosedIndex === -1) {
message.error('请先选择一条数据');
} else if (eleData.choosedIndex === 0) {
message.warn('已经是第一条数据了');
} else {
eleData.dataSource.splice(
eleData.choosedIndex - 1,
1,
...eleData.dataSource.splice(
eleData.choosedIndex,
1,
eleData.dataSource[eleData.choosedIndex - 1],
),
);
}
};
下移
const moveDown = () => {
if (eleData.choosedIndex == -1) {
message.warn('请先选择一条数据');
} else if (eleData.choosedIndex == eleData.dataSource.length - 1) {
message.warn('已经是最后一条数据了');
} else {
eleData.dataSource.splice(
eleData.choosedIndex,
1,
...eleData.dataSource.splice(
eleData.choosedIndex + 1,
1,
eleData.dataSource[eleData.choosedIndex],
),
);
}
};
保存顺序
/** 保存顺序 */
const saveIndex = async () => {
const data = eleData.dataSource.map((item: any, index) => {
item.sort_no = index;
return item;
});
console.log('========item==', data);
const res: any = await saveElementOrder(
data,
);
if (res.status_code == '0000') {
message.success('保存顺序成功');
getTableList(null, null);
} else {
message.error(res.reason);
}
};