| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- namespace App\Filament\Pages;
- use App\Services\LearningAnalyticsService;
- use BackedEnum;
- use Filament\Pages\Page;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Log;
- use UnitEnum;
- use Livewire\Attributes\Layout;
- use Livewire\Attributes\Title;
- class StudentDashboard extends Page
- {
- use \Filament\Pages\Concerns\InteractsWithFormActions;
- protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-chart-bar';
- protected static string|UnitEnum|null $navigationGroup = '学习分析';
- protected static ?string $navigationLabel = '学生仪表板';
- protected static ?int $navigationSort = 1;
- protected ?string $heading = '学生仪表板';
- protected string $view = 'filament.pages.student-dashboard';
- public string $studentId = '';
- public array $dashboardData = [];
- public bool $isLoading = false;
- public string $errorMessage = '';
- public function mount(Request $request): void
- {
- // 从请求中获取学生ID或使用默认值
- $this->studentId = $request->input('student_id', 'student_001');
- }
- public function loadDashboardData(): void
- {
- $this->isLoading = true;
- $this->errorMessage = '';
- try {
- $service = new LearningAnalyticsService();
- // 检查服务健康状态
- if (!$service->checkHealth()) {
- $this->errorMessage = '学习分析系统当前不可用,请稍后重试';
- $this->isLoading = false;
- return;
- }
- // 获取各项数据
- $masteryOverview = $service->getStudentMasteryOverview($this->studentId);
- $skillProficiency = $service->getStudentSkillProficiency($this->studentId);
- $skillSummary = $service->getStudentSkillSummary($this->studentId);
- $predictions = $service->getStudentPredictions($this->studentId, 5);
- $learningPaths = $service->getStudentLearningPaths($this->studentId, 3);
- $predictionAnalytics = $service->getPredictionAnalytics($this->studentId);
- $pathAnalytics = $service->getLearningPathAnalytics($this->studentId);
- $quickPrediction = $service->quickScorePrediction($this->studentId);
- $recommendations = $service->recommendLearningPaths($this->studentId, 3);
- // 组合数据
- $this->dashboardData = [
- 'mastery' => [
- 'overview' => $masteryOverview,
- 'list' => $service->getStudentMasteryList($this->studentId),
- ],
- 'skill' => [
- 'proficiency' => $skillProficiency,
- 'summary' => $skillSummary,
- ],
- 'prediction' => [
- 'list' => $predictions,
- 'analytics' => $predictionAnalytics,
- 'quick' => $quickPrediction,
- ],
- 'learning_path' => [
- 'list' => $learningPaths,
- 'analytics' => $pathAnalytics,
- 'recommendations' => $recommendations,
- ],
- ];
- } catch (\Exception $e) {
- $this->errorMessage = '加载数据时发生错误:' . $e->getMessage();
- Log::error('学生仪表板数据加载失败', [
- 'student_id' => $this->studentId,
- 'error' => $e->getMessage()
- ]);
- } finally {
- $this->isLoading = false;
- }
- }
- public function updatedStudentId(): void
- {
- // 学生ID更新后自动刷新数据
- $this->loadDashboardData();
- }
- public function recalculateMastery(string $kpCode): void
- {
- try {
- $service = new LearningAnalyticsService();
- $result = $service->recalculateMastery($this->studentId, $kpCode);
- if ($result) {
- $this->dispatch('notify', message: '掌握度重新计算完成', type: 'success');
- $this->loadDashboardData(); // 刷新数据
- } else {
- $this->dispatch('notify', message: '掌握度重新计算失败', type: 'danger');
- }
- } catch (\Exception $e) {
- Log::error('重新计算掌握度失败', [
- 'student_id' => $this->studentId,
- 'kp_code' => $kpCode,
- 'error' => $e->getMessage()
- ]);
- $this->dispatch('notify', message: '操作失败:' . $e->getMessage(), type: 'danger');
- }
- }
- public function batchUpdateSkills(): void
- {
- try {
- $service = new LearningAnalyticsService();
- $result = $service->batchUpdateSkillProficiency($this->studentId);
- if ($result) {
- $this->dispatch('notify', message: '技能熟练度更新完成', type: 'success');
- $this->loadDashboardData(); // 刷新数据
- } else {
- $this->dispatch('notify', message: '技能熟练度更新失败', type: 'danger');
- }
- } catch (\Exception $e) {
- Log::error('批量更新技能熟练度失败', [
- 'student_id' => $this->studentId,
- 'error' => $e->getMessage()
- ]);
- $this->dispatch('notify', message: '操作失败:' . $e->getMessage(), type: 'danger');
- }
- }
- public function generateQuickPrediction(): void
- {
- try {
- $service = new LearningAnalyticsService();
- $result = $service->quickScorePrediction($this->studentId);
- if ($result) {
- $this->dispatch('notify', message: '快速预测生成完成', type: 'success');
- $this->loadDashboardData(); // 刷新数据
- } else {
- $this->dispatch('notify', message: '快速预测生成失败', type: 'danger');
- }
- } catch (\Exception $e) {
- Log::error('生成快速预测失败', [
- 'student_id' => $this->studentId,
- 'error' => $e->getMessage()
- ]);
- $this->dispatch('notify', message: '操作失败:' . $e->getMessage(), type: 'danger');
- }
- }
- }
|