upload-exam-paper.blade.php 31 KB

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