Skip to content

Commit f07375e

Browse files
committed
fix(Upload):Upload 图片缩略图不显示 #945
1 parent c9107da commit f07375e

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

components/upload/UploadList.jsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import Progress from '../progress';
77
import classNames from 'classnames';
88
import { UploadListProps } from './interface';
99

10-
const imageTypes = ['image', 'webp', 'png', 'svg', 'gif', 'jpg', 'jpeg', 'bmp', 'ico'];
10+
const isImageFileType = (type) => !!type && type.indexOf('image/') === 0;
1111
// https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL
1212
const previewFile = (file, callback) => {
13-
if (file.type && !imageTypes.includes(file.type)) {
13+
if (!isImageFileType(file.type)) {
1414
callback('');
15+
return;
1516
}
1617
const reader = new window.FileReader();
1718
reader.onloadend = () => callback(reader.result);
@@ -29,7 +30,7 @@ const extname = url => {
2930
};
3031

3132
const isImageUrl = file => {
32-
if (imageTypes.includes(file.type)) {
33+
if (isImageFileType(file.type)) {
3334
return true;
3435
}
3536
const url = file.thumbUrl || file.url;

components/upload/__tests__/uploadlist.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ describe('Upload List', () => {
339339
it('should generate thumbUrl from file', done => {
340340
const handlePreview = jest.fn();
341341
const newFileList = [...fileList];
342-
const newFile = { ...fileList[0], uid: -3, originFileObj: new File([], 'xxx.png') };
342+
const newFile = { ...fileList[0], uid: -3, originFileObj: new File([], 'xxx.png', { type: 'image/png' }) };
343343
delete newFile.thumbUrl;
344344
newFileList.push(newFile);
345345
const props = {
@@ -358,7 +358,7 @@ describe('Upload List', () => {
358358
};
359359
const wrapper = mount(Upload, props);
360360
setTimeout(async () => {
361-
const newFile = { ...fileList[2], uid: -4, originFileObj: new File([], 'xxx.png') };
361+
const newFile = { ...fileList[2], uid: -4, originFileObj: new File([], 'xxx.png', { type: 'image/png' }) };
362362
wrapper.setProps({
363363
defaultFileList: newFileList.push(newFile),
364364
});

0 commit comments

Comments
 (0)