From 8740d39e7062dbc17ccf7443d89da7d370558547 Mon Sep 17 00:00:00 2001 From: Junyi Date: Thu, 22 Aug 2024 14:57:46 +0800 Subject: [PATCH] fix(client): fix upload preview image (#5102) --- .../schema-component/antd/upload/shared.ts | 54 +++---------------- 1 file changed, 6 insertions(+), 48 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/upload/shared.ts b/packages/core/client/src/schema-component/antd/upload/shared.ts index 4a04520882..c979136edc 100644 --- a/packages/core/client/src/schema-component/antd/upload/shared.ts +++ b/packages/core/client/src/schema-component/antd/upload/shared.ts @@ -26,51 +26,7 @@ export const isPdf = (file) => { return match(file.mimetype || file.type, 'application/pdf'); }; -export const toMap = (fileList: any) => { - if (!fileList) { - return []; - } - if (typeof fileList !== 'object') { - return []; - } - let list = fileList; - if (!Array.isArray(fileList)) { - if (Object.keys({ ...fileList }).length === 0) { - return []; - } - list = [fileList]; - } - return list.map((item) => { - return [item.id || item.uid, toItem(item)]; - }); -}; - -export const toImages = (fileList) => { - if (!fileList) { - return []; - } - if (typeof fileList !== 'object') { - return []; - } - if (Object.keys(fileList).length === 0) { - return []; - } - let list = fileList; - if (!Array.isArray(fileList) && typeof fileList === 'object') { - list = [fileList]; - } - return list.map((item) => { - return { - ...item, - title: item.title || item.name, - imageUrl: getImageByUrl(item.url, { - exclude: ['.png', '.jpg', '.jpeg', '.gif'], - }), - }; - }); -}; - -export const toArr = (value) => { +const toArr = (value) => { if (!isValid(value)) { return []; } @@ -210,9 +166,11 @@ export const toItem = (file) => { ...file, id: file.id || file.uid, title: file.title || file.name, - imageUrl: getImageByUrl(file.url, { - exclude: ['.png', '.jpg', '.jpeg', '.gif'], - }), + imageUrl: isImage(file) + ? file.url + : getImageByUrl(file.url, { + exclude: ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp', '.bmp', '.ico'], + }), }; };