修复任务列表排序导致的新增任务定位问题

- 修复 addTask 函数中的任务定位逻辑,使用临时标识来准确定位新任务
- 解决非编号排序时新增任务后展开错误编辑模块的问题
- 确保无论使用何种排序方式,新增任务后都能正确定位到新任务的配置区域
- 保持向后兼容,不影响现有排序和编辑功能

问题:任务列表使用非编号排序时,点击添加任务后展开的是排在最后的任务而不是新添加的任务
解决:通过临时标识和排序后列表查找,确保始终展开新添加的任务
This commit is contained in:
x1ao4 2025-09-15 01:38:17 +08:00
parent 41b2cd7727
commit 9e717f1b69

View File

@ -6915,8 +6915,10 @@
// 应用全局插件配置到新任务
this.applyGlobalPluginConfig(newTask);
// 给新任务添加临时标识,用于后续定位
newTask.__isNewlyAdded = true;
this.formData.tasklist.push(newTask)
const index = this.formData.tasklist.length - 1;
const originalIndex = this.formData.tasklist.length - 1;
// 清除之前任务的搜索记录,避免影响新任务
this.smart_param.taskSuggestions = {
@ -6926,9 +6928,16 @@
// 等Vue更新DOM后自动展开新添加的任务
this.$nextTick(() => {
$(`#collapse_${index}`).collapse('show');
// 滚动到底部
this.scrollToX();
// 找到新任务在排序后列表中的位置
const sortedIndex = this.sortedTasklist.findIndex(task => task.__isNewlyAdded);
if (sortedIndex !== -1) {
// 展开新任务的编辑模块
$(`#collapse_${sortedIndex}`).collapse('show');
// 滚动到新任务位置
this.scrollToX();
// 移除临时标识
delete newTask.__isNewlyAdded;
}
});
},
focusTaskname(index, task) {