需求分析
将echarts图像以file形式传给后台,以excel列表形式进行下载导出图像与列表
掌握内容
- canvas图像下载到本地,转成Blob对象,转成file文件
- FormData添加其它需求参数
- js-file-download下载后台返回的二进制文件
Step1: canvas图像下载到本地,转成Blob对象,转成file
convertCanvas(canvas) {
// canvas参数为获取的echarts容器中的canvas标签;
console.log(canvas)
if (!HTMLCanvasElement.prototype.toBlob) {
Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', {
value: function (callback, type, quality) {
let binStr = atob( this.toDataURL(type, quality).split(',')[1] ),
len = binStr.length,
arr = new Uint8Array(len);
for (let i = 0; i < len; i++ ) {
arr[i] = binStr.charCodeAt(i);
}
// 转成image/jpg 格式
callback( new Blob( [arr], {type: type || 'im