提交 a0f43900 作者: 龚洪江

修复:上传文件类型错误提示

上级 6fd901d8
...@@ -4,6 +4,7 @@ import { CommonAPI } from '~/api'; ...@@ -4,6 +4,7 @@ import { CommonAPI } from '~/api';
import './index.scss'; import './index.scss';
import Viewer from '~/components/viewer'; import Viewer from '~/components/viewer';
import saveAs from 'file-saver'; import saveAs from 'file-saver';
import { fileTypeList } from '~/utils/dictionary';
interface PropsType { interface PropsType {
listType?: 'text' | 'picture' | 'picture-card'; // 上传列表的内建样式 listType?: 'text' | 'picture' | 'picture-card'; // 上传列表的内建样式
...@@ -58,9 +59,7 @@ export const Uploader: React.FC<PropsType> = (props) => { ...@@ -58,9 +59,7 @@ export const Uploader: React.FC<PropsType> = (props) => {
const isType = fileType?.includes(res.type); const isType = fileType?.includes(res.type);
const isSize = res.size / 1024 / 1024 < (fileSize || 2); const isSize = res.size / 1024 / 1024 < (fileSize || 2);
if (!isType) { if (!isType) {
message message.error(`请上传${getFileTypeStr()}格式的文件!`).then();
.error(`请上传${fileType.join('、').replace(/image\/|video\//g, '')}格式的文件!`)
.then();
return isType; return isType;
} }
if (!isSize) { if (!isSize) {
...@@ -125,6 +124,13 @@ export const Uploader: React.FC<PropsType> = (props) => { ...@@ -125,6 +124,13 @@ export const Uploader: React.FC<PropsType> = (props) => {
} }
}, },
}; };
// 获取文件类型提示
const getFileTypeStr = () =>
fileType
.map((v) => fileTypeList.find((i) => i.value === v)?.label)
.filter((v) => !!v)
.join(',');
useEffect(() => { useEffect(() => {
// 如果有默认文件列表 // 如果有默认文件列表
if (defaultFileList?.length) { if (defaultFileList?.length) {
......
...@@ -124,3 +124,66 @@ export const contractStatusList = [ ...@@ -124,3 +124,66 @@ export const contractStatusList = [
value: 5, value: 5,
}, },
]; ];
// 文件字典
export const fileTypeList = [
{
label: 'png',
value: 'image/png',
},
{
label: 'jpeg',
value: 'image/jpeg',
},
{
label: 'jpg',
value: 'image/jpg',
},
{
label: 'gif',
value: 'image/gif',
},
{
label: 'mp4',
value: 'video/mp4',
},
{
label: 'avi',
value: 'video/avi',
},
{
label: 'wmv',
value: 'video/wmv',
},
{
label: 'rmvb',
value: 'video/rmvb',
},
{
label: 'doc',
value: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
},
{
label: 'doc',
value: 'application/msword',
},
{
label: 'excel',
value: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
},
{
label: 'excel',
value: 'application/vnd.ms-excel',
},
{
label: 'pdf',
value: 'application/pdf',
},
{
label: 'ppt',
value: 'application/vnd.ms-powerpoint',
},
{
label: 'ppt',
value: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
},
];
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论