Skip to content

fix(Upload):Upload 图片缩略图不显示 #945 #1189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions components/upload/UploadList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import Progress from '../progress';
import classNames from 'classnames';
import { UploadListProps } from './interface';

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

const isImageUrl = file => {
if (imageTypes.includes(file.type)) {
if (isImageFileType(file.type)) {
return true;
}
const url = file.thumbUrl || file.url;
Expand Down
12 changes: 10 additions & 2 deletions components/upload/__tests__/uploadlist.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,11 @@ describe('Upload List', () => {
it('should generate thumbUrl from file', done => {
const handlePreview = jest.fn();
const newFileList = [...fileList];
const newFile = { ...fileList[0], uid: -3, originFileObj: new File([], 'xxx.png') };
const newFile = {
...fileList[0],
uid: -3,
originFileObj: new File([], 'xxx.png', { type: 'image/png' }),
};
delete newFile.thumbUrl;
newFileList.push(newFile);
const props = {
Expand All @@ -358,7 +362,11 @@ describe('Upload List', () => {
};
const wrapper = mount(Upload, props);
setTimeout(async () => {
const newFile = { ...fileList[2], uid: -4, originFileObj: new File([], 'xxx.png') };
const newFile = {
...fileList[2],
uid: -4,
originFileObj: new File([], 'xxx.png', { type: 'image/png' }),
};
wrapper.setProps({
defaultFileList: newFileList.push(newFile),
});
Expand Down
2 changes: 1 addition & 1 deletion components/vc-form/src/createBaseForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function createBaseForm(option = {}, mixins = []) {
!(
!slotHasProp(fieldElem, valuePropName) &&
valuePropName in originalProps &&
!(fieldOption && initialValue in fieldOption)
!(fieldOption && 'initialValue' in fieldOption)
),
`${getComponentName(
fieldElem.componentOptions,
Expand Down