当前位置:首页 > 编程笔记 > 正文
已解决

uniapp APP下载流文件execl 并用WPS打开

来自网友在路上 149849提问 提问时间:2023-11-21 09:56:08阅读次数: 49

最佳答案 问答题库498位专家为你答疑解惑

使用plus.downloader.createDownload 方法将新建下载任务

HTML5+ API Reference

export default function plusDownload(config){if(!config){console.error("Argument should not be null");return;}const url=request.baseUrl+config.url;let token = uni.getStorageSync("token");let	header={//	'Content-Type':"application/octet-stream",'Authorization':"Bearer " + token//'Accept':'*/*'};config.header=config.header||{};Object.assign(header,config.header);let download= plus.downloader.createDownload(url,config,(d,s)=>config.complete(d,s,download));download.setRequestHeader('Authorization',"Bearer " + token);download.start();
}

封装方法

export function downloadInspectionResult(data) {uni.showLoading({title:'读取文件...',duration:10000});plusDownload({url:'/ny-iqc/incomingInspection/exportCoa?id='+data.id,method: 'POST',filename: '_downloads/'+data.fileName,header: { 'Content-Type': 'application/x-www-form-urlencoded' },data: data,complete: function (res,status,download) {uni.hideLoading();uni.openDocument({filePath: res.filename,fileType: 'xlsx',showMenu: true,success: () => {uni.showToast({title: '打开文档成功',icon: 'success',mask: true,});},fail: (error) => {console.log('error', error);},});},});
}

调用方法

downloadInspectionResult({
        id:id,
        fileName: fileName
 });

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"uniapp APP下载流文件execl 并用WPS打开":http://eshow365.cn/6-41120-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!