let url = this.codes[0].qrImgUrl
this.getBase64(url).then(function(base64){
let save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
save_link.href = base64;
if(that.pageType=='mediaIds'){
save_link.download = that.data[0].mediaNo+'.jpg';
}else{
save_link.download = that.data[0].salesmanName+that.data[0].accNo+'.jpg';
}
let event = document.createEvent('MouseEvents');
event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
save_link.dispatchEvent(event);
},function(err){
});
getBase64(img){
let that = this
let image = new Image();
image.crossOrigin = '';
image.src = img;
let deferred=$.Deferred();
if(img){
image.onload =function (){
deferred.resolve(that.getBase64Image(image));//将base64传给done上传处理
}
return deferred.promise();//问题要让onload完成后再return sessionStorage['imgTest']
}
},
getBase64Image(img,width,height) {//width、height调用时传入具体像素值,控制大小 ,不传则默认图像大小
let canvas = document.createElement("canvas");
canvas.width = width ? width : img.width;
canvas.height = height ? height : img.height;
let ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
let dataURL = canvas.toDataURL();
return dataURL;
},