feat: 支持pdf预览(原生 浏览器接管)
This commit is contained in:
parent
2dce7718d6
commit
801514dbe3
2
apps/web-antd/src/views/system/oss/constant.ts
Normal file
2
apps/web-antd/src/views/system/oss/constant.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/** 支持的图片列表 */
|
||||||
|
export const supportImageList = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
|
@ -31,7 +31,11 @@ const [BasicModal, modalApi] = useVbenModal({
|
|||||||
title="文件上传"
|
title="文件上传"
|
||||||
>
|
>
|
||||||
<div class="flex flex-col gap-4">
|
<div class="flex flex-col gap-4">
|
||||||
<FileUpload v-model:value="fileList" :enable-drag-upload="true" />
|
<FileUpload
|
||||||
|
v-model:value="fileList"
|
||||||
|
:enable-drag-upload="true"
|
||||||
|
:max-count="3"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</BasicModal>
|
</BasicModal>
|
||||||
</template>
|
</template>
|
||||||
|
@ -31,7 +31,7 @@ const [BasicModal, modalApi] = useVbenModal({
|
|||||||
title="图片上传"
|
title="图片上传"
|
||||||
>
|
>
|
||||||
<div class="flex flex-col gap-4">
|
<div class="flex flex-col gap-4">
|
||||||
<ImageUpload v-model:value="fileList" />
|
<ImageUpload v-model:value="fileList" :max-count="3" />
|
||||||
</div>
|
</div>
|
||||||
</BasicModal>
|
</BasicModal>
|
||||||
</template>
|
</template>
|
||||||
|
@ -33,6 +33,7 @@ import { ossDownload, ossList, ossRemove } from '#/api/system/oss';
|
|||||||
import { calculateFileSize } from '#/utils/file';
|
import { calculateFileSize } from '#/utils/file';
|
||||||
import { downloadByData } from '#/utils/file/download';
|
import { downloadByData } from '#/utils/file/download';
|
||||||
|
|
||||||
|
import { supportImageList } from './constant';
|
||||||
import { columns, querySchema } from './data';
|
import { columns, querySchema } from './data';
|
||||||
import fallbackImageBase64 from './fallback-image.txt?raw';
|
import fallbackImageBase64 from './fallback-image.txt?raw';
|
||||||
import fileUploadModal from './file-upload-modal.vue';
|
import fileUploadModal from './file-upload-modal.vue';
|
||||||
@ -164,10 +165,32 @@ onMounted(async () => {
|
|||||||
preview.value = previewStr === 'true';
|
preview.value = previewStr === 'true';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据拓展名判断是否是图片
|
||||||
|
* @param ext 拓展名
|
||||||
|
*/
|
||||||
function isImageFile(ext: string) {
|
function isImageFile(ext: string) {
|
||||||
const supportList = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
|
return supportImageList.some((item) =>
|
||||||
return supportList.some((item) => ext.toLocaleLowerCase().includes(item));
|
ext.toLocaleLowerCase().includes(item),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否是pdf文件
|
||||||
|
* @param ext 扩展名
|
||||||
|
*/
|
||||||
|
function isPdfFile(ext: string) {
|
||||||
|
return ext.toLocaleLowerCase().includes('pdf');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pdf预览 使用浏览器接管
|
||||||
|
* @param url 文件地址
|
||||||
|
*/
|
||||||
|
function pdfPreview(url: string) {
|
||||||
|
window.open(url);
|
||||||
|
}
|
||||||
|
|
||||||
const [ImageUploadModal, imageUploadApi] = useVbenModal({
|
const [ImageUploadModal, imageUploadApi] = useVbenModal({
|
||||||
connectedComponent: imageUploadModal,
|
connectedComponent: imageUploadModal,
|
||||||
});
|
});
|
||||||
@ -231,6 +254,12 @@ const [FileUploadModal, fileUploadApi] = useVbenModal({
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</Image>
|
</Image>
|
||||||
|
<!-- pdf预览 使用浏览器开新窗口 -->
|
||||||
|
<span
|
||||||
|
v-else-if="preview && isPdfFile(row.url)"
|
||||||
|
class="icon-[vscode-icons--file-type-pdf2] size-10 cursor-pointer"
|
||||||
|
@click.stop="pdfPreview(row.url)"
|
||||||
|
></span>
|
||||||
<span v-else>{{ row.url }}</span>
|
<span v-else>{{ row.url }}</span>
|
||||||
</template>
|
</template>
|
||||||
<template #action="{ row }">
|
<template #action="{ row }">
|
||||||
|
Loading…
Reference in New Issue
Block a user