Commit fcb86b7b5f269dedc0f216c1af9345ad51b4c265

Authored by ww
1 parent 1502c978

perf: 优化上传组件可以手动选择更改上传文件类型

... ... @@ -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;
... ...