20251024-calendar-compilation-fix.md 3.6 KB

设计师日历编译错误修复

问题描述

编译时出现以下错误:

Error: app/pages/customer-service/consultation-order/components/designer-calendar/designer-calendar.component.ts:555:21 - error TS2551: Property 'availableDates' does not exist on type 'Designer'. Did you mean 'nextAvailableDate'?

555     return designer.availableDates?.includes(dateStr) ?? false;
                       ~~~~~~~~~~~~~~

原因分析

在实现月历视图时,isDateAvailable() 方法中使用了 designer.availableDates 属性,但这个属性在 Designer 接口中不存在。

Designer 接口定义:

export interface Designer {
  id: string;
  name: string;
  avatar?: string;
  groupId: string;
  groupName: string;
  isLeader: boolean;
  status: 'available' | 'busy' | 'stagnant' | 'overloaded';
  currentProjects: number;
  lastOrderDate?: string;
  idleDays?: number;
  completedThisMonth?: number;
  averageCycle?: number;
  upcomingEvents?: DesignerEvent[];  // ✅ 有这个
  workload?: number;
  nextAvailableDate?: Date;  // ✅ 有这个
  // ❌ 没有 availableDates
}

解决方案

修改 isDateAvailable() 方法的实现逻辑,不再依赖不存在的 availableDates 属性,而是通过设计师的 statusupcomingEvents 来判断:

修改前:

isDateAvailable(designer: Designer, date: Date): boolean {
  const dateStr = this.formatDateString(date);
  return designer.availableDates?.includes(dateStr) ?? false;  // ❌ 错误
}

修改后:

isDateAvailable(designer: Designer, date: Date): boolean {
  // 如果设计师状态是available且该日期没有事件,则认为空闲
  if (designer.status === 'available') {
    const events = this.getDateEvents(designer, date);
    return events.length === 0;
  }
  return false;
}

判断逻辑

新的空闲判断逻辑:

  1. 设计师整体状态为 available - 说明设计师当前是空闲状态
  2. 且该日期没有任何事件 - getDateEvents() 返回空数组

这样的判断更合理:

  • ✅ 使用已有的接口属性
  • ✅ 结合整体状态和具体日期事件
  • ✅ 逻辑清晰易懂

相关方法

其他日期状态判断方法:

isDateReview() - 判断是否对图日

isDateReview(designer: Designer, date: Date): boolean {
  const dateStr = this.formatDateString(date);
  const events = designer.upcomingEvents || [];
  return events.some(e => 
    e.type === 'review' && 
    this.formatDateString(e.date) === dateStr
  );
}

isDateBusy() - 判断是否忙碌

isDateBusy(designer: Designer, date: Date): boolean {
  const events = this.getDateEvents(designer, date);
  return events.some(e => e.type === 'project');
}

修改的文件

  • yss-project/src/app/pages/customer-service/consultation-order/components/designer-calendar/designer-calendar.component.ts
    • 修复 isDateAvailable() 方法实现

编译状态

TypeScript编译通过无Linter错误类型检查通过

测试验证

需要验证的功能:

  • 设计师状态为 available 时,无事件的日期显示✓(绿色空闲标识)
  • 设计师状态为 busy 时,不显示空闲标识
  • 有事件的日期不显示空闲标识
  • 月历视图正常显示
  • 状态指示器正常工作

总结

问题已完全解决。新的实现逻辑更加合理,使用了 Designer 接口中实际存在的属性,并且判断逻辑更清晰:只有当设计师整体状态为空闲,且该日期没有任何安排时,才认为该日期空闲可接单。