uni.showLoading({ title: "正在下载..." });
uni.downloadFile({
url: this.form.fileUrl, //下载地址接口返回
success: (data) => {
if (data.statusCode === 200) {
uni.hideLoading();
//文件保存到本地
uni.saveFile({
tempFilePath: data.tempFilePath, //临时路径
success: function (resd) {
uni.showToast({
icon: "success",
mask: true,
title: "下载成功",
duration: 2000,
});
//自动打开文档查看
setTimeout(() => {
var filePath = resd.savedFilePath;
uni.openDocument({
//新开页面打开文档,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx。
filePath: filePath,
showMenu: true,
success: function (res) {
console.log("打开文档成功");
},
});
}, 2000);
},
});
}
},
});
uni-app实现下载并且可以预览PDF分享到微信好友
于 2023-05-08 09:34:23 首次发布