import React, { useState } from 'react';
import { setProperty } from '@/utils/css';
import { LoadingOutlined, PlusOutlined } from '@ant-design/icons';
import Upload from './Upload';
import styles from './style.less';
function beforeUpload (file) {
const isImage = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/gif';
if (!isImage) {
message.error('请上传 JPG , PNG或GIF 图片!');
}
const isLt10M = file.size / 1024 / 1024 < 10;
if (!isLt10M) {
message.error('图片大小必须小于 10MB!');
}
return isImage && isLt10M;
}
const UploadButton = (props) => (
);
export default (props) => {
const { value, onChange, width = 200, ratio = 1 } = props;
const [loading, setLoading] = useState(false);
const handleChange = info => {
if (info.file.status === 'uploading') {
setLoading(true);
return;
}
if (info.file.status === 'error') {
setLoading(false);
return;
}
if (info.file.status === 'done') {
setLoading(false);
const { url, fileType } = info.file.response;
// console.log('--------方--url-.>', url);
onChange(url);
}
};
const previewUrl = getRealPath ? getRealPath(value) : value;
// console.log('--------previewUrl----->', previewUrl);
React.useEffect(() => {
setProperty('--cust-upload-ratio', ratio);
}, [ratio]);
React.useEffect(() => {
setProperty('--cust-upload-width', `${width}px`);
}, [width]);
// console.log('-----里层----->value,', value);
return (
{value ?
: }
);
}