From 8c4f37d3090e75947e8c7eef27e082c66dfc204e Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 8 Jan 2026 11:49:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8F=91=E5=B8=83=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E8=AE=BE=E8=AE=A1=E5=B8=88=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=EF=BC=8C=E8=87=AA=E5=8A=A8=E5=8A=A0=E8=BD=BD=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=B1=BB=E5=9E=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8D=95=E9=83=A8=E9=97=A8=E8=AE=BE=E8=AE=A1=E5=B8=88=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=8F=8A=E5=B7=A5=E4=BD=9C=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/views/CreateTask.vue | 70 ++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 24 deletions(-) diff --git a/frontend/src/views/CreateTask.vue b/frontend/src/views/CreateTask.vue index 0131291..a2af41c 100644 --- a/frontend/src/views/CreateTask.vue +++ b/frontend/src/views/CreateTask.vue @@ -621,8 +621,8 @@ interface CascaderOption { estimatedHours?: number } -// 设计师列表缓存 { deptId: designers[] } -const designersCache = reactive>({}) +// 设计师列表缓存 { cacheKey: designers[] } +const designersCache = reactive>({}) // 表单数据 const formData = reactive({ @@ -853,27 +853,22 @@ const findTaskTypeById = (id: number, items: any[] = hierarchicalTaskTypes.value return null } -// 加载设计师列表 +// 加载设计师列表(根据任务类型配置的接单部门获取设计师及工作量) const loadDesignersForItem = async (item: TaskTypeItem) => { if (!item.taskTypeId) return - const typeInfo = getTaskTypeInfo(item.taskTypeId) - if (!typeInfo || !typeInfo.allowedDeptIds) return + // 使用 taskTypeId 作为缓存key + const cacheKey = `type_${item.taskTypeId}` - // 简化处理:取第一个允许的部门ID - const deptIds = typeInfo.allowedDeptIds.split(',') - if (deptIds.length === 0) return - - const deptId = Number(deptIds[0]) - - if (!designersCache[deptId]) { + if (!designersCache[cacheKey]) { try { - const res = await userApi.getDesignersWithWorkload(deptId) - if (res.code === 200) { - designersCache[deptId] = res.data - } + // 传入 taskTypeId,后端会根据任务类型配置的接单部门获取设计师 + const designers = await userApi.getDesignersWithWorkload(undefined, item.taskTypeId) + designersCache[cacheKey] = designers || [] + console.log(`加载任务类型 ${item.taskTypeId} 的设计师列表:`, designers?.length || 0, '人') } catch (error) { console.error('加载设计师失败:', error) + designersCache[cacheKey] = [] } } } @@ -882,14 +877,8 @@ const loadDesignersForItem = async (item: TaskTypeItem) => { const getDesignersForItem = (item: TaskTypeItem) => { if (!item.taskTypeId) return [] - const typeInfo = getTaskTypeInfo(item.taskTypeId) - if (!typeInfo || !typeInfo.allowedDeptIds) return [] - - const deptIds = typeInfo.allowedDeptIds.split(',') - if (deptIds.length === 0) return [] - - const deptId = Number(deptIds[0]) - return designersCache[deptId] || [] + const cacheKey = `type_${item.taskTypeId}` + return designersCache[cacheKey] || [] } // 添加任务类型 @@ -962,6 +951,39 @@ watch( } ) +// 监听发布类型变化,当切换到"指定任务"模式时,自动加载设计师列表 +watch( + () => formData.releaseType, + async (newValue) => { + if (newValue === 'assigned') { + // 为所有已选择任务类型的项加载设计师列表 + for (const item of formData.taskTypes) { + if (item.taskTypeId) { + await loadDesignersForItem(item) + } + } + } + } +) + +// 监听任务类型选择变化,当在"指定任务"模式下选择新任务类型时,自动加载设计师 +watch( + () => formData.taskTypes.map(item => item.taskTypeId), + async (newIds, oldIds) => { + if (formData.releaseType === 'assigned') { + // 找出新增或变化的任务类型 + for (let i = 0; i < newIds.length; i++) { + const newId = newIds[i] + const oldId = oldIds?.[i] + if (newId && newId !== oldId) { + await loadDesignersForItem(formData.taskTypes[i]) + } + } + } + }, + { deep: true } +) + // 计算预估积分(累加所有任务类型) const estimatedScore = computed(() => { let totalScore = 0