小程序完成下载
This commit is contained in:
parent
d7a31af5d5
commit
19ba67134f
@ -44,27 +44,39 @@ Page({
|
|||||||
alertInfo(message)
|
alertInfo(message)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const filePath = `${wx.env.USER_DATA_PATH}/发票/${that.data.id}.${res.tapIndex === 0 ? 'xml' : "pdf"}`;
|
wx.downloadFile({
|
||||||
FileSystemManager.writeFile({
|
url: data,
|
||||||
filePath: filePath,
|
success(res) {
|
||||||
data: res.data,
|
if (res.statusCode === 200) {
|
||||||
encoding: 'base64', // 2. base64解密写入, 后台返回的byte[]数组是经过base64编码的,其他方式写入文件打开格式不对
|
wx.openDocument({
|
||||||
success: function(res) {
|
filePath: res.tempFilePath,
|
||||||
wx.openDocument({
|
fileType: [res.tapIndex === 0 ? 'xml' : "pdf"], // 3. 这个必须写合法类型,不然下载不了 !!!
|
||||||
filePath: filePath,
|
success: function (res) {
|
||||||
fileType: [res.tapIndex === 0 ? 'xml' : "pdf"], // 3. 这个必须写合法类型,不然下载不了 !!!
|
console.log('打开文档成功')
|
||||||
success: function (res) {
|
},
|
||||||
console.log('打开文档成功')
|
fail: function (e) {
|
||||||
},
|
console.log(e.errMsg);
|
||||||
fail: function (e) {
|
}
|
||||||
console.log(e.errMsg);
|
})
|
||||||
}
|
}
|
||||||
})
|
|
||||||
},
|
|
||||||
fail: function (e) {
|
|
||||||
console.log(e.errMsg);
|
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// console.log('data', data)
|
||||||
|
// const filePath = `${wx.env.USER_DATA_PATH}/发票/${that.data.id}.${res.tapIndex === 0 ? 'xml' : "pdf"}`;
|
||||||
|
// FileSystemManager.writeFile({
|
||||||
|
// filePath: filePath,
|
||||||
|
// data: res.data,
|
||||||
|
// encoding: 'base64', // 2. base64解密写入, 后台返回的byte[]数组是经过base64编码的,其他方式写入文件打开格式不对
|
||||||
|
// success: function(res) {
|
||||||
|
|
||||||
|
// },
|
||||||
|
// fail: function (e) {
|
||||||
|
// console.log(e.errMsg);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user