diff --git a/frontend/src/views/TaskHall.vue b/frontend/src/views/TaskHall.vue index 3bcf70c..86edd12 100644 --- a/frontend/src/views/TaskHall.vue +++ b/frontend/src/views/TaskHall.vue @@ -4277,21 +4277,16 @@ const loadDashboardStats = async () => { const month = selectedMonth.value?.format('YYYY-MM') const params: { month?: string; deptId?: number } = {} if (month) params.month = month - // 获取有效的部门ID(切换的部门或用户自己的部门) - let effectiveDept = effectiveDeptId.value - // 如果 effectiveDeptId 为空,尝试从 localStorage 获取 - if (!effectiveDept) { - const userStr = localStorage.getItem('userInfo') - if (userStr) { - try { - const user = JSON.parse(userStr) - effectiveDept = user.deptId - } catch (e) { /* ignore */ } - } - } - if (effectiveDept) { - params.deptId = effectiveDept + + // 只有部门负责人切换了部门视角时才传递 deptId + // 普通用户不传 deptId,后端会根据 userId 查询个人数据 + const isDeptLeader = userInfo.value?.isDepartmentLeader || false + if (isDeptLeader && currentDeptView.value !== undefined) { + // 部门负责人且切换了部门视角 + params.deptId = currentDeptView.value } + // 注意:普通用户不传 deptId,这样后端会按用户个人统计数据 + const response = await taskApi.getDashboardStats(Object.keys(params).length > 0 ? params : undefined) if (response.code === 200) { const data = response.data