var that = this
Taro.downloadFile({//下载
url: item.attachArr[0].attachmentPaths,//服务器上的pdf地址
// filePath: item.attachArr[0].attachmentPaths,//自定义文件地址
success: function (res) {
var filePath = res.tempFilePath;
that.stat = 'success';
that.alertText = '附件保存成功';
var fileType = ''
switch (item.attachArr[0].attachmentNames.split('.')[1]) {
case 'doc':
fileType = 'doc'
break;
case 'xls':
fileType = 'xls'
break;
case 'ppt':
fileType = 'ppt'
break;
case 'pdf':
fileType = 'pdf'
break;
case 'docx':
fileType = 'docx'
break;
case 'xlsx':
fileType = 'xlsx'
break;
case 'pptx':
fileType = 'pptx'
break;
default:
fileType = 'else'
break;
}
if(fileType != 'else'){
Taro.openDocument({
filePath: filePath,
fileType: fileType,
success: function(res) {
Taro.showToast({
title: '文档打开成功',
icon: 'success',
duration: 2000
})
console.log("文档打开成功");
},
fail: function (res) {
Taro.showToast({
title: '文档打开失败',
icon: 'none',
duration: 2000
})
},
});
}else{
Taro.previewImage({
current: '',
urls:[res.tempFilePath]
})
}
},
fail: function (res) {
that.isOpened = true
that.stat = 'error';
that.alertText = '附件保存失败';
}
})
关于Taro下载附件并保存
最新推荐文章于 2023-12-22 10:57:39 发布