uni.downloadFile({
url: config.baseUrl + '/mgr/pump/repair/export/' + data.pumpGroupId + '/' + data.date, //仅为示例,并非真实的资源
header:{
'Authorization': 'Bearer ' + getToken(),
'content-type':'application/vnd.ms-excel'
},
responseType: 'blob',
success: (res) => {
if (res.statusCode === 200) {
console.log('下载成功');
//更改文件名称
// 拿到临时文件的绝对路径
let filepathss = plus.io.convertLocalFileSystemURL(res.tempFilePath);
// 通过这个路径来拿到他
plus.io.resolveLocalFileSystemURL(filepathss, function(entry) {
const tempFileName = entry.name;
entry.getParent(function(parentDicEntry) {
console.log(parentDicEntry.fullPath)
entry.moveTo({
fullPath: parentDicEntry.fullPath + '/'
}, '新的文件名字.xlsx', function(newFile) {
uni.openDocument({
fileType: 'xlsx',
filePath: newFile.fullPath,
success: function(res2) {
console.log('打开文档成功');
},
fail: function(err) {
if (err.errCode == 1 || err
.code == 1) {
uni.showToast({
title: `下载成功,未找到能打开xlsx类型文件的手机应用`,
icon: 'none'
})
}
console.log(err)
}
});
}, function(moveError) {
uni.showToast({
title: `已在第三方应用中打开过,请在第三方应用查看时保存`,
icon: 'none'
})
})
})
})
}
}
});
uniapp导出文件,支持流文件
最新推荐文章于 2024-07-06 15:48:59 发布