upload-exam-paper.blade.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <x-filament-panels::page>
  2. <div class="space-y-6">
  3. {{-- 模式选择 --}}
  4. <div class="card bg-base-100 shadow-lg border">
  5. <div class="card-body">
  6. <div class="flex gap-4">
  7. <button
  8. wire:click="$set('mode', 'upload')"
  9. class="btn {{ $mode === 'upload' ? 'btn-primary' : 'btn-outline' }}"
  10. >
  11. <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  12. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"></path>
  13. </svg>
  14. 上传卷子照片
  15. </button>
  16. <button
  17. wire:click="$set('mode', 'select_paper')"
  18. class="btn {{ $mode === 'select_paper' ? 'btn-primary' : 'btn-outline' }}"
  19. >
  20. <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  21. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
  22. </svg>
  23. 选择已有试卷打分
  24. </button>
  25. </div>
  26. </div>
  27. </div>
  28. {{-- 上传模式 --}}
  29. @if($mode === 'upload')
  30. <div class="card bg-base-100 shadow-lg border">
  31. <div class="card-body">
  32. <h2 class="card-title text-xl mb-4">
  33. <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  34. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"></path>
  35. </svg>
  36. 上传考试卷子
  37. </h2>
  38. <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
  39. {{-- 左侧:选择老师和学生 --}}
  40. <div class="space-y-4">
  41. {{-- 选择老师 --}}
  42. <div class="form-control w-full">
  43. <label class="label">
  44. <span class="label-text font-medium">选择老师 <span class="text-error">*</span></span>
  45. </label>
  46. <select
  47. wire:model.live="teacherId"
  48. class="select select-bordered w-full"
  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="label">
  61. <span class="label-text font-medium">选择学生 <span class="text-error">*</span></span>
  62. </label>
  63. <select
  64. wire:model.live="studentId"
  65. class="select select-bordered w-full"
  66. @if(empty($teacherId)) disabled @endif
  67. >
  68. <option value="">
  69. @if(empty($teacherId))
  70. 请先选择老师
  71. @else
  72. 请选择学生...
  73. @endif
  74. </option>
  75. @foreach($this->students as $student)
  76. <option value="{{ $student->student_id }}">
  77. {{ trim($student->name ?? $student->student_id) . " ({$student->grade} - {$student->class_name})" }}
  78. </option>
  79. @endforeach
  80. </select>
  81. </div>
  82. </div>
  83. {{-- 右侧:上传图片 --}}
  84. <div class="form-control w-full">
  85. <label class="label">
  86. <span class="label-text font-medium">卷子图片 <span class="text-error">*</span></span>
  87. </label>
  88. @if($uploadedImage)
  89. {{-- 图片预览 --}}
  90. <div class="relative">
  91. <img
  92. src="{{ $uploadedImage->temporaryUrl() }}"
  93. class="w-full h-48 object-cover rounded-lg border"
  94. alt="预览"
  95. >
  96. <button
  97. type="button"
  98. wire:click="removeImage"
  99. class="btn btn-circle btn-sm btn-error absolute top-2 right-2"
  100. >
  101. <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  102. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
  103. </svg>
  104. </button>
  105. </div>
  106. <label class="label">
  107. <span class="label-text-alt text-success">
  108. {{ $uploadedImage->getClientOriginalName() }}
  109. ({{ number_format($uploadedImage->getSize() / 1024, 1) }} KB)
  110. </span>
  111. </label>
  112. @else
  113. {{-- 上传区域 --}}
  114. <div
  115. x-data="{ uploading: false, progress: 0 }"
  116. x-on:livewire-upload-start="uploading = true"
  117. x-on:livewire-upload-finish="uploading = false"
  118. x-on:livewire-upload-error="uploading = false"
  119. x-on:livewire-upload-progress="progress = $event.detail.progress"
  120. class="relative"
  121. >
  122. <input
  123. type="file"
  124. id="uploadedImage"
  125. wire:model.live="uploadedImage"
  126. class="hidden"
  127. accept="image/jpeg,image/png,image/webp"
  128. >
  129. <label
  130. for="uploadedImage"
  131. class="flex flex-col items-center justify-center w-full h-48 border-2 border-dashed rounded-lg cursor-pointer hover:bg-base-200 transition-colors"
  132. x-bind:class="{ 'border-primary bg-primary/5': uploading }"
  133. >
  134. {{-- 上传进度 --}}
  135. <div x-show="uploading" class="flex flex-col items-center justify-center">
  136. <div class="radial-progress text-primary" x-bind:style="'--value:' + progress + '; --size: 5rem; --thickness: 4px;'" role="progressbar">
  137. <span class="text-sm font-bold" x-text="progress + '%'"></span>
  138. </div>
  139. <p class="mt-3 text-base font-semibold text-primary">正在上传...</p>
  140. </div>
  141. {{-- 默认上传提示 --}}
  142. <div x-show="!uploading" class="flex flex-col items-center justify-center pt-5 pb-6">
  143. <svg class="w-10 h-10 mb-3 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  144. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"></path>
  145. </svg>
  146. <p class="mb-2 text-sm text-gray-500">
  147. <span class="font-semibold">点击上传</span> 或拖拽文件
  148. </p>
  149. <p class="text-xs text-gray-400">
  150. 支持 JPG、PNG、WebP (最大 10MB)
  151. </p>
  152. </div>
  153. </label>
  154. </div>
  155. @endif
  156. </div>
  157. </div>
  158. {{-- 提交按钮 --}}
  159. <div class="card-actions justify-end mt-6">
  160. <button
  161. type="button"
  162. wire:click="submitUpload"
  163. class="btn btn-primary"
  164. @if($isUploading) disabled @endif
  165. >
  166. @if($isUploading)
  167. <span class="loading loading-spinner"></span>
  168. 上传中...
  169. @else
  170. <svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  171. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"></path>
  172. </svg>
  173. 上传并识别
  174. @endif
  175. </button>
  176. </div>
  177. </div>
  178. </div>
  179. @endif
  180. {{-- 选择试卷模式 --}}
  181. @if($mode === 'select_paper')
  182. <div class="card bg-base-100 shadow-lg border">
  183. <div class="card-body">
  184. <h2 class="card-title text-xl mb-4">
  185. <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  186. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
  187. </svg>
  188. 选择试卷并打分
  189. </h2>
  190. <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
  191. {{-- 选择老师 --}}
  192. <div class="form-control w-full">
  193. <label class="label">
  194. <span class="label-text font-medium">选择老师 <span class="text-error">*</span></span>
  195. </label>
  196. <select
  197. wire:model.live="teacherId"
  198. class="select select-bordered w-full"
  199. >
  200. <option value="">请选择老师...</option>
  201. @foreach($this->teachers as $teacher)
  202. <option value="{{ $teacher->teacher_id }}">
  203. {{ trim($teacher->name ?? $teacher->teacher_id) . ($teacher->subject ? " ({$teacher->subject})" : '') }}
  204. </option>
  205. @endforeach
  206. </select>
  207. </div>
  208. {{-- 选择学生 --}}
  209. <div class="form-control w-full">
  210. <label class="label">
  211. <span class="label-text font-medium">选择学生 <span class="text-error">*</span></span>
  212. </label>
  213. <select
  214. wire:model.live="studentId"
  215. class="select select-bordered w-full"
  216. @if(empty($teacherId)) disabled @endif
  217. >
  218. <option value="">
  219. @if(empty($teacherId))
  220. 请先选择老师
  221. @else
  222. 请选择学生...
  223. @endif
  224. </option>
  225. @foreach($this->students as $student)
  226. <option value="{{ $student->student_id }}">
  227. {{ trim($student->name ?? $student->student_id) . " ({$student->grade} - {$student->class_name})" }}
  228. </option>
  229. @endforeach
  230. </select>
  231. </div>
  232. </div>
  233. {{-- 试卷类型 --}}
  234. @if(!empty($studentId))
  235. <div class="form-control w-full mt-4">
  236. <label class="label">
  237. <span class="label-text font-medium">试卷形式 <span class="text-error">*</span></span>
  238. </label>
  239. <select
  240. wire:model.live="paperType"
  241. class="select select-bordered w-full"
  242. >
  243. @foreach($this->paperTypes as $value => $label)
  244. <option value="{{ $value }}">{{ $label }}</option>
  245. @endforeach
  246. </select>
  247. </div>
  248. {{-- 选择试卷 --}}
  249. <div class="form-control w-full mt-4">
  250. <label class="label">
  251. <span class="label-text font-medium">选择试卷 <span class="text-error">*</span></span>
  252. </label>
  253. <select
  254. wire:model.live="selectedPaperId"
  255. class="select select-bordered w-full"
  256. >
  257. <option value="">请选择试卷...</option>
  258. @foreach($this->studentPapers as $paper)
  259. <option value="{{ $paper['paper_id'] }}">
  260. {{ $paper['paper_name'] }} ({{ $paper['total_questions'] }}题 / {{ $paper['total_score'] }}分) - {{ $paper['created_at'] }}
  261. </option>
  262. @endforeach
  263. </select>
  264. </div>
  265. @endif
  266. {{-- 题目列表和评分 --}}
  267. @if(!empty($selectedPaperId) && count($this->selectedPaperQuestions) > 0)
  268. <div class="mt-6">
  269. <h3 class="text-lg font-semibold mb-4">题目列表</h3>
  270. <div class="space-y-4">
  271. @foreach($this->selectedPaperQuestions as $question)
  272. <div class="card bg-base-200 border">
  273. <div class="card-body">
  274. <div class="flex items-start justify-between">
  275. <div class="flex-1">
  276. <div class="flex items-center gap-2 mb-2">
  277. <span class="badge badge-primary">第 {{ $question['question_number'] }} 题</span>
  278. <span class="badge badge-outline">{{ $question['question_type'] }}</span>
  279. <span class="text-sm text-gray-500">({{ $question['score'] }}分)</span>
  280. </div>
  281. <div class="prose max-w-none">
  282. @math($question['content'])
  283. </div>
  284. <div class="mt-2 text-sm text-success">
  285. <strong>参考答案:</strong> @math($question['answer'])
  286. </div>
  287. </div>
  288. </div>
  289. {{-- 评分区域 --}}
  290. <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mt-4 pt-4 border-t">
  291. {{-- 学生答案 --}}
  292. <div class="form-control">
  293. <label class="label">
  294. <span class="label-text">学生答案</span>
  295. </label>
  296. <input
  297. type="text"
  298. wire:model="questionGrades.{{ $question['id'] }}.student_answer"
  299. class="input input-bordered input-sm"
  300. placeholder="输入学生答案..."
  301. >
  302. </div>
  303. {{-- 对错判断(选择题/填空题) --}}
  304. @if(in_array($question['question_type'], ['选择题', '填空题']))
  305. <div class="form-control">
  306. <label class="label">
  307. <span class="label-text">对错</span>
  308. </label>
  309. <div class="flex gap-2">
  310. <label class="label cursor-pointer gap-2">
  311. <input
  312. type="radio"
  313. wire:model="questionGrades.{{ $question['id'] }}.is_correct"
  314. value="1"
  315. class="radio radio-success radio-sm"
  316. >
  317. <span class="label-text">正确</span>
  318. </label>
  319. <label class="label cursor-pointer gap-2">
  320. <input
  321. type="radio"
  322. wire:model="questionGrades.{{ $question['id'] }}.is_correct"
  323. value="0"
  324. class="radio radio-error radio-sm"
  325. >
  326. <span class="label-text">错误</span>
  327. </label>
  328. </div>
  329. </div>
  330. @endif
  331. {{-- 评分(计算题/简答题) --}}
  332. @if(in_array($question['question_type'], ['计算题', '简答题', '解答题']))
  333. <div class="form-control">
  334. <label class="label">
  335. <span class="label-text">得分</span>
  336. </label>
  337. <input
  338. type="number"
  339. wire:model="questionGrades.{{ $question['id'] }}.score"
  340. class="input input-bordered input-sm"
  341. min="0"
  342. max="{{ $question['score'] }}"
  343. step="0.5"
  344. placeholder="0-{{ $question['score'] }}"
  345. >
  346. </div>
  347. @endif
  348. </div>
  349. </div>
  350. </div>
  351. @endforeach
  352. </div>
  353. {{-- 提交按钮 --}}
  354. <div class="flex justify-end mt-6">
  355. <button
  356. type="button"
  357. wire:click="submitManualGrading"
  358. class="btn btn-primary"
  359. >
  360. <svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  361. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
  362. </svg>
  363. 提交评分
  364. </button>
  365. </div>
  366. </div>
  367. @endif
  368. </div>
  369. </div>
  370. @endif
  371. {{-- 最近上传记录 --}}
  372. <div class="card bg-base-100 shadow-lg border">
  373. <div class="card-body">
  374. <h2 class="card-title text-lg mb-4">
  375. <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  376. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
  377. </svg>
  378. 最近上传记录
  379. </h2>
  380. @if(count($this->recentRecords) > 0)
  381. <div class="overflow-x-auto">
  382. <table class="table table-zebra">
  383. <thead>
  384. <tr>
  385. <th>学生</th>
  386. <th>文件名</th>
  387. <th>试卷形式</th>
  388. <th>状态</th>
  389. <th>进度</th>
  390. <th>上传时间</th>
  391. </tr>
  392. </thead>
  393. <tbody>
  394. @foreach($this->recentRecords as $record)
  395. <tr
  396. class="hover:bg-base-200 cursor-pointer transition-colors"
  397. onclick="window.location.href='{{
  398. $record['type'] === 'ocr_upload'
  399. ? route('filament.admin.pages.exam-analysis', ['recordId' => $record['record_id']])
  400. : route('filament.admin.pages.exam-analysis', ['paperId' => $record['paper_id']])
  401. }}'"
  402. >
  403. <td>{{ $record['student_name'] ?? '未知' }}</td>
  404. <td class="max-w-xs truncate" title="{{ $record['paper_name'] }}">
  405. <div class="flex items-center gap-2">
  406. @if($record['type'] === 'ocr_upload')
  407. <svg class="w-4 h-4 text-gray-500 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  408. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"></path>
  409. </svg>
  410. @elseif($record['type'] === 'graded_paper')
  411. <svg class="w-4 h-4 text-green-500 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  412. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
  413. </svg>
  414. @else
  415. <svg class="w-4 h-4 text-blue-500 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  416. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
  417. </svg>
  418. @endif
  419. <span>{{ $record['paper_name'] }}</span>
  420. </div>
  421. </td>
  422. <td>
  423. <span class="badge badge-outline">
  424. @if($record['type'] === 'ocr_upload')
  425. @php
  426. $paperTypeLabel = match($record['paper_type']) {
  427. 'unit_test' => '单元测试',
  428. 'midterm' => '期中考试',
  429. 'final' => '期末考试',
  430. 'homework' => '家庭作业',
  431. 'quiz' => '随堂测验',
  432. 'other' => '其他',
  433. default => '未分类',
  434. };
  435. @endphp
  436. {{ $paperTypeLabel }}
  437. @else
  438. {{ $record['paper_type'] }}
  439. @endif
  440. </span>
  441. </td>
  442. <td>
  443. @php
  444. $statusClass = match($record['status']) {
  445. 'pending' => 'badge-ghost',
  446. 'processing' => 'badge-info',
  447. 'completed' => 'badge-success',
  448. 'failed' => 'badge-error',
  449. 'draft' => 'badge-warning',
  450. default => 'badge-ghost',
  451. };
  452. $statusText = match($record['status']) {
  453. 'pending' => '待处理',
  454. 'processing' => '处理中',
  455. 'completed' => '已评分',
  456. 'failed' => '失败',
  457. 'draft' => '草稿',
  458. default => $record['status'],
  459. };
  460. @endphp
  461. <span class="badge {{ $statusClass }}">{{ $statusText }}</span>
  462. </td>
  463. <td>
  464. @if($record['total_questions'] > 0)
  465. @if($record['type'] === 'ocr_upload' && isset($record['processed_questions']))
  466. <progress
  467. class="progress progress-primary w-20"
  468. value="{{ $record['processed_questions'] }}"
  469. max="{{ $record['total_questions'] }}"
  470. ></progress>
  471. <span class="text-xs ml-1">
  472. {{ $record['processed_questions'] }}/{{ $record['total_questions'] }}
  473. </span>
  474. @else
  475. <span class="badge badge-info">
  476. {{ $record['total_questions'] }} 题
  477. </span>
  478. @endif
  479. @else
  480. <span class="text-gray-400">-</span>
  481. @endif
  482. </td>
  483. <td class="text-sm">
  484. {{ $record['created_at'] }}
  485. </td>
  486. </tr>
  487. @endforeach
  488. </tbody>
  489. </table>
  490. </div>
  491. @else
  492. <div class="text-center py-8 text-gray-500">
  493. <svg class="w-12 h-12 mx-auto mb-3 opacity-50" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  494. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 13h6m-3-3v6m5 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
  495. </svg>
  496. <p>暂无上传记录</p>
  497. </div>
  498. @endif
  499. </div>
  500. </div>
  501. </div>
  502. <x-math-render />
  503. </x-filament-panels::page>