From d6ef94c573130d39b6ac9f0b84519e8c0dcccdf3 Mon Sep 17 00:00:00 2001 From: Karson Date: Fri, 6 Jun 2025 23:43:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=97=E8=A1=A8=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/assets/js/require-table.js | 42 ++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/public/assets/js/require-table.js b/public/assets/js/require-table.js index ecb7aca1..860e25ae 100644 --- a/public/assets/js/require-table.js +++ b/public/assets/js/require-table.js @@ -18,11 +18,45 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table exportTypes: ['json', 'xml', 'csv', 'txt', 'doc', 'excel'], exportOptions: { fileName: 'export_' + Moment().format("YYYY-MM-DD"), - preventInjection: false, + htmlContent: false, mso: { onMsoNumberFormat: function (cell, row, col) { - return !isNaN($(cell).text()) ? '\\@' : ''; - }, + var text = $(cell).text().trim(); + return text !== '' && !isNaN(text) ? '\\@' : ''; + } + }, + onCellHtmlData: function (cell, row, col, html) { + var text = cell.text(); + + var path = location.pathname.match(/\/[^\/]+/)[0]; + path = path.indexOf(".php") > -1 ? path : ''; + if (cell.is("th")) { + return text; + } else if ($("input", cell).length > 0) { + var inputArr = []; + $("input", cell).each(function (key, item) { + inputArr.push($(item).val()); + }); + return inputArr.join(","); + } else if ($(">a", cell).length > 0) { + var anchorArr = []; + $(">a", cell).each(function (key, item) { + if (html.match(/ajax\/icon\?suffix=/)) { + anchorArr.push($(item).attr("href")); + } else if ($(item).find("i.fa-toggle-on").length > 0) { + anchorArr.push($(item).data("value")); + } else { + if ($(">img", item).length > 0 && !$.fn.bootstrapTable.defaults.exportOptions.htmlContent) { + anchorArr.push($(">img", item).prop("src").replace(new RegExp(path, "g"), '')); + } else { + anchorArr.push($(item).html().replace(new RegExp(path, "g"), '')); + } + } + }); + return anchorArr.join(","); + } else { + return html.replace(new RegExp(path, "g"), ''); + } }, ignoreColumn: [0, 'operate'] //默认不导出第一列(checkbox)与操作(operate)列 }, @@ -828,7 +862,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table if (typeof this.disable !== "undefined") { disable = typeof this.disable === "function" ? this.disable.call(this, value, row, index) : this.disable; } - return ""; }, url: function (value, row, index) {