mirror of
https://github.com/dataease/dataease.git
synced 2026-05-15 13:32:18 +08:00
@@ -79,36 +79,6 @@ export function download2AppTemplate(downloadType, canvasDom, name, attachParams
|
||||
}
|
||||
|
||||
export function downloadCanvas2(type, canvasDom, name, callBack?) {
|
||||
toPng(canvasDom)
|
||||
.then(dataUrl => {
|
||||
if (type === 'img') {
|
||||
const a = document.createElement('a')
|
||||
a.setAttribute('download', name + '.png')
|
||||
a.href = dataUrl
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
} else {
|
||||
const contentWidth = canvasDom.offsetWidth
|
||||
const contentHeight = canvasDom.offsetHeight
|
||||
const lp = contentWidth > contentHeight ? 'l' : 'p'
|
||||
const PDF = new JsPDF(lp, 'pt', [contentWidth, contentHeight])
|
||||
PDF.addImage(dataUrl, 'PNG', 0, 0, contentWidth, contentHeight)
|
||||
PDF.save(name + '.pdf')
|
||||
}
|
||||
if (callBack) {
|
||||
callBack()
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
if (callBack) {
|
||||
callBack()
|
||||
}
|
||||
console.error('oops, something went wrong!', error)
|
||||
})
|
||||
}
|
||||
|
||||
export function downloadCanvas(type, canvasDom, name, callBack?) {
|
||||
// const canvasDom = document.getElementById(canvasId)
|
||||
if (canvasDom) {
|
||||
html2canvas(canvasDom)
|
||||
@@ -145,6 +115,36 @@ export function downloadCanvas(type, canvasDom, name, callBack?) {
|
||||
}
|
||||
}
|
||||
|
||||
export function downloadCanvas(type, canvasDom, name, callBack?) {
|
||||
toPng(canvasDom)
|
||||
.then(dataUrl => {
|
||||
if (type === 'img') {
|
||||
const a = document.createElement('a')
|
||||
a.setAttribute('download', name + '.png')
|
||||
a.href = dataUrl
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
} else {
|
||||
const contentWidth = canvasDom.offsetWidth
|
||||
const contentHeight = canvasDom.offsetHeight
|
||||
const lp = contentWidth > contentHeight ? 'l' : 'p'
|
||||
const PDF = new JsPDF(lp, 'pt', [contentWidth, contentHeight])
|
||||
PDF.addImage(dataUrl, 'PNG', 0, 0, contentWidth, contentHeight)
|
||||
PDF.save(name + '.pdf')
|
||||
}
|
||||
if (callBack) {
|
||||
callBack()
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
if (callBack) {
|
||||
callBack()
|
||||
}
|
||||
console.error('oops, something went wrong!', error)
|
||||
})
|
||||
}
|
||||
|
||||
export function dataURLToBlob(dataUrl) {
|
||||
// ie 图片转格式
|
||||
const arr = dataUrl.split(',')
|
||||
|
||||
Reference in New Issue
Block a user