|
@@ -326,17 +326,7 @@ type DfUploadCropProp = Partial<SelectImageProps> & {
|
|
|
}
|
|
|
export const DfUploadCrop = ({ type, caseId, onClose, onSave }: DfUploadCropProp) => {
|
|
|
const onUpload: UploadProps['beforeUpload'] = async file => {
|
|
|
- const filename = file.name
|
|
|
-
|
|
|
- const ext = filename.substring(filename.lastIndexOf('.'))
|
|
|
- const isImg = ['.png', '.jpg'].includes(ext.toLocaleLowerCase())
|
|
|
- if (!isImg) {
|
|
|
- message.error('只能上传png或jpg文件')
|
|
|
- return Upload.LIST_IGNORE
|
|
|
- } else if (file.size > 100 * 1024 * 1024) {
|
|
|
- message.error('大小在100MB以内')
|
|
|
- return Upload.LIST_IGNORE
|
|
|
- }
|
|
|
+
|
|
|
const img = new Image();
|
|
|
img.src = URL.createObjectURL(file);
|
|
|
await new Promise(resolve => {
|
|
@@ -352,8 +342,25 @@ export const DfUploadCrop = ({ type, caseId, onClose, onSave }: DfUploadCropProp
|
|
|
return Upload.LIST_IGNORE
|
|
|
}
|
|
|
|
|
|
+ const beforeCrop = (file: File) => {
|
|
|
+ const filename = file.name
|
|
|
+
|
|
|
+ const ext = filename.substring(filename.lastIndexOf('.'))
|
|
|
+ const isImg = ['.png', '.jpg'].includes(ext.toLocaleLowerCase())
|
|
|
+ console.log(filename)
|
|
|
+ if (!isImg) {
|
|
|
+ message.error('只能上传png或jpg文件')
|
|
|
+ return Upload.LIST_IGNORE
|
|
|
+ } else if (file.size > 100 * 1024 * 1024) {
|
|
|
+ message.error('大小在100MB以内')
|
|
|
+ return Upload.LIST_IGNORE
|
|
|
+ } else {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return (
|
|
|
- <ImgCrop rotationSlider modalTitle={"裁剪" + BoardTypeDesc[type]} aspect={540 / 390} minZoom={1} maxZoom={5}>
|
|
|
+ <ImgCrop beforeCrop={beforeCrop} rotationSlider modalTitle={"裁剪" + BoardTypeDesc[type]} aspect={540 / 390} minZoom={1} maxZoom={5}>
|
|
|
<Upload beforeUpload={onUpload} multiple={false} accept="png">
|
|
|
<Button type="primary" ghost block>上传{ BoardTypeDesc[type] }</Button>
|
|
|
</Upload>
|