upload-form.blade.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <div wire:poll.2000ms="checkOcrStatus">
  2. <div class="bg-white shadow-md rounded-lg p-6">
  3. <h2 class="text-xl font-semibold text-gray-900 mb-4">上传试卷照片</h2>
  4. <form wire:submit.prevent="handleSubmit">
  5. {{-- 图片上传 --}}
  6. <div class="mb-6">
  7. <label class="block text-sm font-medium text-gray-700 mb-2">
  8. 试卷图片 <span class="text-red-500">*</span>
  9. </label>
  10. <div class="mt-1 flex justify-center px-6 pt-5 pb-6 border-2 border-gray-300 border-dashed rounded-md hover:border-gray-400 transition-colors">
  11. <div class="space-y-1 text-center">
  12. <svg class="mx-auto h-12 w-12 text-gray-400" stroke="currentColor" fill="none" viewBox="0 0 48 48">
  13. <path d="M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
  14. </svg>
  15. <div class="flex text-sm text-gray-600">
  16. <label for="file-upload" class="relative cursor-pointer bg-white rounded-md font-medium text-blue-600 hover:text-blue-500 focus-within:outline-none focus-within:ring-2 focus-within:ring-offset-2 focus-within:ring-blue-500">
  17. <span>点击上传</span>
  18. <input id="file-upload" name="file-upload" type="file" class="sr-only" multiple accept="image/*" wire:model="uploadedImages">
  19. </label>
  20. <p class="pl-1">或拖拽文件到此处</p>
  21. </div>
  22. <p class="text-xs text-gray-500">支持 PNG、JPG、JPEG 格式,最多 10 张图片</p>
  23. </div>
  24. </div>
  25. {{-- 预览图片 --}}
  26. @if(count($uploadedImages) > 0)
  27. <div class="mt-4 grid grid-cols-2 md:grid-cols-4 gap-4">
  28. @foreach($uploadedImages as $index => $image)
  29. <div class="relative">
  30. <img src="{{ $image->temporaryUrl() }}" alt="预览" class="h-24 w-full object-cover rounded-md">
  31. <button type="button" wire:click="removeImage({{ $index }})" class="absolute top-1 right-1 bg-red-500 text-white rounded-full w-6 h-6 flex items-center justify-center text-xs hover:bg-red-600">
  32. ×
  33. </button>
  34. </div>
  35. @endforeach
  36. </div>
  37. @endif
  38. </div>
  39. {{-- 提交按钮 --}}
  40. <div class="flex justify-end space-x-3">
  41. <button type="button" wire:click="resetForm" class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50 transition-colors">
  42. 重置
  43. </button>
  44. <button type="submit" wire:loading.attr="disabled" class="px-6 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed">
  45. <span wire:loading.remove>开始 OCR 识别</span>
  46. <span wire:loading>上传中...</span>
  47. </button>
  48. </div>
  49. </form>
  50. </div>
  51. {{-- OCR状态显示 --}}
  52. @if($currentOcrRecordId)
  53. <div class="mt-4
  54. @if($ocrStatus === 'processing')
  55. bg-blue-50 border-blue-200
  56. @elseif($ocrStatus === 'completed')
  57. bg-green-50 border-green-200
  58. @elseif($ocrStatus === 'failed')
  59. bg-red-50 border-red-200
  60. @else
  61. bg-gray-50 border-gray-200
  62. @endif
  63. border rounded-md p-4">
  64. <div class="flex items-center">
  65. @if($ocrStatus === 'processing')
  66. <svg class="animate-spin h-5 w-5 text-blue-600 mr-3" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
  67. <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
  68. <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
  69. </svg>
  70. @elseif($ocrStatus === 'completed')
  71. <svg class="h-5 w-5 text-green-600 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  72. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
  73. </svg>
  74. @elseif($ocrStatus === 'failed')
  75. <svg class="h-5 w-5 text-red-600 mr-3" 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. @endif
  79. <div class="flex-1">
  80. @if($ocrStatus === 'processing')
  81. <p class="text-sm font-medium text-blue-800">正在处理OCR识别...</p>
  82. <p class="text-xs text-blue-600 mt-1">请稍候,这可能需要几分钟时间</p>
  83. @elseif($ocrStatus === 'completed')
  84. <p class="text-sm font-medium text-green-800">OCR识别完成!正在跳转到详情页...</p>
  85. @elseif($ocrStatus === 'failed')
  86. <p class="text-sm font-medium text-red-800">OCR识别失败</p>
  87. <p class="text-xs text-red-600 mt-1">请检查图片质量或稍后重试</p>
  88. @else
  89. <p class="text-sm font-medium text-gray-800">等待处理...</p>
  90. @endif
  91. </div>
  92. @if($ocrStatus === 'completed')
  93. <button type="button" wire:click="checkOcrStatus" class="px-4 py-2 bg-green-600 text-white rounded-md hover:bg-green-700">
  94. 查看详情
  95. </button>
  96. @endif
  97. </div>
  98. </div>
  99. @endif
  100. </div>
  101. <script>
  102. document.addEventListener('livewire:initialized', () => {
  103. // 处理上传完成事件
  104. Livewire.on('uploadComplete', (event) => {
  105. if (event.success) {
  106. // 清空表单
  107. @this.resetForm();
  108. }
  109. });
  110. });
  111. </script>