// 下载查看附件(文件)
openFile(url) {
uni.showLoading({
title: '正在下载文档...',
mask: true
})
uni.downloadFile({
url: url,
success: function(res) {
uni.hideLoading()
console.log("文件url", url)
const types = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf']
const _fileType = types.find(i => url.endsWith(i))
if (res.statusCode === 200) {
console.log('下载成功', res);
let filePath = res.tempFilePath;
uni.openDocument({
fileType: _fileType,
filePath: filePath,
success: function(resp) {
console.log('打开文档成功');
},
fail: function(resp) {
uni.showToast({
title: '请安装可阅读的软件',
icon: 'none',
duration: 2500
})
}
});
} else {
// 下载失败则提示
uni.showToast({
title: '下载异常!请重试!',
icon: 'none',
duration: 2500
})
}
},
complete() {
uni.hideLoading();
}
});
},
小程序查看附件
于 2023-07-27 20:06:37 首次发布