根据用户截图,员工信息面板已经成功复用了 @employee-detail-panel 组件,但存在以下问题:
http://localhost:4200/admin/employeesF12 打开开发者工具应该看到以下日志序列:
// 1️⃣ 开始打开面板
🚀 [Employees] 开始打开员工信息面板: 徐福静 (xxxxxxxx)
// 2️⃣ 预加载数据
🔄 [Employees] 预加载员工 xxxxxxxx 的完整数据...
// 3️⃣ 项目数据加载完成
✅ [Employees] 项目数据加载完成: {
currentProjects: 3, // ⭐ 检查这个值
ongoingProjects: 3,
项目列表: ["项目A", "项目B", "项目C"]
}
// 4️⃣ 日历数据生成完成
📅 [Employees] 日历数据生成完成: {
days: 42, // ⭐ 应该是 42(6行×7列)
有项目的天数: 15 // ⭐ 检查这个值
}
// 5️⃣ 问卷数据加载完成
📝 [Employees] 问卷数据加载完成: {
completed: true, // ⭐ 检查这个值
answers: 12
}
// 6️⃣ 完整数据准备完成
🎯 [Employees] 完整数据准备完成,打开面板: {
currentProjects: 3, // ⭐ 检查这个值
projectData: 3, // ⭐ 检查这个值
calendarData: '✅',
surveyData: '✅'
}
// 7️⃣ 面板已显示
✅ [Employees] 面板已显示
应该看到:
// 8️⃣ 开始转换数据
🔍 [employeeDetailForTeamLeader] 开始转换: {
有employee: true,
activeTab: 'workload',
visible: true
}
// 9️⃣ 转换完成
✅ [employeeDetailForTeamLeader] 转换完成: {
name: '徐福静',
currentProjects: 3, // ⭐ 关键:检查这个值
projectDataLength: 3, // ⭐ 关键:检查这个值
projectNamesLength: 3,
hasCalendarData: true, // ⭐ 关键:应该是 true
calendarDays: 42, // ⭐ 关键:应该是 42
hasSurveyData: true, // ⭐ 关键:如果有问卷应该是 true
surveyCompleted: true,
leaveRecordsLength: 0 // ⭐ 正常:我们没有加载请假数据
}
// 🔟 完整数据结构
📦 [employeeDetailForTeamLeader] 完整数据结构: {
employee: { /* EmployeeFullInfo 对象 */ },
result: { /* EmployeeDetail 对象 */ }
}
currentProjects 为 0症状:
currentProjects: 0,
projectData: 0,
可能原因:
employeeService.getEmployeeWorkload() 返回的数据为空诊断方法:
// 查看项目数据加载日志
✅ [Employees] 项目数据加载完成: {
currentProjects: 0, // ❌ 如果是 0,说明查询结果为空
ongoingProjects: 0,
项目列表: [] // ❌ 如果是空数组,说明没有项目
}
解决方案:
employeeService.getEmployeeWorkload() 的查询逻辑Project 或 ProjectTeam 表calendarData 为 undefined 或 null症状:
hasCalendarData: false,
calendarDays: 0,
可能原因:
buildCalendarData() 方法返回了 undefinedprojects 数组为空诊断方法:
// 查看日历数据生成日志
📅 [Employees] 日历数据生成完成: {
days: 0, // ❌ 如果是 0,说明日历生成失败
有项目的天数: 0
}
解决方案:
buildCalendarData() 方法是否正确返回数据buildCalendarData() 方法wl.ongoingProjects 是否有数据surveyData 为 undefined症状:
hasSurveyData: false,
surveyCompleted: false,
可能原因:
loadEmployeeSurvey() 方法查询失败Profile 表或 SurveyLog 表不存在或无数据诊断方法:
// 查看问卷数据加载日志
📝 [Employees] 问卷数据加载完成: {
completed: false, // ❌ 如果是 false,说明没有完成问卷
answers: 0
}
解决方案:
loadEmployeeSurvey() 方法的查询逻辑Profile 和 SurveyLog 表症状:
❌ [Employees] 加载员工数据失败: Error: ...
可能原因:
解决方案:
检查 employees.ts 的 viewEmployee() 方法:
async viewEmployee(emp: Employee) {
// ... 其他代码 ...
if (emp.roleName === '组员' || emp.roleName === '组长') {
try {
// 1️⃣ 加载项目数据
const wl = await this.employeeService.getEmployeeWorkload(emp.id);
// ⭐ 添加调试日志
console.log(`🔍 [DEBUG] getEmployeeWorkload 返回:`, wl);
console.log(`🔍 [DEBUG] currentProjects:`, wl.currentProjects);
console.log(`🔍 [DEBUG] ongoingProjects:`, wl.ongoingProjects);
// ... 其他代码 ...
} catch (err) {
console.error(`❌ [Employees] 加载员工数据失败:`, err);
// ⭐ 详细输出错误信息
console.error(`❌ [DEBUG] 错误详情:`, {
message: err.message,
stack: err.stack
});
}
}
}
检查 buildCalendarData() 方法:
private buildCalendarData(projects: Array<any>): { currentMonth: Date; days: any[] } {
// ⭐ 添加调试日志
console.log(`🔍 [buildCalendarData] 输入项目数量:`, projects.length);
console.log(`🔍 [buildCalendarData] 项目列表:`, projects.map(p => ({
id: p.id,
name: p.name,
createdAt: p.createdAt,
deadline: p.deadline
})));
// ... 日历生成逻辑 ...
const result = {
currentMonth: now,
days: days
};
// ⭐ 添加调试日志
console.log(`🔍 [buildCalendarData] 输出日历数据:`, {
totalDays: result.days.length,
daysWithProjects: result.days.filter(d => d.projectCount > 0).length,
sampleDay: result.days.find(d => d.projectCount > 0) // 输出一个有项目的日期作为样本
});
return result;
}
检查 loadEmployeeSurvey() 方法:
private async loadEmployeeSurvey(employeeId: string, employeeName: string) {
try {
// ⭐ 添加调试日志
console.log(`🔍 [loadEmployeeSurvey] 开始查询:`, {
employeeId,
employeeName
});
// ... 查询 Profile ...
const profile = profileResults[0];
const surveyCompleted = profile.get('surveyCompleted') || false;
// ⭐ 添加调试日志
console.log(`🔍 [loadEmployeeSurvey] Profile 查询结果:`, {
profileId: profile.id,
surveyCompleted: surveyCompleted
});
if (surveyCompleted) {
// ... 查询 SurveyLog ...
// ⭐ 添加调试日志
console.log(`🔍 [loadEmployeeSurvey] SurveyLog 查询结果:`, {
count: surveyResults.length,
survey: surveyResults[0]
});
}
// ... 其他代码 ...
} catch (error) {
// ⭐ 详细输出错误信息
console.error(`❌ [loadEmployeeSurvey] 查询失败:`, {
employeeId,
employeeName,
error: error.message,
stack: error.stack
});
}
}
使用以下清单逐项检查数据流:
viewEmployee() 方法被正确调用emp.roleName 是 '组员' 或 '组长'employeeService.getEmployeeWorkload() 返回了数据wl.currentProjects 大于 0wl.ongoingProjects 数组不为空buildCalendarData() 返回了正确的日历数据loadEmployeeSurvey() 返回了问卷数据(如果有)this.selectedEmployeeForPanel 被正确赋值selectedEmployeeForPanel.currentProjects 大于 0selectedEmployeeForPanel.projectData 数组不为空selectedEmployeeForPanel.calendarData 不为 undefinedselectedEmployeeForPanel.calendarData.days 数组长度为 42selectedEmployeeForPanel.surveyData 不为 undefined(如果有问卷)employeeDetailForTeamLeader getter 返回了数据employeeDetailForTeamLeader.currentProjects 大于 0employeeDetailForTeamLeader.projectData 数组不为空employeeDetailForTeamLeader.calendarData 不为 undefinedapp-employee-detail-panel 组件接收到了 employeeDetail 输入如果一切正常,应该看到:
🚀 [Employees] 开始打开员工信息面板: 徐福静 (xxxxxxxx)
🔄 [Employees] 预加载员工 xxxxxxxx 的完整数据...
✅ [Employees] 项目数据加载完成: { currentProjects: 3, ongoingProjects: 3, ... }
📅 [Employees] 日历数据生成完成: { days: 42, 有项目的天数: 15 }
📝 [Employees] 问卷数据加载完成: { completed: true, answers: 12 }
🎯 [Employees] 完整数据准备完成,打开面板: { currentProjects: 3, projectData: 3, ... }
✅ [Employees] 面板已显示
🔍 [employeeDetailForTeamLeader] 开始转换: { 有employee: true, ... }
✅ [employeeDetailForTeamLeader] 转换完成: { name: '徐福静', currentProjects: 3, ... }
📦 [employeeDetailForTeamLeader] 完整数据结构: { ... }
请提供以下信息:
📌 建议:按照此指南逐步诊断,找出数据流中断的具体位置!