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

使用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
 });

你可能感兴趣的:(uni-app,前端,安卓)