From 06194088ac3ef195c587609d50dfc0617d7b1927 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 14 Jan 2026 19:32:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A2=AB=E9=A9=B3=E5=9B=9E?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E9=87=8D=E6=96=B0=E7=BC=96=E8=BE=91=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=B1=BB=E5=9E=8B=E4=BF=A1=E6=81=AF=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 从子任务的typeDetails中解析完整的任务类型信息 - 添加findTaskTypePath函数用于查找任务类型的级联路径 - 加载任务后自动设置taskTypePath以正确显示级联选择器 - 不预设selectedDeptId,让用户重新选择或自动匹配 --- frontend/src/views/CreateTask.vue | 80 +++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/frontend/src/views/CreateTask.vue b/frontend/src/views/CreateTask.vue index ae65e5a..7858431 100644 --- a/frontend/src/views/CreateTask.vue +++ b/frontend/src/views/CreateTask.vue @@ -861,6 +861,21 @@ const findTaskTypeById = (id: number, items: any[] = hierarchicalTaskTypes.value return null } +// 根据任务类型ID查找完整的级联路径 +const findTaskTypePath = (targetId: number, items: any[] = hierarchicalTaskTypes.value, currentPath: number[] = []): number[] | null => { + for (const item of items) { + const newPath = [...currentPath, item.id] + if (item.id === targetId) { + return newPath + } + if (item.children && item.children.length > 0) { + const found = findTaskTypePath(targetId, item.children, newPath) + if (found) return found + } + } + return null +} + // 加载设计师列表(根据任务类型ID) const loadDesignersForItem = async (item: TaskTypeItem) => { if (!item.taskTypeId) return @@ -1684,16 +1699,51 @@ const loadTaskForEdit = async (taskId: number) => { }] } - // 处理任务类型和数量 - 优先从子任务中获取 + // 处理任务类型和数量 - 优先从子任务的typeDetails中获取 if (task.isPipeline === 1 && task.subTasks && task.subTasks.length > 0) { - // 流水线任务:从子任务中提取任务类型信息 + // 流水线任务:从子任务的typeDetails中提取任务类型信息 console.log('流水线任务子任务:', task.subTasks) - formData.taskTypes = task.subTasks.map((subTask: any) => ({ - taskTypeId: subTask.taskTypeId, - quantity: subTask.quantity || 1, - receiverId: subTask.receiverId, - selectedDeptId: subTask.receiverDeptId - })) + const taskTypeItems: TaskTypeItem[] = [] + + for (const subTask of task.subTasks) { + // 优先从typeDetails解析(包含完整的任务类型明细) + if (subTask.typeDetails) { + try { + const details = typeof subTask.typeDetails === 'string' + ? JSON.parse(subTask.typeDetails) + : subTask.typeDetails + + for (const detail of details) { + taskTypeItems.push({ + taskTypeId: detail.typeId, + quantity: detail.quantity || 1, + receiverId: detail.receiverId || subTask.receiverId, + selectedDeptId: undefined // 不预设部门,让用户重新选择或自动匹配 + }) + } + } catch (e) { + console.warn('解析typeDetails失败:', e) + // 解析失败时使用子任务的基本信息 + taskTypeItems.push({ + taskTypeId: subTask.taskTypeId, + quantity: subTask.quantity || 1, + receiverId: subTask.receiverId, + selectedDeptId: undefined + }) + } + } else { + // 没有typeDetails时使用子任务的基本信息 + taskTypeItems.push({ + taskTypeId: subTask.taskTypeId, + quantity: subTask.quantity || 1, + receiverId: subTask.receiverId, + selectedDeptId: undefined + }) + } + } + + formData.taskTypes = taskTypeItems + console.log('解析后的任务类型:', formData.taskTypes) } else if (task.taskTypeIds) { // 非流水线任务:从taskTypeIds字符串解析 const typeIds = task.taskTypeIds.split(',').map((id: string) => parseInt(id.trim())) @@ -1711,6 +1761,20 @@ const loadTaskForEdit = async (taskId: number) => { }] } + // 为每个任务类型设置级联路径(需要在层级数据加载后执行) + // 使用 nextTick 确保层级数据已加载 + nextTick(() => { + for (const item of formData.taskTypes) { + if (item.taskTypeId) { + const path = findTaskTypePath(item.taskTypeId) + if (path) { + item.taskTypePath = path + console.log(`任务类型 ${item.taskTypeId} 的路径:`, path) + } + } + } + }) + // 处理附件 - 完整加载原有附件 if (task.attachmentUrl) { formData.attachmentUrl = task.attachmentUrl