日期: 2025-10-22 11:00
问题: 控制台报错 TypeError: deadline.getTime is not a function,甘特图无法显示真实数据
TypeError: deadline.getTime is not a function
at DesignerService.transformProject (designer.service.ts:219:42)
transformProject 中直接调用 deadline.getTime(),但未验证 deadline 是否为 Date 对象。Parse 查询可能返回:
甘特图设计是正确的:
这就是"设计师排版时间轴"的正确呈现方式。用户看到的"项目数据"是指条形图中的项目名称和截止日期,这是预期行为。
// 修复前
const deadline = project.get?.('deadline') || project.deadline;
const daysLeft = deadline ? Math.ceil((deadline.getTime() - now.getTime()) / ...) : 30;
// 修复后
const deadlineRaw = project.get?.('deadline') || project.deadline;
const deadline = deadlineRaw instanceof Date ? deadlineRaw : (deadlineRaw ? new Date(deadlineRaw) : null);
const daysLeft = deadline ? Math.ceil((deadline.getTime() - now.getTime()) / ...) : 30;
// 修复前
const deadline = project.get('deadline') || new Date();
// 修复后
const deadlineRaw = project.get('deadline');
const deadline = deadlineRaw instanceof Date ? deadlineRaw : (deadlineRaw ? new Date(deadlineRaw) : new Date());
constructor (Line 36-40):
constructor() {
this.cid = localStorage.getItem('company') || '';
console.log('🏢 DesignerService初始化,当前公司ID:', this.cid || '(未设置)');
this.initParse();
}
getProjects (Line 193-227):
async getProjects(): Promise<any[]> {
const Parse = await this.ensureParse();
if (!Parse) {
console.error('❌ Parse未初始化,无法查询项目');
return [];
}
if (!this.cid) {
console.error('❌ 未找到公司ID(localStorage的company字段为空),无法查询项目');
return [];
}
console.log('🔍 开始查询项目,company:', this.cid);
const query = new Parse.Query('Project');
// ... 查询逻辑
console.log(`✅ Parse查询成功,找到 ${projects.length} 个项目`);
if (projects.length === 0) {
console.warn('⚠️ 数据库中没有符合条件的项目数据');
console.warn('💡 提示:请确保Project表中有数据,且company字段=', this.cid);
}
return projects.map((p: any) => this.transformProject(p));
}
刷新页面后,应该看到以下日志:
🏢 DesignerService初始化,当前公司ID: <你的company ID>
✅ DesignerService: FmodeParse 初始化成功
🔍 开始查询项目,company: <你的company ID>
✅ Parse查询成功,找到 X 个项目
说明 localStorage.getItem('company') 为空,需要:
localStorage.company说明数据库中没有符合条件的Project数据,需要:
如果有真实数据,甘特图应该显示:
// 在Parse Dashboard或云函数中执行:
const Project = Parse.Object.extend("Project");
const project = new Project();
project.set("title", "测试项目-现代客厅设计");
project.set("company", "<你的company objectId>");
project.set("status", "进行中");
project.set("currentStage", "modeling");
project.set("deadline", new Date(Date.now() + 7 * 24 * 60 * 60 * 1000)); // 7天后
// 可选:关联设计师
const Profile = Parse.Object.extend("Profile");
const designer = Profile.createWithoutData("<设计师objectId>");
project.set("assignee", designer);
// 可选:设置扩展数据
project.set("data", {
projectType: "soft", // soft=软装, hard=硬装
urgency: "high", // high/medium/low
style: "现代简约"
});
await project.save();
const Profile = Parse.Object.extend("Profile");
const profile = new Profile();
profile.set("name", "张三");
profile.set("company", "<你的company objectId>");
profile.set("roleName", "组员"); // 重要:必须是"组员"角色
profile.set("data", {
tags: {
expertise: {
styles: ["现代简约", "北欧风格"],
skills: ["建模", "渲染"],
spaceTypes: ["客厅", "卧室"]
},
capacity: {
weeklyProjects: 3,
maxConcurrent: 5,
avgDaysPerProject: 10
},
emergency: {
willing: true,
premium: 20,
maxPerWeek: 2
},
history: {
totalProjects: 15,
completionRate: 90,
avgRating: 4.5,
onTimeRate: 85,
excellentCount: 5
},
portfolio: []
}
});
await profile.save();
如果数据库中确实没有数据,系统会自动使用模拟数据(fallback机制),甘特图仍然可以正常显示和测试。
等数据准备好后,刷新页面即可看到真实数据。
src/app/pages/team-leader/services/designer.service.ts - 修复Date处理,添加调试日志src/app/pages/team-leader/dashboard/dashboard.ts - 调用数据服务rules/schemas.md - YSS项目的数据表结构