diff --git a/src/main/resources/static/js/tools/toolsMge.js b/src/main/resources/static/js/tools/toolsMge.js index cf09a62..2050ac9 100644 --- a/src/main/resources/static/js/tools/toolsMge.js +++ b/src/main/resources/static/js/tools/toolsMge.js @@ -82,6 +82,7 @@ function initTable(dataList, limit, page) { limit: limit, cols: [ [ + {type: "checkbox", width: 50, unresize: true, align: "center"}, //表头 {title: "序号", width: 80, unresize: true, align: "center", templet: function (d) { @@ -108,20 +109,6 @@ function initTable(dataList, limit, page) { return '打印'; } }, - // {title: "操作", unresize: true, width: 85, align: "center", - // templet: function (d) { - // - // let html = ''; - // // let updaetpwd=""; - // // let del="" - // let view=""; - // html=view; - // if(d.delFlag==1){ - // return ''; - // } - // return html; - // } - // }, ], ], done: function (res, curr, count) { @@ -177,11 +164,6 @@ function handleClick2(submitLocation,sampleTools,devModule,devCode,experTime,nex window.print(); } -// 关闭模态对话框 -span.click(function() { - modal.hide(); -}); - // 点击模态对话框外部区域也可以关闭模态对话框 $(window).click(function(event) { if ($(event.target).is(modal)) { @@ -189,11 +171,64 @@ $(window).click(function(event) { } }); -// 打印二维码 -printButton.click(function() { - // 使用浏览器的打印功能打印二维码 - window.print(); -}); +/** + * 批量下载 + */ +function batchDownload() { + var selectedRows = table.checkStatus("table_data").data; + if (selectedRows.length == 0) { + return layer.msg('请选择要下载的数据', {icon: 7}) + } + // 创建一个临时 canvas 用于绘制带白边的二维码 + var qrWidth = 300; // 二维码的标准宽度 + var whiteBorder = 20; // 白边的宽度 + var totalWidth = qrWidth + 2 * whiteBorder; // 总宽度 + var canvas = document.createElement('canvas'); + canvas.width = totalWidth; + canvas.height = totalWidth; // 保持正方形 + var ctx = canvas.getContext('2d'); + + selectedRows.forEach(function (row, index) { + // 准备二维码内容 + const qrCodeData = { + "样品名称": row.sampleTools, + "规格型号": row.devModule, + "样品编号": row.devCode, + "检验日期": row.experTime, + "下次检验日期": row.nextExperTime, + "试验人员": row.experUser, + "试验结果": row.experConclu, + "送检单位": row.customName + }; + + // 创建二维码并填充白色背景 + $('#qr-canvas').empty(); + $('#qr-canvas').qrcode(utf16to8(JSON.stringify(qrCodeData, null, 2))); + + // 获取 qr-canvas 中的二维码元素 + var qrCanvas = document.querySelector('#qr-canvas canvas'); + var qrSize = qrCanvas.width; + + // 绘制白边 + ctx.fillStyle = "#FFFFFF"; // 设置白色 + ctx.fillRect(0, 0, totalWidth, totalWidth); // 填充整个画布 + + // 计算二维码的位置以确保居中 + var xOffset = (totalWidth - qrSize) / 2; + var yOffset = (totalWidth - qrSize) / 2; + + // 将二维码绘制到白边画布中,居中对齐 + ctx.drawImage(qrCanvas, xOffset, yOffset, qrSize, qrSize); + var dataURL = canvas.toDataURL('image/png'); + + // 创建下载链接并自动点击 + var link = document.createElement('a'); + link.href = dataURL; + link.download = `QRCode_${index + 1}.png`; + link.click(); + }); +} + function utf16to8(str) { var out, i, len, c; diff --git a/src/main/resources/static/pages/tools/toolsMge.html b/src/main/resources/static/pages/tools/toolsMge.html index f2a543b..50b9723 100644 --- a/src/main/resources/static/pages/tools/toolsMge.html +++ b/src/main/resources/static/pages/tools/toolsMge.html @@ -20,7 +20,7 @@
+