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) {