From 410d735a3f7dfd9f3a8f9fa8aaa5cbb37cc86e82 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Sat, 13 Jul 2024 10:10:09 +0800 Subject: [PATCH] * [perf story #59018] Export to png for gantt wg. --- lib/zin/wg/gantt/js/v1.js | 52 +++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/lib/zin/wg/gantt/js/v1.js b/lib/zin/wg/gantt/js/v1.js index b39b663cd2..ae759a9ebc 100644 --- a/lib/zin/wg/gantt/js/v1.js +++ b/lib/zin/wg/gantt/js/v1.js @@ -122,26 +122,46 @@ function drawGanttToCanvas(exportType, successCallback, errorCallback) afterFinish(canvas); if(errorCallback) errorCallback('Cannot convert image to blob.'); }; - let width = canvas.width; - let height = canvas.height; - getRemoteScript(jsRoot + 'js/pdfjs/min.js', function() + if(isExportPDF) { - updateProgress(0.8); - let pdf = new jsPDF( + let width = canvas.width; + let height = canvas.height; + getRemoteScript(jsRoot + 'js/pdfjs/min.js', function() { - format: [width, height], - unit: 'px', - orientation: width > height ? 'l' : 'p' + let pdf = new jsPDF( + { + format: [width, height], + unit: 'px', + orientation: width > height ? 'l' : 'p' + }); + pdf.addImage(canvas, 0, 0, pdf.internal.pageSize.getWidth(), pdf.internal.pageSize.getHeight()); + pdf.save(fileName + '.pdf'); + if(successCallback) successCallback(pdf); + afterFinish(); + }, function(error) + { + afterFinish(canvas); + if(errorCallback) errorCallback(error); }); - pdf.addImage(canvas, 0, 0, pdf.internal.pageSize.getWidth(), pdf.internal.pageSize.getHeight()); - pdf.save(fileName + '.pdf'); - if(successCallback) successCallback(pdf); - afterFinish(); - }, function(error) + } + else { - afterFinish(canvas); - if(errorCallback) errorCallback(error); - }); + canvas.toBlob(function(blob) + { + let imageUrl = URL.createObjectURL(blob); + if(navigator.msSaveBlob) + { + navigator.msSaveOrOpenBlob(blob, fileName + '.png'); + } + else + { + $('#mainContent').append(''); + $('#mainContent #ganttDownload')[0].click(); + } + if(successCallback) successCallback(imageUrl); + afterFinish(canvas); + }); + } }).catch(function(error) { afterFinish();