Commit 2eb9f477 Harvey

下载海报

1 个父辈 0540f13c
...@@ -65,17 +65,14 @@ ...@@ -65,17 +65,14 @@
}, },
save() { save() {
//#ifdef H5 //#ifdef H5
// const $h5 = require('@/static/js/h5-utils.js')
// $h5.downLoadImg(this.src)
try { try {
if (Android) { if (Android) {
Android.save2Album(this.src) Android.save2Album(this.src)
} }
} catch (e) { } catch (e) {
const $h5 = require('@/static/js/h5-utils.js')
$h5.downloadIamge(this.src)
} }
//#endif //#endif
} }
} }
......
...@@ -24,28 +24,26 @@ export function head_tv(url) { ...@@ -24,28 +24,26 @@ export function head_tv(url) {
}); });
} }
export function savePicture(Url) { export function downloadIamge(imgsrc){
var blob=new Blob([''], {type:'application/octet-stream'}); const image = new Image()
var url = URL.createObjectURL(blob); // 允许资源跨域使用
var a = document.createElement('a'); image.setAttribute('crossOrigin', 'anonymous')
a.href = Url; image.src = imgsrc
a.download = Url.replace(/(.*\/)*([^.]+.*)/ig,"$2").split("?")[0]; image.onload = () => {
var e = document.createEvent('MouseEvents'); // 利用canvas将图片转换为base64编码
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); const canvas = document.createElement('canvas')
a.dispatchEvent(e); canvas.width = image.width
URL.revokeObjectURL(url); canvas.height = image.height
} const context = canvas.getContext('2d')
context?.drawImage(image, 0, 0, image.width, image.height)
export function downLoadImg1(url) { // 将canvas对象转换为base64位编码
let alink = document.createElement('a'); const url = canvas.toDataURL('image/png')
alink.href = url;
alink.download = '排1111.png';
alink.click();
}
export function downLoadImg(link, filename){
let a = document.createElement('a')
a.href = link
a.download = filename || 'default.png'
a.dispatchEvent(new MouseEvent('click'))
}
\ No newline at end of file \ No newline at end of file
// 点击触发下载
const a = document.createElement('a')
const event = new MouseEvent('click')
a.download = imgsrc.replace(/(.*\/)*([^.]+.*)/ig, "$2").split("?")[0] || 'Certificate'
a.href = url
a.dispatchEvent(event)
}
}
\ No newline at end of file \ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!