refactor: 重构知识库文件上传和处理, 支持 pdf
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
<h3 class="text-sm font-medium text-danger-800 dark:text-danger-200">
|
||||
文档转换失败
|
||||
</h3>
|
||||
<div class="mt-2 text-sm text-danger-700 dark:text-danger-300">
|
||||
<div class="mt-2 text-sm text-danger-700 dark:text-danger-300 space-y-1">
|
||||
<p><strong>文档:</strong>{{ $document->title }}</p>
|
||||
<p><strong>文件名:</strong>{{ $document->file_name }}</p>
|
||||
<p><strong>失败时间:</strong>{{ $document->updated_at->format('Y年m月d日 H:i:s') }}</p>
|
||||
@@ -35,14 +35,14 @@
|
||||
</div>
|
||||
<div class="ml-3 flex-1">
|
||||
<h3 class="text-sm font-medium text-info-800 dark:text-info-200">
|
||||
常见问题及解决方案
|
||||
常见原因
|
||||
</h3>
|
||||
<div class="mt-2 text-sm text-info-700 dark:text-info-300">
|
||||
<ul class="list-disc list-inside space-y-1">
|
||||
<li>如果错误提示无法连接到 Meilisearch,请确保搜索服务正常运行</li>
|
||||
<li>如果错误提示文件损坏或格式不支持,请检查原始文档是否完整</li>
|
||||
<li>如果错误提示超时,可能是文档过大或包含大量图片,请尝试优化文档</li>
|
||||
<li>您可以点击"重试转换"按钮重新尝试转换此文档</li>
|
||||
<li>文件损坏或格式异常</li>
|
||||
<li>PDF 扫描件或纯图片文档无法提取文本内容</li>
|
||||
<li>文档过大或图片过多,请优化后重新上传</li>
|
||||
<li>您可以点击 "重试转换" 按钮重新尝试</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -10,15 +10,17 @@
|
||||
<h3 class="text-base font-semibold text-danger-800 dark:text-danger-200">
|
||||
文档转换失败
|
||||
</h3>
|
||||
<div class="mt-3 text-sm text-danger-700 dark:text-danger-300">
|
||||
<p class="mb-1"><strong>失败时间:</strong>{{ $document->updated_at->format('Y年m月d日 H:i:s') }}</p>
|
||||
<div class="mt-3 text-sm text-danger-700 dark:text-danger-300 space-y-1">
|
||||
<p><strong>文档:</strong>{{ $document->title }}</p>
|
||||
<p><strong>文件名:</strong>{{ $document->file_name }}</p>
|
||||
<p><strong>失败时间:</strong>{{ $document->updated_at->format('Y年m月d日 H:i:s') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h4 class="text-sm font-semibold text-gray-900 dark:text-gray-100 mb-3">错误详情:</h4>
|
||||
<h4 class="text-sm font-semibold text-gray-900 dark:text-gray-100 mb-3">错误信息:</h4>
|
||||
<div class="rounded-lg bg-gray-100 dark:bg-gray-900 p-4 border border-gray-300 dark:border-gray-700">
|
||||
<pre class="text-sm text-gray-800 dark:text-gray-200 whitespace-pre-wrap break-words font-mono leading-relaxed">{{ $document->conversion_error }}</pre>
|
||||
</div>
|
||||
@@ -33,25 +35,21 @@
|
||||
</div>
|
||||
<div class="ml-3 flex-1">
|
||||
<h3 class="text-sm font-semibold text-info-800 dark:text-info-200 mb-2">
|
||||
常见问题及解决方案
|
||||
常见原因
|
||||
</h3>
|
||||
<div class="text-sm text-info-700 dark:text-info-300">
|
||||
<ul class="space-y-2">
|
||||
<li class="flex items-start">
|
||||
<span class="mr-2">•</span>
|
||||
<span><strong>无法连接到 Meilisearch:</strong>请确保搜索服务正常运行,可以联系系统管理员检查服务状态</span>
|
||||
<span><strong>文件损坏或格式异常:</strong>请确认原始文档可以正常打开。</span>
|
||||
</li>
|
||||
<li class="flex items-start">
|
||||
<span class="mr-2">•</span>
|
||||
<span><strong>文件损坏或格式不支持:</strong>请检查原始文档是否完整,确保文件格式为 .doc 或 .docx</span>
|
||||
<span><strong>转换超时:</strong>文档过大或包含大量图片,请尝试拆分或优化后重新上传</span>
|
||||
</li>
|
||||
<li class="flex items-start">
|
||||
<span class="mr-2">•</span>
|
||||
<span><strong>转换超时:</strong>可能是文档过大或包含大量图片,建议优化文档后重新上传</span>
|
||||
</li>
|
||||
<li class="flex items-start">
|
||||
<span class="mr-2">•</span>
|
||||
<span><strong>Pandoc 错误:</strong>文档可能包含不支持的格式或特殊内容,请尝试简化文档格式</span>
|
||||
<span><strong>内容为空:</strong>PDF 扫描件或纯图片文档无法提取文本内容</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -71,7 +69,7 @@
|
||||
下一步操作
|
||||
</h3>
|
||||
<div class="text-sm text-warning-700 dark:text-warning-300">
|
||||
<p>您可以点击页面右上角的 <strong>"重试转换"</strong> 按钮重新尝试转换此文档。如果问题持续存在,请联系系统管理员或尝试重新上传文档。</p>
|
||||
<p>您可以点击页面右上角的 <strong>"重试转换"</strong> 按钮重新尝试。如果问题持续存在,请联系系统管理员或尝试重新上传文档。</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
@php
|
||||
use App\Services\DocumentPreviewService;
|
||||
|
||||
|
||||
$previewService = app(DocumentPreviewService::class);
|
||||
$canPreview = $previewService->canPreview($document);
|
||||
$htmlContent = null;
|
||||
$error = null;
|
||||
|
||||
|
||||
if ($canPreview) {
|
||||
try {
|
||||
$htmlContent = $previewService->convertToHtml($document);
|
||||
@@ -16,30 +16,39 @@
|
||||
@endphp
|
||||
|
||||
<div class="document-preview-container">
|
||||
@if ($error)
|
||||
@if ($document->conversion_status === 'failed')
|
||||
{{-- 转换失败状态由"转换错误信息"区块处理,此处不重复展示 --}}
|
||||
@elseif ($document->conversion_status === 'processing')
|
||||
<div class="rounded-lg bg-gray-50 p-4 text-gray-600 dark:bg-gray-800 dark:text-gray-400">
|
||||
<div class="flex items-center gap-3">
|
||||
<svg class="h-5 w-5 animate-spin" 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>
|
||||
<p>文档正在转换中,请稍后刷新页面查看...</p>
|
||||
</div>
|
||||
</div>
|
||||
@elseif ($document->conversion_status === 'pending')
|
||||
<div class="rounded-lg bg-warning-50 p-4 text-warning-600 dark:bg-warning-400/10 dark:text-warning-400">
|
||||
<div class="flex items-center gap-3">
|
||||
<svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M12 6v6h4.5m4.5 0a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
<p>文档等待转换中...</p>
|
||||
</div>
|
||||
</div>
|
||||
@elseif ($error)
|
||||
<div class="rounded-lg bg-danger-50 p-4 text-danger-600 dark:bg-danger-400/10 dark:text-danger-400">
|
||||
<div class="flex items-center gap-3">
|
||||
<svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z" />
|
||||
</svg>
|
||||
<div>
|
||||
<p class="font-semibold">预览失败</p>
|
||||
<p class="font-semibold">预览加载失败</p>
|
||||
<p class="text-sm">{{ $error }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@elseif (!$canPreview)
|
||||
<div class="rounded-lg bg-warning-50 p-4 text-warning-600 dark:bg-warning-400/10 dark:text-warning-400">
|
||||
<div class="flex items-center gap-3">
|
||||
<svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z" />
|
||||
</svg>
|
||||
<div>
|
||||
<p class="font-semibold">无法预览此文档</p>
|
||||
<p class="text-sm">该文档格式不支持在线预览,请下载后查看。</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@elseif ($htmlContent)
|
||||
<div class="rounded-lg border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-800">
|
||||
<div class="border-b border-gray-200 bg-gray-50 px-4 py-3 dark:border-gray-700 dark:bg-gray-900">
|
||||
@@ -52,64 +61,48 @@
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="max-h-[600px] overflow-y-auto p-6">
|
||||
<div class="prose prose-sm max-w-none dark:prose-invert">
|
||||
{!! $htmlContent !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="border-t border-gray-200 bg-gray-50 px-4 py-3 dark:border-gray-700 dark:bg-gray-900">
|
||||
<p class="text-xs text-gray-500 dark:text-gray-400">
|
||||
提示:这是文档的预览版本,可能与原始格式略有差异。如需查看完整格式,请下载文档。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@else
|
||||
<div class="rounded-lg bg-gray-50 p-4 text-gray-600 dark:bg-gray-800 dark:text-gray-400">
|
||||
<div class="flex items-center gap-3">
|
||||
<svg class="h-5 w-5 animate-spin" 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>
|
||||
<p>正在加载文档预览...</p>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.document-preview-container .prose {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
|
||||
}
|
||||
|
||||
|
||||
.document-preview-container .prose table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 1em 0;
|
||||
}
|
||||
|
||||
|
||||
.document-preview-container .prose table td,
|
||||
.document-preview-container .prose table th {
|
||||
border: 1px solid #e5e7eb;
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
|
||||
.document-preview-container .prose table th {
|
||||
background-color: #f9fafb;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
|
||||
.document-preview-container .prose img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
|
||||
.dark .document-preview-container .prose table td,
|
||||
.dark .document-preview-container .prose table th {
|
||||
border-color: #374151;
|
||||
}
|
||||
|
||||
|
||||
.dark .document-preview-container .prose table th {
|
||||
background-color: #1f2937;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user