refactor: rerank item

This commit is contained in:
jialin
2024-11-22 10:00:34 +08:00
parent e05ec3d2d5
commit 419f1e07d1
15 changed files with 250 additions and 182 deletions
+18 -1
View File
@@ -3,11 +3,12 @@ import { useIntl } from '@umijs/max';
import { Button, Tooltip, Upload } from 'antd';
import type { UploadFile } from 'antd/es/upload';
import { RcFile } from 'antd/es/upload';
import { debounce } from 'lodash';
import { debounce, round } from 'lodash';
import React, { useCallback, useRef } from 'react';
interface UploadImgProps {
size?: 'small' | 'middle' | 'large';
height?: number;
handleUpdateImgList: (
imgList: { dataUrl: string; uid: number | string }[]
) => void;
@@ -15,6 +16,7 @@ interface UploadImgProps {
const UploadImg: React.FC<UploadImgProps> = ({
handleUpdateImgList,
height = 100,
size = 'small'
}) => {
const intl = useIntl();
@@ -36,6 +38,21 @@ const UploadImg: React.FC<UploadImgProps> = ({
[handleUpdateImgList, intl]
);
const getImgDimensions = useCallback(
(file: any): Promise<{ ratio: number }> => {
return new Promise((resolve) => {
const img = new Image();
img.onload = () => {
resolve({ ratio: round(img.width / img.height, 2) });
};
img.onerror = () => {
resolve({ ratio: 1 });
};
img.src = URL.createObjectURL(file);
});
},
[]
);
const handleChange = useCallback(
async (info: any) => {
const { fileList } = info;