1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| export default {
| save (img, name) {
| if (img) {
| img = this.dataURIToBlob(img, (blob) => {
| let url = URL.createObjectURL(blob)
| this.download(url, name)
| })
| }
| },
| dataURIToBlob (dataURI, cb) {
| let binStr = atob(dataURI.split(',')[1])
| let len = binStr.length
| let arr = new Uint8Array(len)
| for (var i = 0; i < len; i++) {
| arr[i] = binStr.charCodeAt(i)
| }
| cb(new Blob([arr]))
| },
| download (url, name) {
| name = name || ''
| let link = document.createElement('a')
| link.setAttribute('href', url)
| link.setAttribute('download', name)
| let el = document.body.appendChild(link)
| link.click()
| document.body.removeChild(el)
| }
| }
|
|