Compare commits
2 Commits
32c22478ae
...
043daac375
| Author | SHA1 | Date |
|---|---|---|
|
|
043daac375 | |
|
|
c7cbbb84c6 |
|
|
@ -73,8 +73,8 @@ const Upload = (props) => {
|
|||
|
||||
// 验证图片分辨率
|
||||
if (ratioArr.length === 2 && file.type?.startsWith("image/")) {
|
||||
const validateImageResolution = (imageUrl) => {
|
||||
const img = new Image();
|
||||
img.src = file.url || file.thumbUrl;
|
||||
img.onload = () => {
|
||||
if (img.width !== +ratioArr[0] || img.height !== +ratioArr[1]) {
|
||||
message.warning(`只能上传${ratio}分辨率的图片`);
|
||||
|
|
@ -84,6 +84,20 @@ const Upload = (props) => {
|
|||
}
|
||||
onChange?.(fileList);
|
||||
};
|
||||
img.src = imageUrl;
|
||||
};
|
||||
|
||||
// 如果有现成的URL则直接使用,否则使用FileReader读取本地文件
|
||||
if (file.url) {
|
||||
validateImageResolution(file.url);
|
||||
}
|
||||
else {
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
validateImageResolution(e.target.result);
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
}
|
||||
else {
|
||||
onChange?.(fileList);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "zy-react-library",
|
||||
"private": false,
|
||||
"version": "1.0.8",
|
||||
"version": "1.0.9",
|
||||
"type": "module",
|
||||
"description": "",
|
||||
"author": "LiuJiaNan",
|
||||
|
|
|
|||
Loading…
Reference in New Issue