替换
miniprogram_npm\@vant\weapp\uploader\index.js
修改`onPreviewFile`方法
```javascript
onPreviewFile: function (event) {
console.info("vant预览文件");
var index = event.currentTarget.dataset.index;
let file = this.data.lists[index];
let url = file.url;
let name = file.name;
// 图片和视频直接预览,其它支持的下载打开
if (file.isImage || file.isVideo) {
wx.openDocument({
filePath: url,
showMenu: true
});
} else {
let supportExts = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf'];
var pos = url.lastIndexOf(".");
var ext = url.substr(pos + 1).toLowerCase();
if (supportExts.indexOf(ext) == -1) {
wx.showToast({
title: '暂不支持预览该文件',
icon: 'none',
})
} else {
wx.showLoading({
title: '加载中',
})
wx.downloadFile({
url: url,
filePath: `${wx.env.USER_DATA_PATH}/${name}`,
success: function (res) {
wx.openDocument({
filePath: res.filePath,
showMenu: true
})
},
complete: function (res) {
wx.hideLoading();
}
})
}
}
},
微信原生小程序vant van-uploader 文件上传,预览文件
最新推荐文章于 2024-07-05 11:46:52 发布