feat(uploader): support preview file (#3975)

fix #3946
This commit is contained in:
rex 2021-01-19 17:51:20 +08:00 committed by GitHub
parent 5e1c65e52a
commit 808b057980
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -199,6 +199,15 @@ VantComponent({
}); });
}, },
onPreviewFile(event: WechatMiniprogram.TouchEvent) {
const { index } = event.currentTarget.dataset;
wx.openDocument({
filePath: this.data.lists[index].url,
showMenu: true,
});
},
onClickPreview(event) { onClickPreview(event) {
const { index } = event.currentTarget.dataset; const { index } = event.currentTarget.dataset;
const item: File = this.data.lists[index]; const item: File = this.data.lists[index];

View File

@ -20,7 +20,7 @@
class="van-uploader__preview-image" class="van-uploader__preview-image"
style="{{ computed.sizeStyle({ previewSize }) }}" style="{{ computed.sizeStyle({ previewSize }) }}"
data-index="{{ index }}" data-index="{{ index }}"
bind:tap="onPreviewImage" bindtap="onPreviewImage"
/> />
<video <video
wx:elif="{{ item.isVideo }}" wx:elif="{{ item.isVideo }}"
@ -31,13 +31,15 @@
class="van-uploader__preview-image" class="van-uploader__preview-image"
style="{{ computed.sizeStyle({ previewSize }) }}" style="{{ computed.sizeStyle({ previewSize }) }}"
data-index="{{ index }}" data-index="{{ index }}"
bind:tap="onPreviewVideo" bindtap="onPreviewVideo"
> >
</video> </video>
<view <view
wx:else wx:else
class="van-uploader__file" class="van-uploader__file"
style="{{ computed.sizeStyle({ previewSize }) }}" style="{{ computed.sizeStyle({ previewSize }) }}"
data-index="{{ index }}"
bindtap="onPreviewFile"
> >
<van-icon name="description" class="van-uploader__file-icon" /> <van-icon name="description" class="van-uploader__file-icon" />
<view class="van-uploader__file-name van-ellipsis">{{ item.name || item.url }}</view> <view class="van-uploader__file-name van-ellipsis">{{ item.name || item.url }}</view>