| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <div wire:poll.2000ms="checkOcrStatus">
- <div class="bg-white shadow-md rounded-lg p-6">
- <h2 class="text-xl font-semibold text-gray-900 mb-4">上传试卷照片</h2>
- <form wire:submit.prevent="handleSubmit">
- {{-- 图片上传 --}}
- <div class="mb-6">
- <label class="block text-sm font-medium text-gray-700 mb-2">
- 试卷图片 <span class="text-red-500">*</span>
- </label>
- <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">
- <div class="space-y-1 text-center">
- <svg class="mx-auto h-12 w-12 text-gray-400" stroke="currentColor" fill="none" viewBox="0 0 48 48">
- <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" />
- </svg>
- <div class="flex text-sm text-gray-600">
- <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">
- <span>点击上传</span>
- <input id="file-upload" name="file-upload" type="file" class="sr-only" multiple accept="image/*" wire:model="uploadedImages">
- </label>
- <p class="pl-1">或拖拽文件到此处</p>
- </div>
- <p class="text-xs text-gray-500">支持 PNG、JPG、JPEG 格式,最多 10 张图片</p>
- </div>
- </div>
- {{-- 预览图片 --}}
- @if(count($uploadedImages) > 0)
- <div class="mt-4 grid grid-cols-2 md:grid-cols-4 gap-4">
- @foreach($uploadedImages as $index => $image)
- <div class="relative">
- <img src="{{ $image->temporaryUrl() }}" alt="预览" class="h-24 w-full object-cover rounded-md">
- <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">
- ×
- </button>
- </div>
- @endforeach
- </div>
- @endif
- </div>
- {{-- 提交按钮 --}}
- <div class="flex justify-end space-x-3">
- <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">
- 重置
- </button>
- <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">
- <span wire:loading.remove>开始 OCR 识别</span>
- <span wire:loading>上传中...</span>
- </button>
- </div>
- </form>
- </div>
- {{-- OCR状态显示 --}}
- @if($currentOcrRecordId)
- <div class="mt-4
- @if($ocrStatus === 'processing')
- bg-blue-50 border-blue-200
- @elseif($ocrStatus === 'completed')
- bg-green-50 border-green-200
- @elseif($ocrStatus === 'failed')
- bg-red-50 border-red-200
- @else
- bg-gray-50 border-gray-200
- @endif
- border rounded-md p-4">
- <div class="flex items-center">
- @if($ocrStatus === 'processing')
- <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">
- <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
- <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>
- </svg>
- @elseif($ocrStatus === 'completed')
- <svg class="h-5 w-5 text-green-600 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
- </svg>
- @elseif($ocrStatus === 'failed')
- <svg class="h-5 w-5 text-red-600 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
- </svg>
- @endif
- <div class="flex-1">
- @if($ocrStatus === 'processing')
- <p class="text-sm font-medium text-blue-800">正在处理OCR识别...</p>
- <p class="text-xs text-blue-600 mt-1">请稍候,这可能需要几分钟时间</p>
- @elseif($ocrStatus === 'completed')
- <p class="text-sm font-medium text-green-800">OCR识别完成!正在跳转到详情页...</p>
- @elseif($ocrStatus === 'failed')
- <p class="text-sm font-medium text-red-800">OCR识别失败</p>
- <p class="text-xs text-red-600 mt-1">请检查图片质量或稍后重试</p>
- @else
- <p class="text-sm font-medium text-gray-800">等待处理...</p>
- @endif
- </div>
- @if($ocrStatus === 'completed')
- <button type="button" wire:click="checkOcrStatus" class="px-4 py-2 bg-green-600 text-white rounded-md hover:bg-green-700">
- 查看详情
- </button>
- @endif
- </div>
- </div>
- @endif
- </div>
- <script>
- document.addEventListener('livewire:initialized', () => {
- // 处理上传完成事件
- Livewire.on('uploadComplete', (event) => {
- if (event.success) {
- // 清空表单
- @this.resetForm();
- }
- });
- });
- </script>
|