diff --git a/frontend/src/views/TaskHall.vue b/frontend/src/views/TaskHall.vue index 2c27397..5b6c0e7 100644 --- a/frontend/src/views/TaskHall.vue +++ b/frontend/src/views/TaskHall.vue @@ -786,6 +786,10 @@

{{ task.title }}

+ + + 子任务 + 进行中 @@ -2695,7 +2699,7 @@ const handleCreateTask = () => { router.push('/tasks/create') } -// 加载进行中任务 +// 加载进行中任务(同时加载普通任务和子任务) const loadInProgressTasks = async () => { inProgressLoading.value = true try { @@ -2716,9 +2720,59 @@ const loadInProgressTasks = async () => { if (inProgressFilters.minProgress !== undefined) params.minProgress = inProgressFilters.minProgress if (inProgressFilters.maxProgress !== undefined) params.maxProgress = inProgressFilters.maxProgress - const response = await taskApi.getTasks(params) - inProgressTaskList.value = response.data.records || [] - inProgressTotal.value = response.data.total || 0 + // 同时获取普通任务和子任务 + const [taskResponse, itemResponse] = await Promise.all([ + taskApi.getTasks(params), + taskApi.getInProgressTaskItems(params) + ]) + + let allTasks: any[] = [] + let totalCount = 0 + + // 处理普通任务 + if (taskResponse.data && taskResponse.data.records) { + const tasks = taskResponse.data.records.map((task: any) => ({ + ...task, + isSubTask: false // 标记为普通任务 + })) + allTasks = [...allTasks, ...tasks] + totalCount += taskResponse.data.total || 0 + } + + // 处理子任务 + if (itemResponse.data && itemResponse.data.records) { + const items = itemResponse.data.records.map((item: any) => ({ + // 将子任务字段映射到任务字段 + ...item, + id: item.id, // 保持子任务的ID + itemId: item.id, // 额外保存子任务ID + title: item.taskTitle || item.title, // 使用主任务标题 + subTaskNo: item.itemNo, // 子任务编号 + isSubTask: true, // 标记为子任务 + taskId: item.taskId, // 保存主任务ID + // 保留子任务的其他字段 + groupNo: item.groupNo, + taskTypeId: item.taskTypeId, + score: item.score, + estimatedHours: item.estimatedHours, + description: item.description || item.taskDescription, + progress: item.progress, + status: 'in_progress' + })) + allTasks = [...allTasks, ...items] + totalCount += itemResponse.data.total || 0 + } + + // 按更新时间排序 + allTasks.sort((a, b) => { + const timeA = new Date(a.updateTime || a.startTime || 0).getTime() + const timeB = new Date(b.updateTime || b.startTime || 0).getTime() + return timeB - timeA // 降序 + }) + + inProgressTaskList.value = allTasks + inProgressTotal.value = totalCount + } catch (error) { console.error('加载进行中任务失败:', error) message.error('加载进行中任务失败') @@ -2855,13 +2909,13 @@ const handleReviewFiltersReset = () => { } // 判断是否可以更新进度(接单人) -const canUpdateProgress = (task: Task) => { +const canUpdateProgress = (task: TaskOrSubTask) => { const userInfo = JSON.parse(localStorage.getItem('userInfo') || '{}') return task.receiverId === userInfo.id } // 判断是否可以完结任务(接单人) -const canCompleteTask = (task: Task) => { +const canCompleteTask = (task: TaskOrSubTask) => { const userInfo = JSON.parse(localStorage.getItem('userInfo') || '{}') return task.receiverId === userInfo.id && (task.progress || 0) >= 100 } @@ -2890,14 +2944,16 @@ const canRejectTask = (task: Task) => { return canApproveTask(task) } -// 更新进度 -const handleUpdateProgress = (task: Task) => { +// 更新进度(支持普通任务和子任务) +const handleUpdateProgress = (task: TaskOrSubTask) => { let newProgress = task.progress || 0 + const isSubTask = task.isSubTask + const taskType = isSubTask ? '子任务' : '任务' Modal.confirm({ - title: '更新任务进度', + title: `更新${taskType}进度`, content: h('div', [ - h('div', { style: 'margin-bottom: 12px;' }, `任务:${task.title}`), + h('div', { style: 'margin-bottom: 12px;' }, `${taskType}:${task.title}`), h('div', { style: 'margin-bottom: 12px;' }, `当前进度:${task.progress || 0}%`), h(InputNumber, { min: 0, @@ -2910,7 +2966,13 @@ const handleUpdateProgress = (task: Task) => { ]), onOk: async () => { try { - await taskApi.updateTaskProgress(task.id, newProgress) + if (isSubTask) { + // 更新子任务进度 + await taskApi.updateTaskItemProgress(task.itemId || task.id!, newProgress) + } else { + // 更新普通任务进度 + await taskApi.updateTaskProgress(task.id!, newProgress) + } message.success('进度更新成功') loadInProgressTasks() loadAllTabCounts() @@ -2922,14 +2984,16 @@ const handleUpdateProgress = (task: Task) => { }) } -// 完结任务 -const handleCompleteTask = (task: Task) => { +// 完结任务(支持普通任务和子任务) +const handleCompleteTask = (task: TaskOrSubTask) => { let deliveryPath = '' + const isSubTask = task.isSubTask + const taskType = isSubTask ? '子任务' : '任务' Modal.confirm({ - title: '完结任务', + title: `完结${taskType}`, content: h('div', [ - h('div', { style: 'margin-bottom: 12px;' }, `确认完结任务:${task.title}`), + h('div', { style: 'margin-bottom: 12px;' }, `确认完结${taskType}:${task.title}`), h('div', { style: 'margin-bottom: 12px;' }, '交付路径:'), h(Textarea, { rows: 4, @@ -2945,8 +3009,15 @@ const handleCompleteTask = (task: Task) => { } try { - await taskApi.completeTask(task.id, { deliveryPath }) - message.success('任务已提交审核') + if (isSubTask) { + // 完结子任务 + await taskApi.completeTaskItem(task.itemId || task.id!, { deliveryPath }) + message.success('子任务已完成,等待下一个子任务解锁') + } else { + // 完结普通任务 + await taskApi.completeTask(task.id!, { deliveryPath }) + message.success('任务已提交审核') + } loadInProgressTasks() loadAllTabCounts() loadDashboardStats()