From 846ba61b88228e44aafc6bd7a564d14d391eed56 Mon Sep 17 00:00:00 2001 From: zhonghua Date: Tue, 17 Mar 2026 16:18:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=BA=93:=20=E6=8C=89?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E9=99=90=E5=88=B6=E4=B8=8A=E4=BC=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E3=80=81=E7=A7=BB=E9=99=A4=E6=90=9C=E7=B4=A2=E6=A1=86?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E5=9B=BE=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- .../admin/resources/ResourceListView.vue | 67 ++++++++++++++++--- 1 file changed, 56 insertions(+), 11 deletions(-) diff --git a/reading-platform-frontend/src/views/admin/resources/ResourceListView.vue b/reading-platform-frontend/src/views/admin/resources/ResourceListView.vue index 9ab95b2..3d94616 100644 --- a/reading-platform-frontend/src/views/admin/resources/ResourceListView.vue +++ b/reading-platform-frontend/src/views/admin/resources/ResourceListView.vue @@ -64,11 +64,7 @@
- - - + - 图片 (JPG/PNG) + PPT (PPTX) PDF文档 视频 (MP4) + 图片 (JPG/PNG) 音频 (MP3) - PPT (PPTX) 其他 - + 选择文件
- 支持批量上传,单个文件最大 100MB + {{ uploadFileHint }}
@@ -285,7 +281,6 @@ import { ref, reactive, computed, onMounted } from 'vue'; import { message } from 'ant-design-vue'; import { UploadOutlined, - SearchOutlined, FileTextOutlined, FilePdfOutlined, FilePptOutlined, @@ -370,6 +365,32 @@ const uploadForm = reactive({ tags: [] as string[], }); +/** 根据资源类型返回 a-upload 的 accept 限制 */ +const uploadAcceptTypes = computed(() => { + const map: Record = { + IMAGE: '.jpg,.jpeg,.png,.gif,.webp,.bmp', + PDF: '.pdf', + VIDEO: '.mp4,.webm,.ogg,.mov,.avi,.mkv', + AUDIO: '.mp3,.wav,.ogg,.aac,.flac,.m4a', + PPT: '.ppt,.pptx,.pdf', + OTHER: '', + }; + return map[uploadForm.fileType] ?? ''; +}); + +/** 根据资源类型返回上传提示文案 */ +const uploadFileHint = computed(() => { + const hints: Record = { + IMAGE: '支持 JPG、PNG、GIF、WebP、BMP,单个文件最大 100MB', + PDF: '支持 PDF,单个文件最大 100MB', + VIDEO: '支持 MP4、WebM、OGG、MOV、AVI、MKV,单个文件最大 100MB', + AUDIO: '支持 MP3、WAV、OGG、AAC、FLAC、M4A,单个文件最大 100MB', + PPT: '支持 PPT、PPTX、PDF,单个文件最大 100MB', + OTHER: '支持任意格式,单个文件最大 100MB', + }; + return hints[uploadForm.fileType] ?? '支持批量上传,单个文件最大 100MB'; +}); + const editForm = reactive({ title: '', description: '', @@ -555,10 +576,34 @@ const showUploadModal = () => { }; /** OSS 直传:自定义上传请求 */ +/** 根据资源类型获取允许的扩展名列表 */ +const getAllowedExtensions = (fileType: string): string[] => { + const map: Record = { + IMAGE: ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp'], + PDF: ['pdf'], + VIDEO: ['mp4', 'webm', 'ogg', 'mov', 'avi', 'mkv'], + AUDIO: ['mp3', 'wav', 'ogg', 'aac', 'flac', 'm4a'], + PPT: ['ppt', 'pptx', 'pdf'], + OTHER: [], + }; + return map[fileType] ?? []; +}; + const handleCustomUpload = async (options: any) => { const { file, onSuccess, onError, onProgress } = options; const uploadFile = file instanceof File ? file : (file?.originFileObj ?? file); + // 按资源类型校验扩展名(OTHER 不限制) + const allowed = getAllowedExtensions(uploadForm.fileType); + if (allowed.length > 0) { + const ext = (uploadFile.name?.split('.').pop() ?? '').toLowerCase(); + if (!ext || !allowed.includes(ext)) { + message.error(`当前资源类型仅支持:${allowed.join('、').toUpperCase()},请选择正确格式的文件`); + onError?.(new Error('文件类型不符合所选资源类型')); + return; + } + } + // 校验文件大小(资源库单文件 100MB) const validation = validateFileType(uploadFile, 'RESOURCE'); if (!validation.valid) {