From c9601938c908d77932312fdb16d62a2cc28e1f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Tue, 11 Mar 2025 22:44:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=20Excel.loadAll=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E5=8A=A0=E8=BD=BD=E5=BE=85=E6=89=80?= =?UTF-8?q?=E6=9C=89=E5=AF=BC=E5=87=BA=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stc/public/static/plugs/admin/excel.js | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/plugin/think-plugs-static/stc/public/static/plugs/admin/excel.js b/plugin/think-plugs-static/stc/public/static/plugs/admin/excel.js index d1bf7159e..b291e4024 100644 --- a/plugin/think-plugs-static/stc/public/static/plugs/admin/excel.js +++ b/plugin/think-plugs-static/stc/public/static/plugs/admin/excel.js @@ -42,22 +42,33 @@ define(function () { Excel.prototype.bind = function (done, filename, selector, options) { let that = this; this.options = options || {} + this.loadAll(function (data) { + that.export(data, this.dataset.filename || filename, options); + }, selector); + }; + + /** + * 加载所有数据 + * @param done + * @param selector + */ + Excel.prototype.loadAll = function (done, selector) { + let that = this; $('body').off('click', selector || '[data-form-export]').on('click', selector || '[data-form-export]', function () { - let form = $(this).parents('form'); - let name = this.dataset.filename || filename; - let method = this.dataset.method || form.attr('method') || 'get'; - let location = this.dataset.excel || this.dataset.formExport || form.attr('action') || ''; - let sortType = $(this).attr('data-sort-type') || '', sortField = $(this).attr('data-sort-field') || ''; + let button = this, form = $(button).parents('form'); + let method = button.dataset.method || form.attr('method') || 'get'; + let location = button.dataset.excel || button.dataset.formExport || form.attr('action') || ''; + let sortType = $(button).attr('data-sort-type') || '', sortField = $(button).attr('data-sort-field') || ''; if (sortField.length > 0 && sortType.length > 0) { location += (location.indexOf('?') > -1 ? '&' : '?') + '_order_=' + sortType + '&_field_=' + sortField; } that.load(location, form.serialize(), method).then(function (data) { - that.export(done.call(that, data, []), name); + done.call(button, data, []); }).fail(function (ret) { - $.msg.tips(ret || '文件导出失败'); + $.msg.tips(ret || '数据加载失败'); }); }); - }; + } /*! 加载导出的文档 */ Excel.prototype.load = function (url, data, method) {