Ver Fonte

逐步修复 bug——修复权重问题

yemeishu há 1 mês atrás
pai
commit
fcf1a5bba5

+ 36 - 0
database/migrations/2025_11_26_154037_add_answer_verified_to_ocr_question_results.php

@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::table('ocr_question_results', function (Blueprint $table) {
+            // 添加答案验证字段
+            $table->boolean('answer_verified')->nullable()->after('manual_answer')->comment('答案是否已验证');
+
+            // 创建索引
+            $table->index('answer_verified', 'idx_ocr_question_results_answer_verified');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::table('ocr_question_results', function (Blueprint $table) {
+            // 删除索引
+            $table->dropIndex('idx_ocr_question_results_answer_verified');
+
+            // 删除字段
+            $table->dropColumn('answer_verified');
+        });
+    }
+};

+ 19 - 10
resources/views/filament/pages/knowledge-point-detail.blade.php

@@ -305,24 +305,33 @@
                         <p class="text-xs text-gray-500">列表按原始顺序展示,可与上方关系网互相对照。</p>
                     </div>
                     @if(!empty($point['skills']))
-                        <div class="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
-                            @foreach($point['skills'] as $skill)
-                                <div class="rounded-lg border border-gray-200 p-4 dark:border-gray-700">
-                                    <div class="flex items-center justify-between mb-2">
-                                        <h4 class="font-semibold text-sm">{{ $skill['skill_name'] }}</h4>
-                                        <span class="text-xs bg-blue-100 text-blue-800 px-2 py-0.5 rounded">{{ $skill['skill_type'] }}</span>
-                                    </div>
+                        <div class="w-full overflow-hidden">
+                            <div class="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
+                                @foreach($point['skills'] as $skill)
+                                    <div class="rounded-lg border border-gray-200 p-4 dark:border-gray-700 break-words max-w-full">
+                                        <div class="flex items-start justify-between mb-2 gap-2 min-w-0">
+                                            <h4 class="font-semibold text-sm leading-tight truncate">{{ $skill['skill_name'] ?? '未知技能' }}</h4>
+                                            <span class="text-xs bg-blue-100 text-blue-800 px-2 py-0.5 rounded flex-shrink-0 whitespace-nowrap">
+                                                {{ $skill['skill_type'] ?? ($skill['type'] ?? '通用') }}
+                                            </span>
+                                        </div>
                                     <div class="mt-2">
+                                        @php
+                                            // 计算权重百分比,如果权重 > 1 说明它已经是百分比格式(如 5.0 表示 5%)
+                                            $weightValue = $skill['weight'] ?? 0;
+                                            $weightPercentage = $weightValue > 1 ? $weightValue : ($weightValue * 100);
+                                            $weightPercentage = min(100, max(0, $weightPercentage)); // 限制在 0-100 之间
+                                        @endphp
                                         <div class="flex items-center justify-between text-xs text-gray-600 mb-1">
                                             <span>权重</span>
-                                            <span>{{ number_format(($skill['weight'] ?? 0) * 100, 1) }}%</span>
+                                            <span>{{ number_format($weightPercentage, 1) }}%</span>
                                         </div>
                                         <div class="w-full bg-gray-200 rounded-full h-2 dark:bg-gray-700">
-                                            <div class="bg-primary-500 h-2 rounded-full" style="width: {{ ($skill['weight'] ?? 0) * 100 }}%"></div>
+                                            <div class="bg-primary-500 h-2 rounded-full transition-all duration-300" style="width: {{ $weightPercentage }}%"></div>
                                         </div>
                                     </div>
                                     @if(!empty($skill['description']))
-                                        <p class="text-xs text-gray-500 mt-2">{{ Str::limit($skill['description'], 100) }}</p>
+                                        <p class="text-xs text-gray-500 mt-2">{{ Str::limit($skill['description'] ?? '', 100) }}</p>
                                     @endif
                                 </div>
                             @endforeach

+ 40 - 63
resources/views/filament/pages/student-dashboard.blade.php

@@ -19,76 +19,53 @@
             {{-- 选择器区域 --}}
             <div class="bg-gray-50 rounded-lg p-4 border border-gray-200">
                 <div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
-                    <div>
-                        <label for="teacher" class="block text-sm font-medium text-gray-700 mb-2">选择老师</label>
-                        <div class="dropdown w-full">
-                            <label tabindex="0" class="btn btn-bordered w-full justify-between">
-                                @if(!empty($teacherId))
-                                    @php
-                                        $selectedTeacher = collect($this->teachers)->firstWhere('teacher_id', $teacherId);
-                                    @endphp
-                                    {{ $selectedTeacher ? trim($selectedTeacher->name ?? $selectedTeacher->teacher_id) . ($selectedTeacher->subject ? " ({$selectedTeacher->subject})" : '') : '请选择老师...' }}
-                                @else
-                                    请选择老师...
-                                @endif
-                                <svg class="w-4 h-4 ml-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
-                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
-                                </svg>
-                            </label>
-                            <ul tabindex="0" class="dropdown-content menu p-2 shadow bg-base-100 rounded-box w-full max-h-64 overflow-y-auto">
-                                <li>
-                                    <a wire:click="$set('teacherId', '')" class="{{ empty($teacherId) ? 'active' : '' }}">
-                                        请选择老师...
-                                    </a>
-                                </li>
-                                @foreach($this->teachers as $teacher)
-                                    <li>
-                                        <a wire:click="$set('teacherId', '{{ $teacher->teacher_id }}')" class="{{ $teacherId === $teacher->teacher_id ? 'active' : '' }}">
-                                            {{ trim($teacher->name ?? $teacher->teacher_id) . ($teacher->subject ? " ({$teacher->subject})" : '') }}
-                                        </a>
-                                    </li>
-                                @endforeach
-                            </ul>
-                        </div>
-                        <p class="mt-1 text-xs text-gray-500">选择要查看的老师</p>
+                    {{-- 选择老师 --}}
+                    <div class="form-control w-full">
+                        <label class="label">
+                            <span class="label-text font-medium">选择老师</span>
+                        </label>
+                        <select
+                            wire:model.live="teacherId"
+                            class="select select-bordered w-full"
+                        >
+                            <option value="">请选择老师...</option>
+                            @foreach($this->teachers as $teacher)
+                                <option value="{{ $teacher->teacher_id }}">
+                                    {{ trim($teacher->name ?? $teacher->teacher_id) . ($teacher->subject ? " ({$teacher->subject})" : '') }}
+                                </option>
+                            @endforeach
+                        </select>
+                        <label class="label">
+                            <span class="label-text text-xs text-gray-500">选择要查看的老师</span>
+                        </label>
                     </div>
 
-                    <div>
-                        <label for="student" class="block text-sm font-medium text-gray-700 mb-2">选择学生</label>
-                        <div class="dropdown w-full">
-                            <label tabindex="0" class="btn btn-bordered w-full justify-between {{ empty($teacherId) ? 'btn-disabled' : '' }}">
+                    {{-- 选择学生 --}}
+                    <div class="form-control w-full">
+                        <label class="label">
+                            <span class="label-text font-medium">选择学生</span>
+                        </label>
+                        <select
+                            wire:model.live="studentId"
+                            class="select select-bordered w-full"
+                            @if(empty($teacherId)) disabled @endif
+                        >
+                            <option value="">
                                 @if(empty($teacherId))
                                     请先选择老师
-                                @elseif(!empty($studentId))
-                                    @php
-                                        $selectedStudent = collect($this->students)->firstWhere('student_id', $studentId);
-                                    @endphp
-                                    {{ $selectedStudent ? trim($selectedStudent->name ?? $selectedStudent->student_id) . " ({$selectedStudent->grade} - {$selectedStudent->class_name})" : '请选择学生...' }}
                                 @else
                                     请选择学生...
                                 @endif
-                                <svg class="w-4 h-4 ml-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
-                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
-                                </svg>
-                            </label>
-                            @if(!empty($teacherId))
-                                <ul tabindex="0" class="dropdown-content menu p-2 shadow bg-base-100 rounded-box w-full max-h-64 overflow-y-auto">
-                                    <li>
-                                        <a wire:click="$set('studentId', '')" class="{{ empty($studentId) ? 'active' : '' }}">
-                                            请选择学生...
-                                        </a>
-                                    </li>
-                                    @foreach($this->students as $student)
-                                        <li>
-                                            <a wire:click="$set('studentId', '{{ $student->student_id }}')" class="{{ $studentId === $student->student_id ? 'active' : '' }}">
-                                                {{ trim($student->name ?? $student->student_id) . " ({$student->grade} - {$student->class_name})" }}
-                                            </a>
-                                        </li>
-                                    @endforeach
-                                </ul>
-                            @endif
-                        </div>
-                        <p class="mt-1 text-xs text-gray-500">选择要查看的学生</p>
+                            </option>
+                            @foreach($this->students as $student)
+                                <option value="{{ $student->student_id }}">
+                                    {{ trim($student->name ?? $student->student_id) . " ({$student->grade} - {$student->class_name})" }}
+                                </option>
+                            @endforeach
+                        </select>
+                        <label class="label">
+                            <span class="label-text text-xs text-gray-500">选择要查看的学生</span>
+                        </label>
                     </div>
                 </div>
 

+ 1 - 1
routes/api.php

@@ -53,7 +53,7 @@ Route::post('/questions/callback', function () {
         Log::error('Callback processing failed: ' . $e->getMessage());
         return response()->json(['error' => $e->getMessage()], 500);
     }
-})->name('api.questions.callback');
+})->name('api.questions.callback.post');
 
 // 接收OCR题目生成回调
 Route::post('/ocr-question-callback', function () {