style: code optimization (#47300)

* chore: rm useless function

* fix: fix
This commit is contained in:
lijianan 2024-02-02 11:14:22 +08:00 committed by GitHub
parent ac33262111
commit dc4f40380c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 10 deletions

View File

@ -460,14 +460,12 @@ const InternalUpload: React.ForwardRefRenderFunction<UploadRef, UploadProps> = (
[`${prefixCls}-disabled`]: mergedDisabled,
});
const renderUploadButton = (uploadButtonStyle?: React.CSSProperties) => (
<div className={uploadButtonCls} style={uploadButtonStyle}>
const uploadButton = (
<div className={uploadButtonCls} style={children ? undefined : { display: 'none' }}>
<RcUpload {...rcUploadProps} ref={upload} />
</div>
);
const uploadButton = renderUploadButton(children ? undefined : { display: 'none' });
if (listType === 'picture-card' || listType === 'picture-circle') {
return wrapCSSVar(
<span className={mergedCls}>{renderUploadList(uploadButton, !!children)}</span>,

View File

@ -54,7 +54,7 @@ export const isImageUrl = (file: UploadFile): boolean => {
if (file.type && !file.thumbUrl) {
return isImageFileType(file.type);
}
const url: string = (file.thumbUrl || file.url || '') as string;
const url = file.thumbUrl || file.url || '';
const extension = extname(url);
if (
/^data:image\//.test(url) ||
@ -76,17 +76,16 @@ export const isImageUrl = (file: UploadFile): boolean => {
const MEASURE_SIZE = 200;
export function previewImage(file: File | Blob): Promise<string> {
return new Promise((resolve) => {
return new Promise<string>((resolve) => {
if (!file.type || !isImageFileType(file.type)) {
resolve('');
return;
}
const canvas = document.createElement('canvas');
canvas.width = MEASURE_SIZE;
canvas.height = MEASURE_SIZE;
canvas.style.cssText = `position: fixed; left: 0; top: 0; width: ${MEASURE_SIZE}px; height: ${MEASURE_SIZE}px; z-index: 9999; display: none;`;
document.body.appendChild(canvas);
document.body.appendChild<HTMLCanvasElement>(canvas);
const ctx = canvas.getContext('2d');
const img = new Image();
img.onload = () => {
@ -115,13 +114,17 @@ export function previewImage(file: File | Blob): Promise<string> {
if (file.type.startsWith('image/svg+xml')) {
const reader = new FileReader();
reader.onload = () => {
if (reader.result) img.src = reader.result as string;
if (reader.result && typeof reader.result === 'string') {
img.src = reader.result;
}
};
reader.readAsDataURL(file);
} else if (file.type.startsWith('image/gif')) {
const reader = new FileReader();
reader.onload = () => {
if (reader.result) resolve(reader.result as string);
if (reader.result) {
resolve(reader.result as string);
}
};
reader.readAsDataURL(file);
} else {