数据准备“:
const links = [
{
“sort”: 0,
“model_id”: “ew_sellerinfo_filepath”,
“collection_name”: “ewta_resource_data_ew_sellerinfo_filepath”
},
{
“sort”: 1,
“model_id”: “ew_collect_java_process”,
“collection_name”: “ewta_resource_data_ew_collect_java_process”
},
{
“sort”: 2,
“model_id”: “ew_sellerinfo_filetype”,
“collection_name”: “ewta_resource_data_ew_sellerinfo_filepath”
}
]
function handleSort(index, type) {
if (type == 'up') {
if (index == 0) return message.error('已经是第一个了')
// 与前一个元素交换
let temp = links[index].sort;
links[index].sort = links[index - 1].sort;
links[index - 1].sort = temp;
// 重新排序并更新显示
links.sort((a, b) => a.sort - b.sort);
setLinks([...links])
} else {
if (index == links.length - 1) return message.error('已经是最后一个了')
// 与下一个元素交换
let temp = links[index].sort;
links[index].sort = links[index + 1].sort;
links[index + 1].sort = temp;
// 重新排序并更新显示
links.sort((a, b) => a.sort - b.sort)
setLinks([...links])
}
}