zy-react-library 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Upload/index.js +24 -10
- package/package.json +1 -1
- package/regular/index.d.ts +6 -1
- package/regular/index.js +5 -0
|
@@ -73,17 +73,31 @@ const Upload = (props) => {
|
|
|
73
73
|
|
|
74
74
|
// 验证图片分辨率
|
|
75
75
|
if (ratioArr.length === 2 && file.type?.startsWith("image/")) {
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
76
|
+
const validateImageResolution = (imageUrl) => {
|
|
77
|
+
const img = new Image();
|
|
78
|
+
img.onload = () => {
|
|
79
|
+
if (img.width !== +ratioArr[0] || img.height !== +ratioArr[1]) {
|
|
80
|
+
message.warning(`只能上传${ratio}分辨率的图片`);
|
|
81
|
+
const filtered = fileList.filter(item => item.uid !== file.uid);
|
|
82
|
+
onChange?.(filtered);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
onChange?.(fileList);
|
|
86
|
+
};
|
|
87
|
+
img.src = imageUrl;
|
|
86
88
|
};
|
|
89
|
+
|
|
90
|
+
// 如果有现成的URL则直接使用,否则使用FileReader读取本地文件
|
|
91
|
+
if (file.url) {
|
|
92
|
+
validateImageResolution(file.url);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const reader = new FileReader();
|
|
96
|
+
reader.onload = (e) => {
|
|
97
|
+
validateImageResolution(e.target.result);
|
|
98
|
+
};
|
|
99
|
+
reader.readAsDataURL(file);
|
|
100
|
+
}
|
|
87
101
|
}
|
|
88
102
|
else {
|
|
89
103
|
onChange?.(fileList);
|
package/package.json
CHANGED
package/regular/index.d.ts
CHANGED
package/regular/index.js
CHANGED