uniapp下载和保存发票到本地
·
var downloadTask = uni.downloadFile({
url: ioii_invoice_pic_url,
// #ifdef MP-WEIXIN
filePath: wx.env.USER_DATA_PATH + "/" + filename,
// #endif
success: (res) => {
console.log('res', res)
this.downloading = false
if (res.statusCode === 200) {
// #ifdef MP-WEIXIN
const filePath = res.filePath
if (fileExt === 'jpg' || fileExt === 'jpeg' || fileExt === 'png' || fileExt ===
'gif') {
//如果是图片走这里
uni.saveImageToPhotosAlbum({ //保存图片到系统相册。
filePath: filePath, //图片文件路径
success: function() {
uni.showToast({
title: '发票保存成功',
icon: 'none',
});
uni.previewImage({
current: 0,
urls: [ioii_invoice_pic_url],
})
},
fail: function(e) {
uni.showToast({
title: '发票保存失败',
icon: 'none',
});
}
});
} else {
wx.openDocument({
filePath: filePath,
fileType: fileExt,
showMenu: true,
success: (res) => {
console.log('打开文档成功')
},
fail: function(err) {
console.error('打开失败', err);
}
})
}
// #endif
// #ifdef H5
//this.h5SaveFile(res.tempFilePath, filename)
//this.common.toast(instructionUrl, 2000, false)
//this.h5SaveFile(instructionUrl, filename)
// #endif
}
},
fail: (err) => {
console.error('', err)
this.downloading = false
//this.common.toast(err, 2000, false)
this.common.toast('下载失败', 2000, false)
}
})
更多推荐
所有评论(0)