From 192ee65a1525b8a5cb8de89a406f19236c74aa9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=98=89=E8=B1=AA?= <42510293+ziyujiahao@users.noreply.github.com> Date: Tue, 28 Oct 2025 12:00:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E4=BF=AE=E5=A4=8DSa?= =?UTF-8?q?fari=20=E5=9C=A8=E5=AF=BC=E5=87=BA=E5=9B=BE=E8=A1=A8=E4=B8=BAPN?= =?UTF-8?q?G=E5=9B=BE=E7=89=87=E6=97=B6=E6=8A=A5=E9=94=99=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20#17210=20(#17279)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/core-frontend/src/utils/imgUtils.ts | 60 ++++++++++++------------ 1 file changed, 30 insertions(+), 30 deletions(-) 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(',')