Commit e6cd64cb8584127ee69ef9b8783e7d2a4c5efd76
Merge branch 'perf/upload-file-limit' into 'main_dev'
perf: 优化上传组件可以手动选择更改上传文件类型 See merge request yunteng/thingskit-front!891
Showing
1 changed file
with
11 additions
and
2 deletions
| ... | ... | @@ -9,7 +9,7 @@ |
| 9 | 9 | import { useMessage } from '/@/hooks/web/useMessage'; |
| 10 | 10 | import { computed, ref, unref } from 'vue'; |
| 11 | 11 | import { cloneDeep } from 'lodash-es'; |
| 12 | - import { isFunction, isNumber, isObject } from '/@/utils/is'; | |
| 12 | + import { isFunction, isNumber, isObject, isString } from '/@/utils/is'; | |
| 13 | 13 | import { useDesign } from '/@/hooks/web/useDesign'; |
| 14 | 14 | |
| 15 | 15 | export interface FileItem { |
| ... | ... | @@ -59,10 +59,19 @@ |
| 59 | 59 | ); |
| 60 | 60 | |
| 61 | 61 | const handleBeforeUpload = (file: File, fileList: File[]) => { |
| 62 | - const { beforeUpload } = props; | |
| 62 | + const { beforeUpload, accept } = props; | |
| 63 | 63 | |
| 64 | 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 | 75 | if (file.size > props.maxSize) { |
| 67 | 76 | createMessage.warning(`文件大小超过${Math.floor(props.maxSize / 1024 / 1024)}mb`); |
| 68 | 77 | return false; | ... | ... |