
- 发布:2021-04-27 16:11
- 更新:2021-04-27 16:11
- 阅读:1215
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win10版本1909
HBuilderX类型: 正式
HBuilderX版本号: 3.1.2
手机系统: 全部
手机厂商: 华为
页面类型: vue
打包方式: 云端
项目创建方式: HBuilderX
测试过的手机:
示例代码:
this.begindown = true;
var url = 'https://xxxxx/wx/p/9004?sid=' + sid + '&ctype=1&cid=' + cid;
sid=48yo我KqMLyytKpGSZ mZ2v43luuPaXYpcLalawhwMDAwRqdrxQIoBAAIC&ctype=1&cid=3451083'
const downloadTask = uni.downloadFile({
url: url, //下载地址接口返回
success: (data) => {
uni.hideLoading()
//console.log("========report====downloadTask====successed=======", data)
var pages = getCurrentPages();
console.log("======== currentpage===", pages.length, [pages.length - 1].toString())
if (pages[pages.length - 1].route === 'pages/reportBody/reportBody') {
this.tmpfile = data.tempFilePath;
console.log("-----------tmp dir:", data.tempFilePath)
setTimeout(() => {
this.begindown = false;
//打开文档查看
console.log("==========filepath============", this.tmpfile, this.filetype)
uni.openDocument({
filePath: data.tempFilePath,
fileType: this.filetype,
success: function(res) {
uni.hideLoading();
console.log('打开文档成功', res);
},
fail() {
uni.showToast({
title: '暂不支持此类型',
duration: 2000
});
uni.hideLoading();
}
});
}, 100)
}
},
fail: (err) => {
uni.hideLoading();
console.log("download err.........................")
console.log(err);
uni.showToast({
icon: 'none',
mask: true,
title: '失败请重新下载',
});
},
});
downloadTask.onProgressUpdate((res) => {
this.progress = res.progress;
this.downloadfilesize = res.totalBytesWritten;
console.log('下载进度' + this.progress);
// console.log('已经下载的数据长度' + res.totalBytesWritten);
// console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
});
}
this.begindown = true;
var url = 'https://xxxxx/wx/p/9004?sid=' + sid + '&ctype=1&cid=' + cid;
sid=48yo我KqMLyytKpGSZ mZ2v43luuPaXYpcLalawhwMDAwRqdrxQIoBAAIC&ctype=1&cid=3451083'
const downloadTask = uni.downloadFile({
url: url, //下载地址接口返回
success: (data) => {
uni.hideLoading()
//console.log("========report====downloadTask====successed=======", data)
var pages = getCurrentPages();
console.log("======== currentpage===", pages.length, [pages.length - 1].toString())
if (pages[pages.length - 1].route === 'pages/reportBody/reportBody') {
this.tmpfile = data.tempFilePath;
console.log("-----------tmp dir:", data.tempFilePath)
setTimeout(() => {
this.begindown = false;
//打开文档查看
console.log("==========filepath============", this.tmpfile, this.filetype)
uni.openDocument({
filePath: data.tempFilePath,
fileType: this.filetype,
success: function(res) {
uni.hideLoading();
console.log('打开文档成功', res);
},
fail() {
uni.showToast({
title: '暂不支持此类型',
duration: 2000
});
uni.hideLoading();
}
});
}, 100)
}
},
fail: (err) => {
uni.hideLoading();
console.log("download err.........................")
console.log(err);
uni.showToast({
icon: 'none',
mask: true,
title: '失败请重新下载',
});
},
});
downloadTask.onProgressUpdate((res) => {
this.progress = res.progress;
this.downloadfilesize = res.totalBytesWritten;
console.log('下载进度' + this.progress);
// console.log('已经下载的数据长度' + res.totalBytesWritten);
// console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
});
}
操作步骤:
参加附件代码
参加附件代码
预期结果:
正常显示文档
正常显示文档
实际结果:
未能显示文档
未能显示文档
bug描述:
2021年1月之前打开文档(pdf,word)成功,今天重新编译版本发现无法打开文档。接口显示打开文档成功!但是不显示文档,
文档下载成功,在微信小程序调试中点击文件可以正常打开。

