From b7300ea55866aeeb5f169b6dc5bfb5704fbfa039 Mon Sep 17 00:00:00 2001 From: Karson Date: Thu, 21 Dec 2017 23:04:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A1=A8=E6=A0=BC=E5=9C=A8?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E5=88=97=E5=A4=B4=E6=97=B6buttons=E7=9A=84?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E5=8F=AF=E8=83=BD=E4=B8=8D=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E7=9A=84BUG=20=E7=A7=BB=E9=99=A4=E8=A1=A8=E6=A0=BC=E6=8C=89?= =?UTF-8?q?=E9=92=AEcolumnIndex=EF=BC=8C=E5=A2=9E=E5=8A=A0fieldIndex?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/assets/js/backend.js | 50 +++++++++++++++++----- public/assets/js/require-backend.min.js | 57 ++++++++++++++++++------- public/assets/js/require-table.js | 7 ++- 3 files changed, 84 insertions(+), 30 deletions(-) diff --git a/public/assets/js/backend.js b/public/assets/js/backend.js index 8aca0a5e..0d4bca89 100755 --- a/public/assets/js/backend.js +++ b/public/assets/js/backend.js @@ -113,12 +113,26 @@ define(['fast', 'moment'], function (Fast, Moment) { $(document).on('click', '.btn-dialog,.dialogit', function (e) { var that = this; var options = $.extend({}, $(that).data() || {}); - if (typeof options.tableId !== 'undefined' && typeof options.columnIndex !== 'undefined' && typeof options.buttonIndex !== 'undefined') { + if (typeof options.tableId !== 'undefined' && typeof options.fieldIndex !== 'undefined' && typeof options.buttonIndex !== 'undefined') { var tableOptions = $("#" + options.tableId).bootstrapTable('getOptions'); if (tableOptions) { - var button = tableOptions.columns[0][options.columnIndex]['buttons'][options.buttonIndex]; - if (button && typeof button.callback === 'function') { - options.callback = button.callback; + var columnObj = null; + $.each(tableOptions.columns, function (i, columns) { + $.each(columns, function (j, column) { + if (typeof column.fieldIndex !== 'undefined' && column.fieldIndex === options.fieldIndex) { + columnObj = column; + return false; + } + }); + if (columnObj) { + return false; + } + }); + if (columnObj) { + var button = columnObj['buttons'][options.buttonIndex]; + if (button && typeof button.callback === 'function') { + options.callback = button.callback; + } } } } @@ -159,15 +173,29 @@ define(['fast', 'moment'], function (Fast, Moment) { var error = typeof options.error === 'function' ? options.error : null; delete options.success; delete options.error; - if (typeof options.tableId !== 'undefined' && typeof options.columnIndex !== 'undefined' && typeof options.buttonIndex !== 'undefined') { + if (typeof options.tableId !== 'undefined' && typeof options.fieldIndex !== 'undefined' && typeof options.buttonIndex !== 'undefined') { var tableOptions = $("#" + options.tableId).bootstrapTable('getOptions'); if (tableOptions) { - var button = tableOptions.columns[0][options.columnIndex]['buttons'][options.buttonIndex]; - if (button && typeof button.success === 'function') { - success = button.success; - } - if (button && typeof button.error === 'function') { - error = button.error; + var columnObj = null; + $.each(tableOptions.columns, function (i, columns) { + $.each(columns, function (j, column) { + if (typeof column.fieldIndex !== 'undefined' && column.fieldIndex === options.fieldIndex) { + columnObj = column; + return false; + } + }); + if (columnObj) { + return false; + } + }); + if (columnObj) { + var button = columnObj['buttons'][options.buttonIndex]; + if (button && typeof button.success === 'function') { + success = button.success; + } + if (button && typeof button.error === 'function') { + error = button.error; + } } } } diff --git a/public/assets/js/require-backend.min.js b/public/assets/js/require-backend.min.js index 00e46a17..8679e87b 100644 --- a/public/assets/js/require-backend.min.js +++ b/public/assets/js/require-backend.min.js @@ -6911,12 +6911,26 @@ define('backend',['fast', 'moment'], function (Fast, Moment) { $(document).on('click', '.btn-dialog,.dialogit', function (e) { var that = this; var options = $.extend({}, $(that).data() || {}); - if (typeof options.tableId !== 'undefined' && typeof options.columnIndex !== 'undefined' && typeof options.buttonIndex !== 'undefined') { + if (typeof options.tableId !== 'undefined' && typeof options.fieldIndex !== 'undefined' && typeof options.buttonIndex !== 'undefined') { var tableOptions = $("#" + options.tableId).bootstrapTable('getOptions'); if (tableOptions) { - var button = tableOptions.columns[0][options.columnIndex]['buttons'][options.buttonIndex]; - if (button && typeof button.callback === 'function') { - options.callback = button.callback; + var columnObj = null; + $.each(tableOptions.columns, function (i, columns) { + $.each(columns, function (j, column) { + if (typeof column.fieldIndex !== 'undefined' && column.fieldIndex === options.fieldIndex) { + columnObj = column; + return false; + } + }); + if (columnObj) { + return false; + } + }); + if (columnObj) { + var button = columnObj['buttons'][options.buttonIndex]; + if (button && typeof button.callback === 'function') { + options.callback = button.callback; + } } } } @@ -6957,15 +6971,29 @@ define('backend',['fast', 'moment'], function (Fast, Moment) { var error = typeof options.error === 'function' ? options.error : null; delete options.success; delete options.error; - if (typeof options.tableId !== 'undefined' && typeof options.columnIndex !== 'undefined' && typeof options.buttonIndex !== 'undefined') { + if (typeof options.tableId !== 'undefined' && typeof options.fieldIndex !== 'undefined' && typeof options.buttonIndex !== 'undefined') { var tableOptions = $("#" + options.tableId).bootstrapTable('getOptions'); if (tableOptions) { - var button = tableOptions.columns[0][options.columnIndex]['buttons'][options.buttonIndex]; - if (button && typeof button.success === 'function') { - success = button.success; - } - if (button && typeof button.error === 'function') { - error = button.error; + var columnObj = null; + $.each(tableOptions.columns, function (i, columns) { + $.each(columns, function (j, column) { + if (typeof column.fieldIndex !== 'undefined' && column.fieldIndex === options.fieldIndex) { + columnObj = column; + return false; + } + }); + if (columnObj) { + return false; + } + }); + if (columnObj) { + var button = columnObj['buttons'][options.buttonIndex]; + if (button && typeof button.success === 'function') { + success = button.success; + } + if (button && typeof button.error === 'function') { + error = button.error; + } } } } @@ -10005,9 +10033,8 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr var options = table ? table.bootstrapTable('getOptions') : {}; var html = []; var url, classname, icon, text, title, extend; - var columnIndex = options.columns[0].findIndex(function (element) { - return element === column; - }); + var fieldIndex = column.fieldIndex; + $.each(buttons, function (i, j) { if (type === 'operate') { if (j.name === 'dragsort' && typeof row[Table.config.dragsortfield] === 'undefined') { @@ -10028,7 +10055,7 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr refresh = j.refresh ? 'data-refresh="' + j.refresh + '"' : ''; confirm = j.confirm ? 'data-confirm="' + j.confirm + '"' : ''; extend = j.extend ? j.extend : ''; - html.push('' + (text ? ' ' + text : '') + ''); + html.push('' + (text ? ' ' + text : '') + ''); } }); return html.join(' '); diff --git a/public/assets/js/require-table.js b/public/assets/js/require-table.js index eebbf0c4..5b5b23b3 100644 --- a/public/assets/js/require-table.js +++ b/public/assets/js/require-table.js @@ -432,9 +432,8 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table var options = table ? table.bootstrapTable('getOptions') : {}; var html = []; var url, classname, icon, text, title, extend; - var columnIndex = options.columns[0].findIndex(function (element) { - return element === column; - }); + var fieldIndex = column.fieldIndex; + $.each(buttons, function (i, j) { if (type === 'operate') { if (j.name === 'dragsort' && typeof row[Table.config.dragsortfield] === 'undefined') { @@ -455,7 +454,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table refresh = j.refresh ? 'data-refresh="' + j.refresh + '"' : ''; confirm = j.confirm ? 'data-confirm="' + j.confirm + '"' : ''; extend = j.extend ? j.extend : ''; - html.push('' + (text ? ' ' + text : '') + ''); + html.push('' + (text ? ' ' + text : '') + ''); } }); return html.join(' ');