预览文件添加地址前缀

This commit is contained in:
2026-10-13 11:39:21 +08:00
parent 91536b193c
commit 7797b4479d
+18 -13
View File
@@ -5,6 +5,7 @@ import 'vue3-office-preview/lib/style.css'
const props = defineProps(['previewFile',])
const currentOrigin = window.location.origin;
// 判断文件类型
const handleFileType = (type:string) => {
if(type){
@@ -33,37 +34,41 @@ const handleFileType = (type:string) => {
</script>
<template>
<div class="max-h-[70vh] overflow-x-auto rounded-lg border">
<div class="max-h-[70vh] overflow-x-auto rounded-lg border">
<!-- 图片预览 -->
<template v-if="handleFileType(previewFile?.file_type) === 'image'">
<div class="flex items-center justify-center py-2">
<NImage :src="previewFile?.file_url" />
</div>
<div class="flex items-center justify-center py-2">
<NImage :src="currentOrigin + previewFile?.file_url" />
</div>
</template>
<!-- Word 预览 -->
<template v-else-if="handleFileType(previewFile?.file_type) === 'word'">
<VueOfficeDocx :src="previewFile?.file_url" class="w-full items-center" />
<div class="h-[68vh]">
<VueOfficeDocx :src="currentOrigin + previewFile?.file_url" class="w-full items-center" />
</div>
</template>
<!-- Excel 预览 -->
<template v-else-if="handleFileType(previewFile?.file_type) === 'excel'">
<VueOfficeExcel :src="previewFile?.file_url" class="w-full items-center" />
<div class="h-[68vh]">
<VueOfficeExcel :src="currentOrigin + previewFile?.file_url" class="w-full items-center" />
</div>
</template>
<!-- Ppt 预览 -->
<template v-else-if="handleFileType(previewFile?.file_type) === 'ppt'">
<VueOfficePptx :src="previewFile?.file_url" class="w-full items-center" />
<VueOfficePptx :src="currentOrigin + previewFile?.file_url" class="w-full items-center" />
</template>
<!-- PDF 预览 -->
<template v-else-if="handleFileType(previewFile?.file_type) === 'pdf'">
<div class="h-[68vh]">
<PDF :src="previewFile?.file_url" class="w-full h-full items-center" />
</div>
<div class="h-[68vh]">
<PDF :src="currentOrigin + previewFile?.file_url" class="w-full h-full items-center" />
</div>
</template>
<!-- 其他类型文件预览 -->
<template v-else>
<div class="flex items-center justify-center py-2">
<div class="flex items-center justify-center py-2">
<p>暂不支持预览该文件类型</p>
</div>
</div>
</template>
</div>
</div>
</template>