ocr-paper-grading.blade.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <x-filament-panels::page>
  2. @push('styles')
  3. <style>
  4. .status-pending { color: #6b7280; }
  5. .status-processing { color: #3b82f6; }
  6. .status-completed { color: #10b981; }
  7. .status-failed { color: #ef4444; }
  8. </style>
  9. @endpush
  10. <div class="space-y-6">
  11. <!-- 上传区域 -->
  12. <div class="bg-white p-6 rounded-lg shadow">
  13. <div class="flex items-center gap-3 mb-6">
  14. <div class="w-12 h-12 {{ $useChatGPT ? 'bg-purple-100' : 'bg-blue-100' }} rounded-xl flex items-center justify-center">
  15. @if($useChatGPT)
  16. <x-heroicon-o-sparkles class="w-6 h-6 text-purple-600" />
  17. @else
  18. <x-heroicon-o-document-plus class="w-6 h-6 text-blue-600" />
  19. @endif
  20. </div>
  21. <div>
  22. <h2 class="text-xl font-bold text-gray-900">
  23. 上传试卷进行{{ $useChatGPT ? 'ChatGPT智能识别' : 'OCR识别' }}
  24. </h2>
  25. <p class="text-sm text-gray-500">
  26. @if($useChatGPT)
  27. 支持JPG、PNG格式图片,ChatGPT将直接识别学生答案
  28. @else
  29. 支持JPG、PNG格式图片
  30. @endif
  31. </p>
  32. </div>
  33. </div>
  34. <div class="space-y-4">
  35. {{-- 选择老师和学生 --}}
  36. <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
  37. {{-- 选择老师 --}}
  38. <div class="form-control w-full">
  39. <label class="block text-sm font-medium text-gray-700 mb-2">
  40. 选择老师 <span class="text-red-500">*</span>
  41. @if($isTeacher ?? false)
  42. <span class="text-green-600 text-xs ml-2">(当前登录)</span>
  43. @endif
  44. </label>
  45. <select
  46. wire:model.live="teacherId"
  47. @if($isTeacher ?? false) disabled @endif
  48. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 @if($isTeacher ?? false) bg-gray-100 @endif"
  49. >
  50. <option value="">请选择老师...</option>
  51. @foreach($this->teachers as $teacher)
  52. <option value="{{ $teacher->teacher_id }}">
  53. {{ trim($teacher->name ?? $teacher->teacher_id) . ($teacher->subject ? " ({$teacher->subject})" : '') }}
  54. </option>
  55. @endforeach
  56. </select>
  57. </div>
  58. {{-- 选择学生 --}}
  59. <div class="form-control w-full">
  60. <label class="block text-sm font-medium text-gray-700 mb-2">选择学生 <span class="text-red-500">*</span></label>
  61. <select
  62. wire:model.live="studentId"
  63. wire:loading.attr="disabled"
  64. @if(empty($teacherId)) disabled @endif
  65. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 @if(empty($teacherId)) bg-gray-100 @endif"
  66. >
  67. <option value="">
  68. @if(empty($teacherId))
  69. 请先选择老师
  70. @else
  71. 请选择学生...
  72. @endif
  73. </option>
  74. @foreach($this->students as $student)
  75. <option value="{{ $student->student_id }}">
  76. {{ trim($student->name ?? $student->student_id) . " ({$student->grade} - {$student->class_name})" }}
  77. </option>
  78. @endforeach
  79. </select>
  80. </div>
  81. </div>
  82. {{-- 选择试卷 --}}
  83. @if(!empty($studentId))
  84. <div class="form-control w-full">
  85. <label class="block text-sm font-medium text-gray-700 mb-2">选择试卷 <span class="text-red-500">*</span></label>
  86. <select
  87. wire:model.live="selectedPaperId"
  88. class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
  89. >
  90. <option value="">请选择试卷...</option>
  91. @foreach($this->studentPapers as $paper)
  92. <option value="{{ $paper['paper_id'] }}">
  93. {{ $paper['paper_name'] }} ({{ $paper['total_questions'] }}题 / {{ $paper['total_score'] }}分) - {{ $paper['created_at'] }}
  94. </option>
  95. @endforeach
  96. </select>
  97. </div>
  98. @endif
  99. {{-- 显示选中的试卷题目 --}}
  100. @if(!empty($selectedPaperId) && count($this->selectedPaperQuestions) > 0)
  101. <div class="p-4 bg-blue-50 border border-blue-200 rounded-lg">
  102. <h3 class="text-sm font-medium text-blue-900 mb-2">选中的试卷题目(共{{ count($this->selectedPaperQuestions) }}题)</h3>
  103. <div class="space-y-2 max-h-40 overflow-y-auto">
  104. @foreach($this->selectedPaperQuestions as $index => $question)
  105. <div class="text-xs text-blue-800">
  106. <span class="font-medium">第{{ $question['question_number'] ?? ($index + 1) }}题:</span>
  107. {{ Str::limit(strip_tags($question['content'] ?? $question['stem'] ?? ''), 80) }}
  108. </div>
  109. @endforeach
  110. </div>
  111. </div>
  112. @endif
  113. {{-- 识别模式选择 --}}
  114. @if(!empty($selectedPaperId))
  115. <div class="p-4 bg-gray-50 border border-gray-200 rounded-lg">
  116. <h3 class="text-sm font-medium text-gray-900 mb-3">选择识别方式</h3>
  117. <div class="flex gap-4">
  118. <label class="flex items-center gap-2 cursor-pointer">
  119. <input
  120. type="radio"
  121. wire:model.live="useChatGPT"
  122. value="0"
  123. class="w-4 h-4 text-blue-600"
  124. />
  125. <span class="text-sm text-gray-700">OCR识别 + AI判分(传统方式)</span>
  126. </label>
  127. <label class="flex items-center gap-2 cursor-pointer">
  128. <input
  129. type="radio"
  130. wire:model.live="useChatGPT"
  131. value="1"
  132. class="w-4 h-4 text-blue-600"
  133. />
  134. <span class="text-sm text-gray-700">ChatGPT智能识别(无需OCR)</span>
  135. </label>
  136. </div>
  137. </div>
  138. @endif
  139. {{-- 上传组件 - 复用同一个UploadForm --}}
  140. @if(!empty($selectedPaperId))
  141. @livewire(\App\Livewire\UploadExam\UploadForm::class, [
  142. 'teacherId' => $teacherId,
  143. 'studentId' => $studentId,
  144. 'selectedPaperId' => $selectedPaperId,
  145. 'mode' => $useChatGPT ? 'chatgpt' : 'ocr'
  146. ], key('upload-form-' . $selectedPaperId . '-' . $useChatGPT))
  147. @endif
  148. </div>
  149. </div>
  150. <!-- 当前处理状态 -->
  151. @if($selectedRecord)
  152. <div class="bg-white p-6 rounded-lg shadow">
  153. <div class="flex items-center gap-3 mb-6">
  154. <div class="w-12 h-12 bg-yellow-100 rounded-xl flex items-center justify-center">
  155. <x-heroicon-o-clock class="w-6 h-6 text-yellow-600" />
  156. </div>
  157. <div>
  158. <h2 class="text-xl font-bold text-gray-900">处理进度</h2>
  159. <p class="text-sm text-gray-500">{{ $selectedRecord->paper_title }}</p>
  160. </div>
  161. </div>
  162. <div class="space-y-4">
  163. <!-- 处理步骤指示器 -->
  164. <div class="flex justify-between items-center">
  165. <div class="flex items-center gap-4">
  166. <div class="flex flex-col items-center">
  167. <div class="w-10 h-10 rounded-full {{ $selectedRecord->status === 'pending' ? 'bg-blue-600' : 'bg-green-500' }} flex items-center justify-center">
  168. <x-heroicon-o-check class="w-5 h-5 text-white" />
  169. </div>
  170. <span class="text-xs mt-1">上传</span>
  171. </div>
  172. <div class="flex flex-col items-center">
  173. <div class="w-10 h-10 rounded-full {{ $selectedRecord->status === 'processing' ? 'bg-blue-600 animate-pulse' : ($selectedRecord->status === 'completed' ? 'bg-green-500' : 'bg-gray-200') }} flex items-center justify-center">
  174. <x-heroicon-o-cpu-chip class="w-5 h-5 {{ in_array($selectedRecord->status, ['processing', 'completed']) ? 'text-white' : 'text-gray-600' }}" />
  175. </div>
  176. <span class="text-xs mt-1">OCR识别</span>
  177. </div>
  178. <div class="flex flex-col items-center">
  179. <div class="w-10 h-10 rounded-full {{ $selectedRecord->status === 'completed' ? 'bg-green-500' : 'bg-gray-200' }} flex items-center justify-center">
  180. <x-heroicon-o-academic-cap class="w-5 h-5 {{ $selectedRecord->status === 'completed' ? 'text-white' : 'text-gray-600' }}" />
  181. </div>
  182. <span class="text-xs mt-1">AI判分</span>
  183. </div>
  184. </div>
  185. <div class="text-right">
  186. <span class="text-sm text-gray-500">状态:</span>
  187. <span class="font-semibold status-{{ $selectedRecord->status }}">
  188. @switch($selectedRecord->status)
  189. @case('pending') 待处理 @break
  190. @case('processing') 处理中 @break
  191. @case('completed') 已完成 @break
  192. @case('failed') 失败 @break
  193. @default 未知
  194. @endswitch
  195. </span>
  196. </div>
  197. </div>
  198. <!-- 处理结果 -->
  199. @if($selectedRecord->status === 'completed' && $selectedRecord->questions->count() > 0)
  200. <div class="mt-6 border-t pt-6">
  201. <h3 class="font-semibold text-gray-900 mb-4">识别结果预览</h3>
  202. <div class="space-y-3">
  203. @foreach($selectedRecord->questions->take(5) as $question)
  204. <div class="flex items-center justify-between p-3 bg-gray-50 rounded">
  205. <div>
  206. <span class="font-medium">第{{ $question->question_number }}题</span>
  207. <span class="text-sm text-gray-600 ml-2">{{ $question->question_type }}</span>
  208. </div>
  209. <div class="text-sm">
  210. <span class="text-gray-600">答案:</span>
  211. <span class="font-medium">{{ $question->student_answer }}</span>
  212. </div>
  213. </div>
  214. @endforeach
  215. @if($selectedRecord->questions->count() > 5)
  216. <p class="text-sm text-gray-500 text-center">...还有 {{ $selectedRecord->questions->count() - 5 }} 道题</p>
  217. @endif
  218. </div>
  219. </div>
  220. <div class="flex justify-end gap-3 mt-6">
  221. <button
  222. wire:click="regrade({{ $selectedRecord->id }})"
  223. class="px-4 py-2 text-blue-600 border border-blue-600 rounded-lg hover:bg-blue-50"
  224. >
  225. 重新判分
  226. </button>
  227. <a
  228. href="/admin/ocr-analysis-view/{{ $selectedRecord->id }}"
  229. class="px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700"
  230. >
  231. 查看详细分析
  232. </a>
  233. </div>
  234. @endif
  235. @if($selectedRecord->status === 'failed')
  236. <div class="mt-4 p-4 bg-red-50 rounded-lg">
  237. <p class="text-red-800 text-sm">{{ $selectedRecord->error_message ?? '处理失败,请重试' }}</p>
  238. </div>
  239. @endif
  240. </div>
  241. </div>
  242. @endif
  243. <!-- 最近记录 -->
  244. <div class="bg-white p-6 rounded-lg shadow">
  245. <h2 class="text-xl font-bold text-gray-900 mb-6">最近处理记录</h2>
  246. <div class="overflow-x-auto">
  247. <table class="w-full">
  248. <thead>
  249. <tr class="border-b border-gray-200">
  250. <th class="text-left py-3 text-sm font-semibold text-gray-600">试卷标题</th>
  251. <th class="text-left py-3 text-sm font-semibold text-gray-600">学生ID</th>
  252. <th class="text-left py-3 text-sm font-semibold text-gray-600">题数</th>
  253. <th class="text-left py-3 text-sm font-semibold text-gray-600">状态</th>
  254. <th class="text-left py-3 text-sm font-semibold text-gray-600">提交时间</th>
  255. <th class="text-left py-3 text-sm font-semibold text-gray-600">操作</th>
  256. </tr>
  257. </thead>
  258. <tbody>
  259. @foreach($this->getRecentRecords() as $record)
  260. <tr class="border-b border-gray-100 hover:bg-gray-50">
  261. <td class="py-3 text-sm text-gray-900">{{ $record->paper_title }}</td>
  262. <td class="py-3 text-sm text-gray-600">{{ $record->user_id }}</td>
  263. <td class="py-3 text-sm text-gray-600">{{ $record->questions->count() }}</td>
  264. <td class="py-3 text-sm">
  265. <span class="px-2 py-1 rounded-full text-xs status-{{ $record->status }}">
  266. @switch($record->status)
  267. @case('pending') 待处理 @break
  268. @case('processing') 处理中 @break
  269. @case('completed') 已完成 @break
  270. @case('failed') 失败 @break
  271. @default 未知
  272. @endswitch
  273. </span>
  274. </td>
  275. <td class="py-3 text-sm text-gray-600">{{ $record->created_at->diffForHumans() }}</td>
  276. <td class="py-3">
  277. <button
  278. wire:click="viewRecord({{ $record->id }})"
  279. class="text-sm text-blue-600 hover:text-blue-700"
  280. >
  281. 查看
  282. </button>
  283. </td>
  284. </tr>
  285. @endforeach
  286. </tbody>
  287. </table>
  288. </div>
  289. </div>
  290. </div>
  291. </x-filament-panels::page>