upload-exam-paper.blade.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. <h2 class="card-title text-xl mb-4">
  7. <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  8. <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>
  9. </svg>
  10. 上传考试卷子
  11. </h2>
  12. <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
  13. {{-- 左侧:选择老师和学生 --}}
  14. <div class="space-y-4">
  15. {{-- 选择老师 --}}
  16. <div class="form-control w-full">
  17. <label class="label">
  18. <span class="label-text font-medium">选择老师 <span class="text-error">*</span></span>
  19. </label>
  20. <select
  21. wire:model.live="teacherId"
  22. class="select select-bordered w-full"
  23. >
  24. <option value="">请选择老师...</option>
  25. @foreach($this->teachers as $teacher)
  26. <option value="{{ $teacher->teacher_id }}">
  27. {{ trim($teacher->name ?? $teacher->teacher_id) . ($teacher->subject ? " ({$teacher->subject})" : '') }}
  28. </option>
  29. @endforeach
  30. </select>
  31. </div>
  32. {{-- 选择学生 --}}
  33. <div class="form-control w-full">
  34. <label class="label">
  35. <span class="label-text font-medium">选择学生 <span class="text-error">*</span></span>
  36. </label>
  37. <select
  38. wire:model.live="studentId"
  39. class="select select-bordered w-full"
  40. @if(empty($teacherId)) disabled @endif
  41. >
  42. <option value="">
  43. @if(empty($teacherId))
  44. 请先选择老师
  45. @else
  46. 请选择学生...
  47. @endif
  48. </option>
  49. @foreach($this->students as $student)
  50. <option value="{{ $student->student_id }}">
  51. {{ trim($student->name ?? $student->student_id) . " ({$student->grade} - {$student->class_name})" }}
  52. </option>
  53. @endforeach
  54. </select>
  55. </div>
  56. </div>
  57. {{-- 右侧:上传图片 --}}
  58. <div class="form-control w-full">
  59. <label class="label">
  60. <span class="label-text font-medium">卷子图片 <span class="text-error">*</span></span>
  61. </label>
  62. @if($uploadedImage)
  63. {{-- 图片预览 --}}
  64. <div class="relative">
  65. <img
  66. src="{{ $uploadedImage->temporaryUrl() }}"
  67. class="w-full h-48 object-cover rounded-lg border"
  68. alt="预览"
  69. >
  70. <button
  71. type="button"
  72. wire:click="removeImage"
  73. class="btn btn-circle btn-sm btn-error absolute top-2 right-2"
  74. >
  75. <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  76. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
  77. </svg>
  78. </button>
  79. </div>
  80. <label class="label">
  81. <span class="label-text-alt text-success">
  82. {{ $uploadedImage->getClientOriginalName() }}
  83. ({{ number_format($uploadedImage->getSize() / 1024, 1) }} KB)
  84. </span>
  85. </label>
  86. @else
  87. {{-- 上传区域 --}}
  88. <div
  89. x-data="{ uploading: false, progress: 0 }"
  90. x-on:livewire-upload-start="uploading = true"
  91. x-on:livewire-upload-finish="uploading = false"
  92. x-on:livewire-upload-error="uploading = false"
  93. x-on:livewire-upload-progress="progress = $event.detail.progress"
  94. class="relative"
  95. >
  96. <input
  97. type="file"
  98. id="uploadedImage"
  99. wire:model.live="uploadedImage"
  100. class="hidden"
  101. accept="image/jpeg,image/png,image/webp"
  102. >
  103. <label
  104. for="uploadedImage"
  105. 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"
  106. x-bind:class="{ 'border-primary bg-primary/5': uploading }"
  107. >
  108. {{-- 上传进度 --}}
  109. <div x-show="uploading" class="flex flex-col items-center justify-center">
  110. <div class="radial-progress text-primary" x-bind:style="'--value:' + progress + '; --size: 5rem; --thickness: 4px;'" role="progressbar">
  111. <span class="text-sm font-bold" x-text="progress + '%'"></span>
  112. </div>
  113. <p class="mt-3 text-base font-semibold text-primary">正在上传...</p>
  114. </div>
  115. {{-- 默认上传提示 --}}
  116. <div x-show="!uploading" class="flex flex-col items-center justify-center pt-5 pb-6">
  117. <svg class="w-10 h-10 mb-3 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  118. <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>
  119. </svg>
  120. <p class="mb-2 text-sm text-gray-500">
  121. <span class="font-semibold">点击上传</span> 或拖拽文件
  122. </p>
  123. <p class="text-xs text-gray-400">
  124. 支持 JPG、PNG、WebP (最大 10MB)
  125. </p>
  126. </div>
  127. </label>
  128. </div>
  129. @endif
  130. </div>
  131. </div>
  132. {{-- 提交按钮 --}}
  133. <div class="card-actions justify-end mt-6">
  134. <button
  135. type="button"
  136. wire:click="submitUpload"
  137. class="btn btn-primary"
  138. @if($isUploading) disabled @endif
  139. >
  140. @if($isUploading)
  141. <span class="loading loading-spinner"></span>
  142. 上传中...
  143. @else
  144. <svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  145. <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>
  146. </svg>
  147. 上传并识别
  148. @endif
  149. </button>
  150. </div>
  151. </div>
  152. </div>
  153. {{-- 最近上传记录 --}}
  154. <div class="card bg-base-100 shadow-lg border">
  155. <div class="card-body">
  156. <h2 class="card-title text-lg mb-4">
  157. <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  158. <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>
  159. </svg>
  160. 最近上传记录
  161. </h2>
  162. @if(count($this->recentRecords) > 0)
  163. <div class="overflow-x-auto">
  164. <table class="table table-zebra">
  165. <thead>
  166. <tr>
  167. <th>学生</th>
  168. <th>文件名</th>
  169. <th>状态</th>
  170. <th>进度</th>
  171. <th>上传时间</th>
  172. </tr>
  173. </thead>
  174. <tbody>
  175. @foreach($this->recentRecords as $record)
  176. <tr
  177. class="hover:bg-base-200 cursor-pointer transition-colors"
  178. onclick="window.location.href='{{ route('filament.admin.resources.ocr-records-legacy.view', ['record' => $record['id']]) }}'"
  179. >
  180. <td>{{ $record['student']['name'] ?? '未知' }}</td>
  181. <td class="max-w-xs truncate">{{ $record['image_filename'] }}</td>
  182. <td>
  183. @php
  184. $statusClass = match($record['status']) {
  185. 'pending' => 'badge-ghost',
  186. 'processing' => 'badge-info',
  187. 'completed' => 'badge-success',
  188. 'failed' => 'badge-error',
  189. default => 'badge-ghost',
  190. };
  191. $statusText = match($record['status']) {
  192. 'pending' => '待处理',
  193. 'processing' => '处理中',
  194. 'completed' => '已完成',
  195. 'failed' => '失败',
  196. default => $record['status'],
  197. };
  198. @endphp
  199. <span class="badge {{ $statusClass }}">{{ $statusText }}</span>
  200. </td>
  201. <td>
  202. @if($record['total_questions'] > 0)
  203. <progress
  204. class="progress progress-primary w-20"
  205. value="{{ $record['processed_questions'] }}"
  206. max="{{ $record['total_questions'] }}"
  207. ></progress>
  208. <span class="text-xs ml-1">
  209. {{ $record['processed_questions'] }}/{{ $record['total_questions'] }}
  210. </span>
  211. @else
  212. <span class="text-gray-400">-</span>
  213. @endif
  214. </td>
  215. <td class="text-sm">
  216. {{ \Carbon\Carbon::parse($record['created_at'])->format('m-d H:i') }}
  217. </td>
  218. </tr>
  219. @endforeach
  220. </tbody>
  221. </table>
  222. </div>
  223. @else
  224. <div class="text-center py-8 text-gray-500">
  225. <svg class="w-12 h-12 mx-auto mb-3 opacity-50" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  226. <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>
  227. </svg>
  228. <p>暂无上传记录</p>
  229. </div>
  230. @endif
  231. </div>
  232. </div>
  233. </div>
  234. </x-filament-panels::page>