mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-10 03:09:50 +08:00
refactor: 重构优先级拖拽排序逻辑,支持整组移动与归一化
- 将拖拽逻辑从简单的两项交换改为整组移动并重新归一化优先级值 - 修复对话框内容区域高度限制(min-h 改为 max-h) - 优化 API 调用,只更新实际发生变化的 key
This commit is contained in:
@@ -1118,11 +1118,34 @@ async function handleKeyDrop(event: DragEvent, targetIndex: number) {
|
||||
handleKeyDragEnd()
|
||||
|
||||
try {
|
||||
// 直接交换优先级
|
||||
await Promise.all([
|
||||
updateProviderKey(draggedKey.id, { internal_priority: targetPriority }),
|
||||
updateProviderKey(targetKey.id, { internal_priority: draggedPriority })
|
||||
])
|
||||
// 收集所有唯一的优先级并排序
|
||||
const uniquePriorities = [...new Set(keys.map(k => k.internal_priority ?? 0))].sort((a, b) => a - b)
|
||||
|
||||
// 找到被拖动组和目标组的索引
|
||||
const draggedGroupIndex = uniquePriorities.indexOf(draggedPriority)
|
||||
const targetGroupIndex = uniquePriorities.indexOf(targetPriority)
|
||||
|
||||
// 移动优先级组
|
||||
uniquePriorities.splice(draggedGroupIndex, 1)
|
||||
uniquePriorities.splice(targetGroupIndex, 0, draggedPriority)
|
||||
|
||||
// 创建旧优先级到新优先级的映射(按顺序重新分配 1, 2, 3...)
|
||||
const priorityMap = new Map<number, number>()
|
||||
uniquePriorities.forEach((oldPriority, index) => {
|
||||
priorityMap.set(oldPriority, index + 1)
|
||||
})
|
||||
|
||||
// 更新所有 key 的优先级
|
||||
const updatePromises = keys.map(key => {
|
||||
const oldPriority = key.internal_priority ?? 0
|
||||
const newPriority = priorityMap.get(oldPriority)
|
||||
if (newPriority !== undefined && oldPriority !== newPriority) {
|
||||
return updateProviderKey(key.id, { internal_priority: newPriority })
|
||||
}
|
||||
return Promise.resolve()
|
||||
})
|
||||
|
||||
await Promise.all(updatePromises)
|
||||
showSuccess('优先级已更新')
|
||||
await loadEndpoints()
|
||||
emit('refresh')
|
||||
|
||||
Reference in New Issue
Block a user