提交
This commit is contained in:
1 parent
2df2ef0808
commit
683f14828f
388 files changed
+2738488
-81306
No files matched your search
@@ -13,6 +13,7 @@ export type BxAttachmentItem = {
|
||||
|
||||
const IMAGE_EXT = /\.(png|jpe?g|gif|webp|bmp|svg)$/i
|
||||
const VIDEO_EXT = /\.(mp4|webm|ogg|mov|avi)$/i
|
||||
const PDF_EXT = /\.pdf$/i
|
||||
|
||||
export function isBxImageFile(file: { fileName?: string; fileType?: string }) {
|
||||
const name = String(file.fileName || '').toLowerCase()
|
||||
@@ -26,9 +27,15 @@ export function isBxVideoFile(file: { fileName?: string; fileType?: string }) {
|
||||
return type.startsWith('video/') || VIDEO_EXT.test(name)
|
||||
}
|
||||
|
||||
export function isBxPdfFile(file: { fileName?: string; fileType?: string }) {
|
||||
const name = String(file.fileName || '').toLowerCase()
|
||||
const type = String(file.fileType || '').toLowerCase()
|
||||
return type === 'application/pdf' || type.includes('pdf') || PDF_EXT.test(name)
|
||||
}
|
||||
|
||||
export function canBxPreview(file: BxAttachmentItem) {
|
||||
if (file._uploading) return false
|
||||
return isBxImageFile(file) || isBxVideoFile(file)
|
||||
return isBxImageFile(file) || isBxVideoFile(file) || isBxPdfFile(file)
|
||||
}
|
||||
|
||||
export async function fillBxAttachmentPreviews(
|
||||
@@ -102,6 +109,15 @@ export async function previewBxAttachment(file: BxAttachmentItem) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
await downloadBxAttachment(file)
|
||||
if (isBxPdfFile(file)) {
|
||||
try {
|
||||
const res: any = await attachmentApi.preview(file.id)
|
||||
return { type: 'pdf' as const, url: res.data?.url || '', fileName: file.fileName }
|
||||
} catch (error: any) {
|
||||
ElMessage.error(error?.message || '预览失败')
|
||||
throw error
|
||||
}
|
||||
}
|
||||
ElMessage.warning('该文件类型暂不支持在线预览,请使用下载查看')
|
||||
return null
|
||||
}
|
||||
Reference in new issue
Block a user