|
|
@@ -46,12 +46,14 @@
|
|
|
>
|
|
|
<div v-loading="previewLoading" class="preview-container">
|
|
|
<iframe
|
|
|
- v-if="previewIframeUrl && !previewLoading"
|
|
|
+ v-if="previewIframeUrl"
|
|
|
:src="previewIframeUrl"
|
|
|
class="preview-iframe"
|
|
|
frameborder="0"
|
|
|
+ @load="previewLoading = false"
|
|
|
+ @error="previewLoading = false"
|
|
|
></iframe>
|
|
|
- <el-empty v-if="!previewIframeUrl && !previewLoading" description="无法预览此文档" />
|
|
|
+ <el-empty v-if="!previewIframeUrl" description="无法预览此文档" />
|
|
|
</div>
|
|
|
</el-dialog>
|
|
|
</div>
|
|
|
@@ -365,33 +367,12 @@ async function handlePreview(item: any) {
|
|
|
previewLoading.value = true
|
|
|
previewVisible.value = true
|
|
|
|
|
|
- const url = `/api/v1/retrieval/files/preview?file_url=${encodeURIComponent(item.file_url)}`
|
|
|
-
|
|
|
- try {
|
|
|
- const resp = await fetch(url)
|
|
|
- if (!resp.ok) {
|
|
|
- const err = await resp.json().catch(() => ({}))
|
|
|
- throw new Error(err.message || `预览失败 (${resp.status})`)
|
|
|
- }
|
|
|
-
|
|
|
- const contentType = resp.headers.get('content-type') || 'application/pdf'
|
|
|
- const arrayBuffer = await resp.arrayBuffer()
|
|
|
- const blob = new Blob([arrayBuffer], { type: contentType })
|
|
|
- const blobUrl = URL.createObjectURL(blob)
|
|
|
- previewIframeUrl.value = blobUrl
|
|
|
- } catch (e: any) {
|
|
|
- ElMessage.error(e.message || '预览失败')
|
|
|
- previewVisible.value = false
|
|
|
- } finally {
|
|
|
- previewLoading.value = false
|
|
|
- }
|
|
|
+ // 直接把后端预览接口当做 iframe 的 src,浏览器原生渲染 PDF
|
|
|
+ previewIframeUrl.value = `/api/v1/retrieval/files/preview?file_url=${encodeURIComponent(item.file_url)}`
|
|
|
}
|
|
|
|
|
|
function closePreview() {
|
|
|
previewVisible.value = false
|
|
|
- if (previewIframeUrl.value) {
|
|
|
- URL.revokeObjectURL(previewIframeUrl.value)
|
|
|
- }
|
|
|
previewIframeUrl.value = ''
|
|
|
}
|
|
|
|
|
|
@@ -484,7 +465,6 @@ async function doSearch() {
|
|
|
const data = res.data
|
|
|
if (data) {
|
|
|
results.value = data.objs || []
|
|
|
- // 使用外部 API 返回的 total_count
|
|
|
totalCount.value = data.total_count || 0
|
|
|
} else {
|
|
|
results.value = []
|