uniapp导出文件,支持流文件

content-type对照表

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'
								})
							})
						})
					})
				}
			}
		});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值