diff --git a/core/core-frontend/src/utils/imgUtils.ts b/core/core-frontend/src/utils/imgUtils.ts index e965964490..27f73371b2 100644 --- a/core/core-frontend/src/utils/imgUtils.ts +++ b/core/core-frontend/src/utils/imgUtils.ts @@ -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(',')