Commit 5302545d authored by 武广's avatar 武广

fix: 外卖商品添加图片校验

parent 4185b9b2
import { PlusOutlined, DeleteOutlined, EyeOutlined } from '@ant-design/icons'; import { PlusOutlined, DeleteOutlined, EyeOutlined } from '@ant-design/icons';
import { Modal, Upload, notification, Spin } from 'antd'; import { Modal, Upload, notification, Spin } from 'antd';
import React, { useState, useEffect, useRef, forwardRef } from 'react'; import React, { useState, useEffect, useRef, forwardRef } from 'react';
import { validImageType } from '@/utils/img.valid';
import lodash from 'lodash'; import lodash from 'lodash';
import { ReactSortable } from 'react-sortablejs'; import { ReactSortable } from 'react-sortablejs';
import ImgCrop from 'antd-img-crop'; import ImgCrop from 'antd-img-crop';
...@@ -92,6 +93,12 @@ const UploadCropImage = forwardRef((props, ref) => { ...@@ -92,6 +93,12 @@ const UploadCropImage = forwardRef((props, ref) => {
warningTip(`[${file.name}] 图片不可以大于2MB`); warningTip(`[${file.name}] 图片不可以大于2MB`);
resolve(null); resolve(null);
} }
const curType = file.name.substr(file.name.lastIndexOf('.') + 1).toLowerCase();
validImageType(file, curType).then(res => {
if (!res) {
warningTip(`[${file.name}] 请上传正确图片!`);
resolve(null);
} else {
getBase64(file, url => { getBase64(file, url => {
const image = new Image(); const image = new Image();
image.addEventListener('load', () => { image.addEventListener('load', () => {
...@@ -108,6 +115,8 @@ const UploadCropImage = forwardRef((props, ref) => { ...@@ -108,6 +115,8 @@ const UploadCropImage = forwardRef((props, ref) => {
}); });
image.src = url; image.src = url;
}); });
}
});
}); });
const CheckImageInfoList = async files => { const CheckImageInfoList = async files => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment