// 前台
 // this.vehPlateImg :base64字符串
            downloadImgFront(row){
                console.log("开始下载图片");
                this.searchImgParams.gantryId = row.gantryid;
                this.searchImgParams.picId = row.picid;
                this.picId = row.picid;
                getImgInfo(this.searchImgParams).then(data => {
                    if (data) {
                        this.vehPlateImg = data.image;
                    }
                });
                let s = "data:image/jpg;base64,";
                this.downloadFileByBase64(s+this.vehPlateImg,this.picId+".jpg");
            },
             dataURLtoBlob(dataurl) {
                    var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
                        bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
                    while (n--) {
                        u8arr[n] = bstr.charCodeAt(n);
                    }
                    return new Blob([u8arr], { type: mime });
             },
            downloadFileByBase64(base64,name){
                var myBlob = this.dataURLtoBlob(base64)
                var myUrl = URL.createObjectURL(myBlob)
                this.downloadFile(myUrl,name)
            },
             downloadFile(url,name='What\'s the fuvk'){
                var a = document.createElement("a")
                a.setAttribute("href",url)
                a.setAttribute("download",name)
                a.setAttribute("target","_blank")
                let clickEvent = document.createEvent("MouseEvents");
                clickEvent.initEvent("click", true, true);
                a.dispatchEvent(clickEvent);
             },
Logo

前往低代码交流专区

更多推荐