智能學習計劃生成器應用,專注於幫助用户制定、管理和優化學習計劃。主要功能包括:

  • 智能計劃制定:根據學習目標和時間安排自動生成學習計劃
  • 進度追蹤:實時追蹤學習進度和完成情況
  • 知識點管理:組織和管理學習主題和知識點
  • 學習資源整合:關聯學習資源和參考資料
  • 效率分析:分析學習效率和成果,提供改進建議
  • 時間規劃:智能安排學習時間和休息間隔
  • 學習統計:展示學習時長、進度和成果統計
  • 目標設定:設定學習目標並追蹤完成情況

通過這個示例,可以深入理解ArkTS如何實現複雜的學習管理和智能規劃功能。

2. 代碼邏輯分析

應用採用"目標導向學習規劃"的架構設計:

  1. 智能計劃生成引擎
  • 分析學習目標 → 分解知識點 → 分配學習時間
  • 考慮時間約束 → 優化學習順序 → 生成詳細計劃
  1. 進度管理系統
  • 記錄學習時長 → 更新進度狀態 → 計算完成率
  • 監測學習節奏 → 調整計劃安排 → 保持學習動力
  1. 知識點關聯網絡
  • 建立知識點聯繫 → 優化學習路徑 → 強化知識記憶
  • 識別知識盲點 → 針對性複習 → 提高學習效果
  1. 資源整合機制
  • 關聯學習材料 → 提供參考資源 → 豐富學習內容
  • 整合多種形式 → 適應學習風格 → 提升學習體驗
  1. 效率分析算法
  • 分析學習數據 → 評估學習效率 → 提供改進建議
  • 識別學習模式 → 優化學習策略 → 提高學習成果

完整代碼

@Entry @Component struct LearningPlanGenerator { @State learningPlans: LearningPlan[] = []; @State activePlan: LearningPlan | null = null; @State knowledgeTopics: KnowledgeTopic[] = []; @State learningStats: LearningStatistics = new LearningStatistics(); @State currentView: string = 'dashboard'; @State studyResources: StudyResource[] = []; @State learningGoals: LearningGoal[] = []; @State selectedTopics: string[] = [];

aboutToAppear() { this.loadSampleData(); this.updateLearningStats(); }

build() { Column({ space: 0 }) { this.BuildAppHeader()

if (this.currentView === 'dashboard') {
    this.BuildDashboard()
  } else if (this.currentView === 'planner') {
    this.BuildPlanGenerator()
  } else if (this.currentView === 'progress') {
    this.BuildProgressTracker()
  } else if (this.currentView === 'library') {
    this.BuildKnowledgeLibrary()
  } else if (this.currentView === 'analytics') {
    this.BuildLearningAnalytics()
  }
}
.width('100%')
.height('100%')
.backgroundColor('#F5F7FA')

}

@Builder BuildAppHeader() { Column({ space: 0 }) { Row({ space: 10 }) { Text('📚 學習計劃生成器') .fontSize(20) .fontWeight(FontWeight.Bold) .fontColor('#2D3436') .layoutWeight(1)

Button('🏠')
      .onClick(() => { this.currentView = 'dashboard'; })
      .backgroundColor(this.currentView === 'dashboard' ? '#4A6FA5' : '#FFFFFF')
      .fontColor(this.currentView === 'dashboard' ? '#FFFFFF' : '#666666')
      .borderRadius(20)
      .width(40)
      .height(40)
    
    Button('📅')
      .onClick(() => { this.currentView = 'planner'; })
      .backgroundColor(this.currentView === 'planner' ? '#4A6FA5' : '#FFFFFF')
      .fontColor(this.currentView === 'planner' ? '#FFFFFF' : '#666666')
      .borderRadius(20)
      .width(40)
      .height(40)
    
    Button('📊')
      .onClick(() => { this.currentView = 'progress'; })
      .backgroundColor(this.currentView === 'progress' ? '#4A6FA5' : '#FFFFFF')
      .fontColor(this.currentView === 'progress' ? '#FFFFFF' : '#666666')
      .borderRadius(20)
      .width(40)
      .height(40)
    
    Button('📈')
      .onClick(() => { this.currentView = 'analytics'; })
      .backgroundColor(this.currentView === 'analytics' ? '#4A6FA5' : '#FFFFFF')
      .fontColor(this.currentView === 'analytics' ? '#FFFFFF' : '#666666')
      .borderRadius(20)
      .width(40)
      .height(40)
  }
  .width('100%')
  .padding(15)
  .backgroundColor('#FFFFFF')
  .shadow({ radius: 2, color: '#00000010', offsetX: 0, offsetY: 1 })
}

}

@Builder BuildDashboard() { Scroll() { Column({ space: 25 }) { this.BuildLearningOverview() this.BuildCurrentPlan() this.BuildTodayTasks() this.BuildQuickActions() this.BuildLearningTips() } .width('100%') .padding(20) } .width('100%') .layoutWeight(1) }

@Builder BuildLearningOverview() { Column({ space: 15 }) { Row({ space: 10 }) { Text('學習概覽') .fontSize(20) .fontWeight(FontWeight.Bold) .fontColor('#2D3436') .layoutWeight(1)

Text(`${this.learningStats.totalDays}天`)
      .fontSize(14)
      .fontColor('#666666')
  }
  .width('100%')
  
  Row({ space: 15 }) {
    this.BuildOverviewCard('累計學習', `${this.learningStats.totalHours}小時`, '#4A6FA5', '⏱️')
    this.BuildOverviewCard('完成計劃', `${this.learningStats.completedPlans}個`, '#2E8B57', '✅')
  }
  .width('100%')
  
  Row({ space: 15 }) {
    this.BuildOverviewCard('學習主題', `${this.learningStats.topicsLearned}個`, '#FF6B6B', '📚')
    this.BuildOverviewCard('連續天數', `${this.learningStats.streakDays}天`, '#FFA500', '🔥')
  }
  .width('100%')
}
.width('100%')
.padding(20)
.backgroundColor('#FFFFFF')
.borderRadius(16)
.shadow({ radius: 4, color: '#00000008', offsetX: 0, offsetY: 2 })

}

@Builder BuildOverviewCard(title: string, value: string, color: string, icon: string) { Column({ space: 10 }) { Row({ space: 8 }) { Text(icon) .fontSize(20)

Text(value)
      .fontSize(18)
      .fontWeight(FontWeight.Bold)
      .fontColor('#2D3436')
  }
  
  Text(title)
    .fontSize(12)
    .fontColor('#666666')
    .textAlign(TextAlign.Center)
}
.layoutWeight(1)
.padding(15)
.backgroundColor('#F8F9FA')
.borderRadius(12)

}

@Builder BuildCurrentPlan() { Column({ space: 15 }) { Row({ space: 10 }) { Text('當前學習計劃') .fontSize(18) .fontWeight(FontWeight.Bold) .fontColor('#2D3436') .layoutWeight(1)

if (this.activePlan) {
      Text(`${this.activePlan.progress}%`)
        .fontSize(16)
        .fontColor('#4A6FA5')
        .fontWeight(FontWeight.Medium)
    }
  }
  .width('100%')
  
  if (this.activePlan) {
    Column({ space: 12 }) {
      Row({ space: 8 }) {
        Text('📖')
          .fontSize(16)
        
        Text(this.activePlan.title)
          .fontSize(16)
          .fontColor('#2D3436')
          .layoutWeight(1)
      }
      .width('100%')
      
      Text(this.activePlan.goal)
        .fontSize(14)
        .fontColor('#666666')
        .maxLines(2)
      
      Stack() {
        Rect()
          .width('100%')
          .height(8)
          .fill('#E9ECEF')
          .borderRadius(4)
        
        Rect()
          .width(`${this.activePlan.progress}%`)
          .height(8)
          .fill('#4A6FA5')
          .borderRadius(4)
      }
      .width('100%')
      .height(8)
      
      Row({ space: 10 }) {
        Text(`${this.activePlan.completedHours}/${this.activePlan.totalHours}小時`)
          .fontSize(12)
          .fontColor('#666666')
          .layoutWeight(1)
        
        Button('繼續學習')
          .onClick(() => { this.startStudySession(); })
          .backgroundColor('#4A6FA5')
          .fontColor('#FFFFFF')
          .fontSize(12)
          .borderRadius(6)
          .padding({ left: 12, right: 12 })
          .height(30)
      }
      .width('100%')
    }
    .width('100%')
    .padding(15)
    .backgroundColor('#F8F9FA')
    .borderRadius(12)
  } else {
    Column({ space: 10 }) {
      Text('📚')
        .fontSize(32)
        .opacity(0.3)
      
      Text('暫無活躍計劃')
        .fontSize(14)
        .fontColor('#666666')
      
      Button('創建新計劃')
        .onClick(() => { this.currentView = 'planner'; })
        .backgroundColor('#4A6FA5')
        .fontColor('#FFFFFF')
        .width(120)
        .height(36)
        .margin({ top: 10 })
    }
    .width('100%')
    .height(150)
    .justifyContent(FlexAlign.Center)
  }
}
.width('100%')
.padding(20)
.backgroundColor('#FFFFFF')
.borderRadius(16)
.shadow({ radius: 4, color: '#00000008', offsetX: 0, offsetY: 2 })

}

@Builder BuildTodayTasks() { const todayTasks = this.getTodaySessions();

Column({ space: 15 }) {
  Row({ space: 10 }) {
    Text('今日學習任務')
      .fontSize(18)
      .fontWeight(FontWeight.Bold)
      .fontColor('#2D3436')
      .layoutWeight(1)
    
    if (todayTasks.length > 0) {
      Text(`${this.getCompletedToday()}/${todayTasks.length}`)
        .fontSize(14)
        .fontColor('#666666')
    }
  }
  .width('100%')
  
  if (todayTasks.length > 0) {
    ForEach(todayTasks.slice(0, 3), (session: StudySession) => {
      this.BuildTaskItem(session)
    })
    
    if (todayTasks.length > 3) {
      Text(`還有${todayTasks.length - 3}個任務...`)
        .fontSize(12)
        .fontColor('#666666')
        .textAlign(TextAlign.Center)
        .width('100%')
        .margin({ top: 10 })
    }
  } else {
    Column({ space: 10 }) {
      Text('🎯')
        .fontSize(32)
        .opacity(0.3)
      
      Text('今日無安排')
        .fontSize(14)
        .fontColor('#666666')
      
      Text('休息一下或添加新任務')
        .fontSize(12)
        .fontColor('#999999')
    }
    .width('100%')
    .height(120)
    .justifyContent(FlexAlign.Center)
    .backgroundColor('#F8F9FA')
    .borderRadius(12)
  }
}
.width('100%')
.padding(20)
.backgroundColor('#FFFFFF')
.borderRadius(16)
.shadow({ radius: 4, color: '#00000008', offsetX: 0, offsetY: 2 })

}

@Builder BuildTaskItem(session: StudySession) { const topic = this.getTopicById(session.topicId);

Row({ space: 12 }) {
  Checkbox()
    .select(session.status === 'completed')
    .onChange((checked: boolean) => {
      this.toggleSessionStatus(session.id, checked);
    })
    .selectedColor('#4A6FA5')
    .width(20)
    .height(20)
  
  Column({ space: 4 }) {
    Text(topic ? topic.title : '未知主題')
      .fontSize(14)
      .fontColor(session.status === 'completed' ? '#999999' : '#2D3436')
      .alignSelf(ItemAlign.Start)
      .textDecoration(session.status === 'completed' ? TextDecorationType.LineThrough : TextDecorationType.None)
    
    Row({ space: 8 }) {
      Text(`${session.plannedHours}小時`)
        .fontSize(12)
        .fontColor('#666666')
      
      if (session.status === 'completed') {
        Text('✅ 已完成')
          .fontSize(12)
          .fontColor('#2E8B57')
      }
    }
    .width('100%')
  }
  .layoutWeight(1)
}
.width('100%')
.padding(12)
.backgroundColor(session.status === 'completed' ? '#F0F8F0' : '#F8F9FA')
.borderRadius(10)
.margin({ bottom: 8 })

}

@Builder BuildQuickActions() { Column({ space: 15 }) { Text('快速開始') .fontSize(18) .fontWeight(FontWeight.Bold) .fontColor('#2D3436') .alignSelf(ItemAlign.Start)

Row({ space: 15 }) {
    Button('添加學習任務')
      .onClick(() => { this.addQuickTask(); })
      .backgroundColor('#4A6FA5')
      .fontColor('#FFFFFF')
      .borderRadius(10)
      .layoutWeight(1)
      .height(60)
    
    Button('複習知識點')
      .onClick(() => { this.startReview(); })
      .backgroundColor('#2E8B57')
      .fontColor('#FFFFFF')
      .borderRadius(10)
      .layoutWeight(1)
      .height(60)
  }
  .width('100%')
  
  Row({ space: 15 }) {
    Button('查看資源庫')
      .onClick(() => { this.currentView = 'library'; })
      .backgroundColor('#FF6B6B')
      .fontColor('#FFFFFF')
      .borderRadius(10)
      .layoutWeight(1)
      .height(60)
    
    Button('學習分析')
      .onClick(() => { this.currentView = 'analytics'; })
      .backgroundColor('#FFA500')
      .fontColor('#FFFFFF')
      .borderRadius(10)
      .layoutWeight(1)
      .height(60)
  }
  .width('100%')
}
.width('100%')
.padding(20)
.backgroundColor('#FFFFFF')
.borderRadius(16)
.shadow({ radius: 4, color: '#00000008', offsetX: 0, offsetY: 2 })

}

@Builder BuildLearningTips() { const tip = this.getDailyTip();

Column({ space: 15 }) {
  Row({ space: 10 }) {
    Text('💡')
      .fontSize(18)
    
    Text('學習建議')
      .fontSize(16)
      .fontWeight(FontWeight.Medium)
      .fontColor('#2D3436')
      .layoutWeight(1)
  }
  .width('100%')
  
  Text(tip.content)
    .fontSize(14)
    .fontColor('#666666')
    .lineHeight(20)
  
  if (tip.action) {
    Button(tip.action)
      .onClick(() => { this.applyTip(tip); })
      .backgroundColor('#E8F4FF')
      .fontColor('#4A6FA5')
      .width('100%')
      .height(36)
      .margin({ top: 10 })
      .borderRadius(8)
  }
}
.width('100%')
.padding(20)
.backgroundColor('#FFFFFF')
.borderRadius(16)
.shadow({ radius: 4, color: '#00000008', offsetX: 0, offsetY: 2 })

}

@Builder BuildPlanGenerator() { Column({ space: 25 }) { this.BuildPlanCreationForm() this.BuildSmartRecommendations() this.BuildSchedulePreview() this.BuildResourceAllocation() this.BuildGenerateButton() } .width('100%') .padding(20) }

@Builder BuildPlanCreationForm() { Column({ space: 15 }) { Text('創建新學習計劃') .fontSize(20) .fontWeight(FontWeight.Bold) .fontColor('#2D3436') .margin({ top: 10 })

// 計劃標題
  Column({ space: 8 }) {
    Text('計劃標題')
      .fontSize(14)
      .fontColor('#666666')
      .alignSelf(ItemAlign.Start)
    
    TextInput({ placeholder: '例如:Python編程入門' })
      .width('100%')
      .height(40)
      .backgroundColor('#F8F9FA')
      .borderRadius(8)
      .padding(8)
  }
  .width('100%')
  
  // 學習目標
  Column({ space: 8 }) {
    Text('學習目標')
      .fontSize(14)
      .fontColor('#666666')
      .alignSelf(ItemAlign.Start)
    
    TextInput({ placeholder: '描述你想要達到的目標' })
      .width('100%')
      .height(60)
      .backgroundColor('#F8F9FA')
      .borderRadius(8)
      .padding(8)
  }
  .width('100%')
  
  // 時間安排
  Row({ space: 15 }) {
    Column({ space: 8 }) {
      Text('開始日期')
        .fontSize(14)
        .fontColor('#666666')
        .alignSelf(ItemAlign.Start)
      
      TextInput({ placeholder: 'YYYY-MM-DD' })
        .width('100%')
        .height(40)
        .backgroundColor('#F8F9FA')
        .borderRadius(8)
        .padding(8)
    }
    .layoutWeight(1)
    
    Column({ space: 8 }) {
      Text('結束日期')
        .fontSize(14)
        .fontColor('#666666')
        .alignSelf(ItemAlign.Start)
      
      TextInput({ placeholder: 'YYYY-MM-DD' })
        .width('100%')
        .height(40)
        .backgroundColor('#F8F9FA')
        .borderRadius(8)
        .padding(8)
    }
    .layoutWeight(1)
  }
  .width('100%')
  
  // 每日學習時間
  Column({ space: 8 }) {
    Text('每日學習時間(小時)')
      .fontSize(14)
      .fontColor('#666666')
      .alignSelf(ItemAlign.Start)
    
    Slider({
      value: 1,
      min: 0.5,
      max: 4,
      step: 0.5,
      style: SliderStyle.OutSet
    })
      .width('100%')
      .height(30)
  }
  .width('100%')
}
.width('100%')
.padding(20)
.backgroundColor('#FFFFFF')
.borderRadius(16)
.shadow({ radius: 4, color: '#00000008', offsetX: 0, offsetY: 2 })

}

@Builder BuildSmartRecommendations() { const recommendations = this.generateTopicRecommendations();

Column({ space: 15 }) {
  Row({ space: 10 }) {
    Text('🤖')
      .fontSize(18)
    
    Text('智能推薦主題')
      .fontSize(16)
      .fontWeight(FontWeight.Medium)
      .fontColor('#2D3436')
      .layoutWeight(1)
  }
  .width('100%')
  
  if (recommendations.length > 0) {
    ForEach(recommendations.slice(0, 4), (topic: KnowledgeTopic) => {
      Row({ space: 10 }) {
        Checkbox()
          .select(this.selectedTopics.includes(topic.id))
          .onChange((checked: boolean) => {
            this.toggleTopicSelection(topic.id, checked);
          })
          .selectedColor('#4A6FA5')
          .width(20)
          .height(20)
        
        Column({ space: 4 }) {
          Text(topic.title)
            .fontSize(14)
            .fontColor('#2D3436')
            .alignSelf(ItemAlign.Start)
          
          Row({ space: 8 }) {
            Text(topic.category)
              .fontSize(12)
              .fontColor('#666666')
            
            Text(`${topic.estimatedHours}小時`)
              .fontSize(12)
              .fontColor('#666666')
          }
          .width('100%')
        }
        .layoutWeight(1)
      }
      .width('100%')
      .padding(12)
      .backgroundColor('#F8F9FA')
      .borderRadius(10)
      .margin({ bottom: 8 })
    })
  } else {
    Text('選擇學習目標後生成推薦')
      .fontSize(14)
      .fontColor('#999999')
      .padding(20)
      .backgroundColor('#F8F9FA')
      .borderRadius(12)
      .width('100%')
  }
}
.width('100%')
.padding(20)
.backgroundColor('#FFFFFF')
.borderRadius(16)
.shadow({ radius: 4, color: '#00000008', offsetX: 0, offsetY: 2 })

}

@Builder BuildSchedulePreview() { const preview = this.generateSchedulePreview();

Column({ space: 15 }) {
  Text('時間安排預覽')
    .fontSize(18)
    .fontWeight(FontWeight.Medium)
    .fontColor('#2D3436')
    .alignSelf(ItemAlign.Start)
  
  if (preview.days > 0) {
    Row({ space: 15 }) {
      this.BuildPreviewCard('總天數', `${preview.days}天`, '#4A6FA5')
      this.BuildPreviewCard('總學時', `${preview.totalHours}小時`, '#2E8B57')
    }
    .width('100%')
    
    Row({ space: 15 }) {
      this.BuildPreviewCard('主題數', `${preview.topicCount}個`, '#FF6B6B')
      this.BuildPreviewCard('每日學時', `${preview.dailyHours}小時`, '#FFA500')
    }
    .width('100%')
    
    Text('計劃將自動安排學習時間和休息間隔')
      .fontSize(12)
      .fontColor('#666666')
      .textAlign(TextAlign.Center)
      .width('100%')
      .margin({ top: 10 })
  } else {
    Text('選擇主題後查看時間安排')
      .fontSize(14)
      .fontColor('#999999')
      .padding(20)
      .backgroundColor('#F8F9FA')
      .borderRadius(12)
      .width('100%')
  }
}
.width('100%')
.padding(20)
.backgroundColor('#FFFFFF')
.borderRadius(16)
.shadow({ radius: 4, color: '#00000008', offsetX: 0, offsetY: 2 })

}

@Builder BuildPreviewCard(label: string, value: string, color: string) { Column({ space: 8 }) { Text(value) .fontSize(16) .fontWeight(FontWeight.Bold) .fontColor(color)

Text(label)
    .fontSize(12)
    .fontColor('#666666')
    .textAlign(TextAlign.Center)
}
.layoutWeight(1)
.padding(15)
.backgroundColor('#F8F9FA')
.borderRadius(12)

}

@Builder BuildGenerateButton() { Button('生成學習計劃') .onClick(() => { this.generateLearningPlan(); }) .backgroundColor('#4A6FA5') .fontColor('#FFFFFF') .width('100%') .height(50) .fontSize(16) .fontWeight(FontWeight.Medium) .borderRadius(12) .margin({ top: 10 }) }

// 以下為部分私有方法,因篇幅限制僅展示關鍵部分 private loadSampleData(): void { this.knowledgeTopics = [ { id: '1', title: 'Python基礎語法', category: '編程', difficulty: 1, estimatedHours: 8, prerequisites: [], resources: [] }, { id: '2', title: '數據結構與算法', category: '計算機科學', difficulty: 3, estimatedHours: 20, prerequisites: ['1'], resources: [] }, { id: '3', title: 'Web開發基礎', category: '前端開發', difficulty: 2, estimatedHours: 12, prerequisites: ['1'], resources: [] }, { id: '4', title: '數據庫設計', category: '後端開發', difficulty: 2, estimatedHours: 10, prerequisites: ['1'], resources: [] } ];

this.studyResources = [
  { id: '1', title: 'Python官方文檔', type: '文檔', url: '', topicId: '1' },
  { id: '2', title: '算法圖解', type: '書籍', url: '', topicId: '2' }
];

this.learningGoals = [
  { id: '1', title: '掌握Python編程', description: '能夠獨立完成Python項目', priority: 1, deadline: '2024-03-01' }
];

}

private updateLearningStats(): void { const totalHours = this.learningPlans.reduce((sum, plan) => sum + plan.completedHours, 0); const completedPlans = this.learningPlans.filter(plan => plan.progress === 100).length; const topicsLearned = new Set();

this.learningPlans.forEach(plan => {
  plan.topics.forEach(topic => {
    if (topic.completed) {
      topicsLearned.add(topic.topicId);
    }
  });
});

this.learningStats = {
  totalHours: Math.round(totalHours * 10) / 10,
  completedPlans: completedPlans,
  topicsLearned: topicsLearned.size,
  streakDays: this.calculateStreakDays(),
  totalDays: this.learningPlans.length * 7 // 簡化計算
};

}

private getTodaySessions(): StudySession[] { if (!this.activePlan) return []; const today = new Date().toISOString().split('T')[0]; return this.activePlan.schedule.filter(session => session.date === today); }

private getCompletedToday(): number { return this.getTodaySessions().filter(session => session.status === 'completed').length; }

private getTopicById(topicId: string): KnowledgeTopic | undefined { return this.knowledgeTopics.find(topic => topic.id === topicId); }

private getDailyTip(): LearningTip { const tips = [ { content: '建議採用番茄工作法,每25分鐘學習後休息5分鐘', action: '設置番茄鍾' }, { content: '定期複習已學內容有助於長期記憶', action: '開始複習' }, { content: '保持學習環境整潔可以提高專注力', action: '整理學習空間' } ]; return tips[Math.floor(Math.random() * tips.length)]; }

private generateTopicRecommendations(): KnowledgeTopic[] { // 簡化推薦邏輯 return this.knowledgeTopics.slice(0, 3); }

private generateSchedulePreview(): SchedulePreview { const selectedCount = this.selectedTopics.length; const totalHours = selectedCount * 3; // 簡化計算 const dailyHours = 1.5; // 預設值

return {
  days: Math.ceil(totalHours / dailyHours),
  totalHours: totalHours,
  topicCount: selectedCount,
  dailyHours: dailyHours
};

}

private calculateStreakDays(): number { // 簡化實現:返回示例數據 return 7; }

private startStudySession(): void { console.log('開始學習會話'); }

private toggleSessionStatus(sessionId: string, completed: boolean): void { console.log(更新會話狀態: ${sessionId} -> ${completed ? '完成' : '未完成'}); }

private addQuickTask(): void { console.log('添加快速任務'); }

private startReview(): void { console.log('開始複習'); }

private applyTip(tip: LearningTip): void { console.log(應用建議: ${tip.action}); }

private toggleTopicSelection(topicId: string, selected: boolean): void { if (selected && !this.selectedTopics.includes(topicId)) { this.selectedTopics.push(topicId); } else if (!selected) { this.selectedTopics = this.selectedTopics.filter(id => id !== topicId); } }

private generateLearningPlan(): void { if (this.selectedTopics.length === 0) { console.log('請選擇至少一個學習主題'); return; }

const newPlan: LearningPlan = {
  id: Date.now().toString(),
  title: '新學習計劃',
  goal: '掌握選定主題',
  topics: this.selectedTopics.map(id => ({
    topicId: id,
    title: this.getTopicById(id)?.title || '未知主題',
    completed: false,
    progress: 0
  })),
  schedule: [],
  startDate: new Date().toISOString().split('T')[0],
  endDate: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString().split('T')[0],
  progress: 0,
  totalHours: this.selectedTopics.reduce((sum, id) => {
    const topic = this.getTopicById(id);
    return sum + (topic?.estimatedHours || 0);
  }, 0),
  completedHours: 0
};

this.learningPlans.push(newPlan);
this.activePlan = newPlan;
this.currentView = 'dashboard';
this.updateLearningStats();
console.log('學習計劃已生成');

} }

// 數據模型定義 class LearningPlan { id: string = ''; title: string = ''; goal: string = ''; topics: PlanTopic[] = []; schedule: StudySession[] = []; startDate: string = ''; endDate: string = ''; progress: number = 0; totalHours: number = 0; completedHours: number = 0; }

class KnowledgeTopic { id: string = ''; title: string = ''; category: string = ''; difficulty: number = 1; estimatedHours: number = 2; prerequisites: string[] = []; resources: string[] = []; }

class StudySession { id: string = ''; topicId: string = ''; date: string = ''; plannedHours: number = 1; actualHours: number = 0; status: string = 'planned'; notes: string = ''; }

class LearningGoal { id: string = ''; title: string = ''; description: string = ''; priority: number = 1; deadline: string = ''; }

class LearningStatistics { totalHours: number = 0; completedPlans: number = 0; topicsLearned: number = 0; streakDays: number = 0; totalDays: number = 0; }

class StudyResource { id: string = ''; title: string = ''; type: string = ''; url: string = ''; topicId: string = ''; }

class PlanTopic { topicId: string = ''; title: string = ''; completed: boolean = false; progress: number = 0; }

class LearningTip { content: string = ''; action: string = ''; }

class SchedulePreview { days: number = 0; totalHours: number = 0; topicCount: number = 0; dailyHours: number = 0; }


想入門鴻蒙開發又怕花冤枉錢?別錯過!現在能免費系統學 -- 從 ArkTS 面向對象核心的類和對象、繼承多態,到吃透鴻蒙開發關鍵技能,還能衝刺鴻蒙基礎 +高級開發者證書,更驚喜的是考證成功還送好禮!快加入我的鴻蒙班,一起從入門到精通,班級鏈接:點擊免費進入