Showing
1 changed file
with
11 additions
and
2 deletions
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | import { useMessage } from '/@/hooks/web/useMessage'; | 9 | import { useMessage } from '/@/hooks/web/useMessage'; |
10 | import { computed, ref, unref } from 'vue'; | 10 | import { computed, ref, unref } from 'vue'; |
11 | import { cloneDeep } from 'lodash-es'; | 11 | import { cloneDeep } from 'lodash-es'; |
12 | - import { isFunction, isNumber, isObject } from '/@/utils/is'; | 12 | + import { isFunction, isNumber, isObject, isString } from '/@/utils/is'; |
13 | import { useDesign } from '/@/hooks/web/useDesign'; | 13 | import { useDesign } from '/@/hooks/web/useDesign'; |
14 | 14 | ||
15 | export interface FileItem { | 15 | export interface FileItem { |
@@ -59,10 +59,19 @@ | @@ -59,10 +59,19 @@ | ||
59 | ); | 59 | ); |
60 | 60 | ||
61 | const handleBeforeUpload = (file: File, fileList: File[]) => { | 61 | const handleBeforeUpload = (file: File, fileList: File[]) => { |
62 | - const { beforeUpload } = props; | 62 | + const { beforeUpload, accept } = props; |
63 | 63 | ||
64 | if (beforeUpload && isFunction(beforeUpload)) return beforeUpload?.(file, fileList); | 64 | if (beforeUpload && isFunction(beforeUpload)) return beforeUpload?.(file, fileList); |
65 | 65 | ||
66 | + if (accept && isString(accept)) { | ||
67 | + const limitFileSuffix = accept.split(','); | ||
68 | + | ||
69 | + if (limitFileSuffix.length && !limitFileSuffix.some((suffix) => file.name.includes(suffix))) { | ||
70 | + createMessage.warning(`允许上传的文件类型包括${accept}`); | ||
71 | + return false; | ||
72 | + } | ||
73 | + } | ||
74 | + | ||
66 | if (file.size > props.maxSize) { | 75 | if (file.size > props.maxSize) { |
67 | createMessage.warning(`文件大小超过${Math.floor(props.maxSize / 1024 / 1024)}mb`); | 76 | createMessage.warning(`文件大小超过${Math.floor(props.maxSize / 1024 / 1024)}mb`); |
68 | return false; | 77 | return false; |