From 473380d197c3d08122599a0f073b5ff990b0ef42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9C=E7=AC=99=E6=AD=8C?= <2277317060@qq.com> Date: Thu, 9 Jan 2025 19:48:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=93=E5=8D=B0=E7=95=8C?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/static/js/jQuery.print.js | 311 ++++++++++++++++++ .../manage/record_inspection/print.html | 130 +++++--- 2 files changed, 392 insertions(+), 49 deletions(-) create mode 100644 ruoyi-admin/src/main/resources/static/js/jQuery.print.js diff --git a/ruoyi-admin/src/main/resources/static/js/jQuery.print.js b/ruoyi-admin/src/main/resources/static/js/jQuery.print.js new file mode 100644 index 0000000..2c1cfba --- /dev/null +++ b/ruoyi-admin/src/main/resources/static/js/jQuery.print.js @@ -0,0 +1,311 @@ +/* @license + * jQuery.print, version 1.6.2 + * Licence: CC-By (http://creativecommons.org/licenses/by/3.0/) + *--------------------------------------------------------------------------*/ +(function ($) { + "use strict"; + // A nice closure for our definitions + + function jQueryCloneWithSelectAndTextAreaValues(elmToClone, withDataAndEvents, deepWithDataAndEvents) { + // Replacement jQuery clone that also clones the values in selects and textareas as jQuery doesn't for performance reasons - https://stackoverflow.com/questions/742810/clone-isnt-cloning-select-values + // Based on https://github.com/spencertipping/jquery.fix.clone + var $elmToClone = $(elmToClone), + $result = $elmToClone.clone(withDataAndEvents, deepWithDataAndEvents), + $myTextareas = $elmToClone.find('textarea').add($elmToClone.filter('textarea')), + $resultTextareas = $result.find('textarea').add($result.filter('textarea')), + $mySelects = $elmToClone.find('select').add($elmToClone.filter('select')), + $resultSelects = $result.find('select').add($result.filter('select')), + $myCanvas = $elmToClone.find('canvas').add($elmToClone.filter('canvas')), + $resultCanvas = $result.find('canvas').add($result.filter('canvas')), + i, l, j, m, myCanvasContext; + + for (i = 0, l = $myTextareas.length; i < l; ++i) { + $($resultTextareas[i]).val($($myTextareas[i]).val()); + } + for (i = 0, l = $mySelects.length; i < l; ++i) { + for (j = 0, m = $mySelects[i].options.length; j < m; ++j) { + if ($mySelects[i].options[j].selected === true) { + $resultSelects[i].options[j].selected = true; + } + } + } + for (i = 0, l = $myCanvas.length; i < l; ++i) { + // https://stackoverflow.com/a/41242597 + myCanvasContext = $myCanvas[i].getContext('2d'); + if(myCanvasContext) { + $resultCanvas[i].getContext('2d').drawImage($myCanvas[i], 0,0); + $($resultCanvas[i]).attr("data-jquery-print", myCanvasContext.canvas.toDataURL()); + } + } + return $result; + } + + function getjQueryObject(string) { + // Make string a vaild jQuery thing + var jqObj = $(""); + try { + jqObj = jQueryCloneWithSelectAndTextAreaValues(string); + } catch (e) { + jqObj = $("") + .html(string); + } + return jqObj; + } + + function printFrame(frameWindow, content, options) { + // Print the selected window/iframe + var def = $.Deferred(); + try { + frameWindow = frameWindow.contentWindow || frameWindow.contentDocument || frameWindow; + try { + frameWindow.resizeTo(window.innerWidth, window.innerHeight); + } catch (err) { + console.warn(err); + } + var wdoc = frameWindow.document || frameWindow.contentDocument || frameWindow; + if(options.doctype) { + wdoc.write(options.doctype); + } + wdoc.write(content); + try { + var canvas = wdoc.querySelectorAll('canvas'); + for(var i = 0; i < canvas.length; i++) { + var ctx = canvas[i].getContext("2d"); + var image = new Image(); + image.onload = function() { + ctx.drawImage(image, 0, 0); + }; + image.src = canvas[i].getAttribute("data-jquery-print"); + } + } catch (err) { + console.warn(err); + } + wdoc.close(); + var printed = false, + callPrint = function () { + if(printed) { + return; + } + // Fix for IE : Allow it to render the iframe + frameWindow.focus(); + try { + // Fix for IE11 - printng the whole page instead of the iframe content + if (!frameWindow.document.execCommand('print', false, null)) { + // document.execCommand returns false if it failed -http://stackoverflow.com/a/21336448/937891 + frameWindow.print(); + } + // focus body as it is losing focus in iPad and content not getting printed + $('body').focus(); + } catch (e) { + frameWindow.print(); + } + frameWindow.close(); + printed = true; + def.resolve(); + }; + // Print once the frame window loads - seems to work for the new-window option but unreliable for the iframe + $(frameWindow).on("load", callPrint); + // Fallback to printing directly if the frame doesn't fire the load event for whatever reason + setTimeout(callPrint, options.timeout); + } catch (err) { + def.reject(err); + } + return def; + } + + function printContentInIFrame(content, options) { + var $iframe = $(options.iframe + ""); + var iframeCount = $iframe.length; + if (iframeCount === 0) { + // Create a new iFrame if none is given + $iframe = $('