From 8c374c74249e425eb09a99a0fc0f4e9a4fc218eb 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 23:26:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DExcel=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E6=A0=B7=E5=BC=8F=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stc/public/static/plugs/admin/excel.js | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 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 3c3cade95..90e728f55 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 @@ -20,13 +20,13 @@ define(function () { } /*! 默认导出配置 */ - Excel.prototype.options = {writeOpt: {bookSST: true}}; + Excel.prototype.options = {writeOpt: {bookSST: false}}; /*! 导出 Excel 文件 */ Excel.prototype.export = function (data, name, options) { - if (data === false || data === null) return this; + name = name || '数据导出_' + layui.util.toDateString(Date.now(), '_yyyyMMdd_HHmmss'); if (name.substring(0, -5).toLowerCase() !== '.xlsx') name += '.xlsx'; - layui.excel.exportExcel(data, name, 'xlsx', options || this.options || {writeOpt: {bookSST: true}}); + layui.excel.exportExcel(data, name, 'xlsx', $.extend(options || {}, this.options)); }; /*! 绑定导出的事件 */ @@ -41,30 +41,24 @@ define(function () { // Excel.prototype.bind = function (done, filename, selector, options) { let that = this; - this.options = options || {} - this.bindLoadDone(function (data) { - that.export(data, this.dataset.filename || filename, options); + this.options = $.extend(this.options, options || {}); + this.bindLoadDone(function (data, button) { + that.export(done.call(that, data, []), button.dataset.filename || filename); }, selector); }; - /** - * 加载所有数据 - * @param done - * @param selector - */ + /*! 加载所有数据 */ Excel.prototype.bindLoadDone = function (done, selector) { let that = this; $('body').off('click', selector || '[data-form-export]').on('click', selector || '[data-form-export]', function () { - 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') || ''; + let button = this, form = $(this).parents('form'); + 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') || ''; if (sortField.length > 0 && sortType.length > 0) { location += (location.indexOf('?') > -1 ? '&' : '?') + '_order_=' + sortType + '&_field_=' + sortField; } - that.load(location, form.serialize(), method).then(function (data) { - done.call(button, data, []); - }).fail(function (ret) { + that.load(location, form.serialize(), method).then((data) => done.call(that, data, button)).fail(function (ret) { $.msg.tips(ret || '数据加载失败'); }); });