diff --git a/src/components/SelectFile/components/select-data.vue b/src/components/SelectFile/components/select-data.vue index 978b38d..ce456f9 100644 --- a/src/components/SelectFile/components/select-data.vue +++ b/src/components/SelectFile/components/select-data.vue @@ -34,9 +34,9 @@ @@ -46,6 +46,19 @@ 上传图片 + + + + 上传文件 + + { const { file } = item; - if (!file.type.startsWith('image') && props.type != 'video') { - message.error('只能选择图片'); - return; - } if (props.type == 'video') { + if (!file.type.startsWith('video')) { + message.error('只能选择视频'); + return; + } if (file.size / 1024 / 1024 > 100) { message.error('大小不能超过 100MB'); return; } + } else if (props.type == 'image') { + if (!file.type.startsWith('image')) { + message.error('只能选择图片'); + return; + } + if (file.size / 1024 / 1024 > 10) { + message.error('大小不能超过 10MB'); + return; + } } else { + // 默认:允许图片/文档等附件 + const isAllowed = + file.type.startsWith('image') || + file.type.startsWith('application') || + file.type.startsWith('text') || + file.type === 'application/octet-stream' || + file.type === ''; + if (!isAllowed) { + message.error('只能选择图片或文件'); + return; + } if (file.size / 1024 / 1024 > 10) { message.error('大小不能超过 10MB'); return; diff --git a/src/components/SelectFile/index.vue b/src/components/SelectFile/index.vue index c0af394..13a6074 100644 --- a/src/components/SelectFile/index.vue +++ b/src/components/SelectFile/index.vue @@ -16,7 +16,16 @@
- + + + {{ item.name || guessNameFromUrl(item.url) }} + @@ -47,7 +56,7 @@ import { PlusOutlined, CloseOutlined, - YoutubeOutlined + FileOutlined } from '@ant-design/icons-vue'; import { ref } from 'vue'; import SelectData from './components/select-data.vue'; @@ -98,6 +107,16 @@ const onDeleteItem = (index: number) => { emit('del', index); }; + + const guessNameFromUrl = (url: string) => { + const cleanUrl = (url?.split('?')[0] ?? '').trim(); + const last = cleanUrl.split('/').pop() || ''; + try { + return decodeURIComponent(last) || url; + } catch { + return last || url; + } + };