Skip to content

Commit 9f7df84

Browse files
committed
fix: upload thumbUrl preview not work
1 parent 1f77ee6 commit 9f7df84

File tree

7 files changed

+45
-45
lines changed

7 files changed

+45
-45
lines changed

components/upload/Upload.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import { T, fileToObject, genPercentAdd, getFileItem, removeFileItem } from './u
1313

1414
export { UploadProps }
1515

16-
function noop () {}
17-
1816
export default {
1917
name: 'AUpload',
2018
Dragger: Dragger,
@@ -189,9 +187,11 @@ export default {
189187
},
190188
on: {
191189
remove: this.handleManualRemove,
192-
preview: this.$listeners.preview || noop,
193190
},
194191
}
192+
if (this.$listeners.preview) {
193+
uploadListProps.on.preview = this.$listeners.preview
194+
}
195195
return (
196196
<UploadList
197197
{...uploadListProps}

components/upload/UploadList.jsx

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ export default {
6161
this.$emit('remove', file)
6262
},
6363
handlePreview (file, e) {
64+
const { preview } = this.$listeners
65+
if(!preview) {
66+
return
67+
}
6468
e.preventDefault()
6569
return this.$emit('preview', file)
6670
},

components/upload/__tests__/__snapshots__/demo.test.js.snap

+5-18
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,18 @@ exports[`renders ./components/upload/demo/picture-card.md correctly 1`] = `
5757
`;
5858
5959
exports[`renders ./components/upload/demo/picture-style.md correctly 1`] = `
60-
<div><span><div class="ant-upload-list ant-upload-list-picture-card"><div class="ant-upload-list-item ant-upload-list-item-done"><div class="ant-upload-list-item-info"><span><a href="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" target="_blank" rel="noopener noreferrer" class="ant-upload-list-item-thumbnail"><img src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" alt="xxx.png"></a><a href="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" target="_blank" rel="noopener noreferrer" title="xxx.png" class="ant-upload-list-item-name">xxx.png</a></span></div>
61-
<span
62-
class="ant-upload-list-item-actions">
63-
<a href="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" target="_blank" rel="noopener noreferrer" title="Preview file">
64-
<i class="anticon anticon-eye-o"></i>
65-
</a>
66-
<i title="Remove file" class="anticon anticon-delete"></i>
67-
</span>
60+
<div><span><div class="ant-upload ant-upload-select ant-upload-select-picture"><!----></div><div class="ant-upload-list ant-upload-list-picture"><div class="ant-upload-list-item ant-upload-list-item-done"><div class="ant-upload-list-item-info"><span><a href="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" target="_blank" rel="noopener noreferrer" class="ant-upload-list-item-thumbnail"><img src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" alt="xxx.png"></a><a href="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" target="_blank" rel="noopener noreferrer" title="xxx.png" class="ant-upload-list-item-name">xxx.png</a></span></div>
61+
<i
62+
class="anticon anticon-cross"></i>
6863
<!---->
6964
</div>
7065
<div class="ant-upload-list-item ant-upload-list-item-done">
7166
<div class="ant-upload-list-item-info"><span><a href="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" target="_blank" rel="noopener noreferrer" class="ant-upload-list-item-thumbnail"><img src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" alt="yyy.png"></a><a href="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" target="_blank" rel="noopener noreferrer" title="yyy.png" class="ant-upload-list-item-name">yyy.png</a></span></div>
72-
<span
73-
class="ant-upload-list-item-actions">
74-
<a href="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" target="_blank" rel="noopener noreferrer" title="Preview file">
75-
<i class="anticon anticon-eye-o"></i>
76-
</a>
77-
<i title="Remove file" class="anticon anticon-delete"></i>
78-
</span>
67+
<i
68+
class="anticon anticon-cross"></i>
7969
<!---->
8070
</div>
8171
</div>
82-
<div class="ant-upload ant-upload-select ant-upload-select-picture-card">
83-
<!---->
84-
</div>
8572
</span>
8673
<br>
8774
<br> <span class="upload-list-inline"><div class="ant-upload ant-upload-select ant-upload-select-picture"><!----></div><div class="ant-upload-list ant-upload-list-picture"><div class="ant-upload-list-item ant-upload-list-item-done"><div class="ant-upload-list-item-info"><span><a href="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" target="_blank" rel="noopener noreferrer" class="ant-upload-list-item-thumbnail"><img src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" alt="xxx.png"></a><a href="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" target="_blank" rel="noopener noreferrer" title="xxx.png" class="ant-upload-list-item-name">xxx.png</a></span></div>

components/upload/demo/avatar.md

+23-14
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ The return value of function `beforeUpload` can be a Promise to check asynchrono
2929
</a-upload>
3030
</template>
3131
<script>
32-
function getBase64(img, callback) {
33-
const reader = new FileReader();
34-
reader.addEventListener('load', () => callback(reader.result));
35-
reader.readAsDataURL(img);
32+
function getBase64 (img, callback) {
33+
const reader = new FileReader()
34+
reader.addEventListener('load', () => callback(reader.result))
35+
reader.readAsDataURL(img)
3636
}
3737
export default {
3838
data () {
@@ -42,38 +42,47 @@ export default {
4242
}
4343
},
4444
methods: {
45-
handleChange(info) {
45+
handleChange (info) {
4646
if (info.file.status === 'uploading') {
4747
this.loading = true
48-
return;
48+
return
4949
}
5050
if (info.file.status === 'done') {
5151
// Get this url from response in real world.
5252
getBase64(info.file.originFileObj, (imageUrl) => {
5353
this.imageUrl = imageUrl
5454
this.loading = false
55-
});
55+
})
5656
}
5757
},
58-
beforeUpload(file) {
59-
const isJPG = file.type === 'image/jpeg';
58+
beforeUpload (file) {
59+
const isJPG = file.type === 'image/jpeg'
6060
if (!isJPG) {
61-
this.$message.error('You can only upload JPG file!');
61+
this.$message.error('You can only upload JPG file!')
6262
}
63-
const isLt2M = file.size / 1024 / 1024 < 2;
63+
const isLt2M = file.size / 1024 / 1024 < 2
6464
if (!isLt2M) {
65-
this.$message.error('Image must smaller than 2MB!');
65+
this.$message.error('Image must smaller than 2MB!')
6666
}
67-
return isJPG && isLt2M;
67+
return isJPG && isLt2M
6868
},
6969
},
7070
}
7171
</script>
72-
<style scoped>
72+
<style>
7373
.avatar-uploader > .ant-upload {
7474
width: 128px;
7575
height: 128px;
7676
}
77+
.ant-upload-select-picture-card i {
78+
font-size: 32px;
79+
color: #999;
80+
}
81+
82+
.ant-upload-select-picture-card .ant-upload-text {
83+
margin-top: 8px;
84+
color: #666;
85+
}
7786
</style>
7887
```
7988

components/upload/demo/picture-card.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ After users upload picture, the thumbnail will be shown in list. The upload butt
2424
</div>
2525
</a-upload>
2626
<a-modal :visible="previewVisible" :footer="null" @cancel="handleCancel">
27-
<img alt="example" style="width: '100%'" :src="previewImage" />
27+
<img alt="example" style="width: 100%" :src="previewImage" />
2828
</a-modal>
2929
</div>
3030
</template>
@@ -43,20 +43,20 @@ export default {
4343
}
4444
},
4545
methods: {
46-
handleCancel() {
46+
handleCancel () {
4747
this.previewVisible = false
4848
},
49-
handlePreview(file) {
49+
handlePreview (file) {
5050
this.previewImage = file.url || file.thumbUrl
5151
this.previewVisible = true
5252
},
53-
handleChange({ fileList }) {
53+
handleChange ({ fileList }) {
5454
this.fileList = fileList
5555
},
5656
},
5757
}
5858
</script>
59-
<style scoped>
59+
<style>
6060
/* you can make up upload button and sample style by using stylesheets */
6161
.ant-upload-select-picture-card i {
6262
font-size: 32px;

components/upload/demo/picture-style.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ If uploaded file is a picture, the thumbnail can be shown. `IE8/9` do not suppor
1313
<div>
1414
<a-upload
1515
action="//jsonplaceholder.typicode.com/posts/"
16-
listType="picture-card"
16+
listType="picture"
1717
:defaultFileList="fileList"
1818
>
1919
<a-button>
@@ -57,15 +57,15 @@ export default {
5757
</script>
5858
<style scoped>
5959
/* tile uploaded pictures */
60-
.upload-list-inline .ant-upload-list-item {
60+
.upload-list-inline >>> .ant-upload-list-item {
6161
float: left;
6262
width: 200px;
6363
margin-right: 8px;
6464
}
65-
.upload-list-inline .ant-upload-animate-enter {
65+
.upload-list-inline >>> .ant-upload-animate-enter {
6666
animation-name: uploadAnimateInlineIn;
6767
}
68-
.upload-list-inline .ant-upload-animate-leave {
68+
.upload-list-inline >>> .ant-upload-animate-leave {
6969
animation-name: uploadAnimateInlineOut;
7070
}
7171
</style>

components/upload/interface.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const UploadFileStatus = PropsTypes.oneOf(['error', 'success', 'done', 'u
3030
function UploadFile ({ uid, name }) {
3131
if (!uid && uid !== 0) return false
3232
if (!['string', 'number'].includes(typeof uid)) return false
33-
if (!name && typeof name !== 'string') return false
33+
if (name === '' || typeof name !== 'string') return false
3434
return true
3535
}
3636

0 commit comments

Comments
 (0)