require-table.js 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  1. define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table', 'bootstrap-table-lang', 'bootstrap-table-export', 'bootstrap-table-commonsearch', 'bootstrap-table-template', 'bootstrap-table-jumpto', 'bootstrap-table-fixed-columns'], function ($, undefined, Moment) {
  2. var Table = {
  3. list: {},
  4. // Bootstrap-table 基础配置
  5. defaults: {
  6. url: '',
  7. sidePagination: 'server',
  8. method: 'get', //请求方法
  9. toolbar: ".toolbar", //工具栏
  10. search: true, //是否启用快速搜索
  11. cache: false,
  12. commonSearch: true, //是否启用通用搜索
  13. searchFormVisible: false, //是否始终显示搜索表单
  14. titleForm: '', //为空则不显示标题,不定义默认显示:普通搜索
  15. idTable: 'commonTable',
  16. showExport: true,
  17. exportDataType: "auto",
  18. exportTypes: ['json', 'xml', 'csv', 'txt', 'doc', 'excel'],
  19. exportOptions: {
  20. fileName: 'export_' + Moment().format("YYYY-MM-DD"),
  21. preventInjection: false,
  22. mso: {
  23. onMsoNumberFormat: function (cell, row, col) {
  24. return !isNaN($(cell).text()) ? '\\@' : '';
  25. },
  26. },
  27. ignoreColumn: [0, 'operate'] //默认不导出第一列(checkbox)与操作(operate)列
  28. },
  29. pageSize: Config.pagesize || localStorage.getItem("pagesize") || 10,
  30. pageList: [10, 15, 20, 25, 50, 'All'],
  31. pagination: true,
  32. clickToSelect: true, //是否启用点击选中
  33. dblClickToEdit: true, //是否启用双击编辑
  34. singleSelect: false, //是否启用单选
  35. showRefresh: false,
  36. showJumpto: true,
  37. locale: Config.language == 'zh-cn' ? 'zh-CN' : 'en-US',
  38. showToggle: true,
  39. showColumns: true,
  40. pk: 'id',
  41. sortName: 'id',
  42. sortOrder: 'desc',
  43. paginationFirstText: __("First"),
  44. paginationPreText: __("Previous"),
  45. paginationNextText: __("Next"),
  46. paginationLastText: __("Last"),
  47. cardView: false, //卡片视图
  48. iosCardView: true, //ios卡片视图
  49. checkOnInit: true, //是否在初始化时判断
  50. escape: true, //是否对内容进行转义
  51. fixDropdownPosition: true, //是否修复下拉的定位
  52. dragCheckboxMultiselect: true, //拖拽时复选框是否多选模式
  53. selectedIds: [],
  54. selectedData: [],
  55. extend: {
  56. index_url: '',
  57. add_url: '',
  58. edit_url: '',
  59. del_url: '',
  60. import_url: '',
  61. multi_url: '',
  62. dragsort_url: 'ajax/weigh',
  63. }
  64. },
  65. // Bootstrap-table 列配置
  66. columnDefaults: {
  67. align: 'center',
  68. valign: 'middle',
  69. },
  70. config: {
  71. checkboxtd: 'tbody>tr>td.bs-checkbox',
  72. toolbar: '.toolbar',
  73. refreshbtn: '.btn-refresh',
  74. addbtn: '.btn-add',
  75. editbtn: '.btn-edit',
  76. delbtn: '.btn-del',
  77. importbtn: '.btn-import',
  78. multibtn: '.btn-multi',
  79. disabledbtn: '.btn-disabled',
  80. editonebtn: '.btn-editone',
  81. restoreonebtn: '.btn-restoreone',
  82. destroyonebtn: '.btn-destroyone',
  83. restoreallbtn: '.btn-restoreall',
  84. destroyallbtn: '.btn-destroyall',
  85. dragsortfield: 'weigh',
  86. },
  87. button: {
  88. edit: {
  89. name: 'edit',
  90. icon: 'fa fa-pencil',
  91. title: __('Edit'),
  92. extend: 'data-toggle="tooltip"',
  93. classname: 'btn btn-xs btn-success btn-editone'
  94. },
  95. del: {
  96. name: 'del',
  97. icon: 'fa fa-trash',
  98. title: __('Del'),
  99. extend: 'data-toggle="tooltip"',
  100. classname: 'btn btn-xs btn-danger btn-delone'
  101. },
  102. dragsort: {
  103. name: 'dragsort',
  104. icon: 'fa fa-arrows',
  105. title: __('Drag to sort'),
  106. extend: 'data-toggle="tooltip"',
  107. classname: 'btn btn-xs btn-primary btn-dragsort'
  108. }
  109. },
  110. api: {
  111. init: function (defaults, columnDefaults, locales) {
  112. defaults = defaults ? defaults : {};
  113. columnDefaults = columnDefaults ? columnDefaults : {};
  114. locales = locales ? locales : {};
  115. $.fn.bootstrapTable.Constructor.prototype.getSelectItem = function () {
  116. return this.$selectItem;
  117. };
  118. var _onPageListChange = $.fn.bootstrapTable.Constructor.prototype.onPageListChange;
  119. $.fn.bootstrapTable.Constructor.prototype.onPageListChange = function () {
  120. _onPageListChange.apply(this, Array.prototype.slice.apply(arguments));
  121. localStorage.setItem('pagesize', this.options.pageSize);
  122. return false;
  123. };
  124. // 写入bootstrap-table默认配置
  125. $.extend(true, $.fn.bootstrapTable.defaults, Table.defaults, defaults);
  126. // 写入bootstrap-table column配置
  127. $.extend($.fn.bootstrapTable.columnDefaults, Table.columnDefaults, columnDefaults);
  128. // 写入bootstrap-table locale配置
  129. $.extend($.fn.bootstrapTable.locales[Table.defaults.locale], {
  130. formatCommonSearch: function () {
  131. return __('Common search');
  132. },
  133. formatCommonSubmitButton: function () {
  134. return __('Submit');
  135. },
  136. formatCommonResetButton: function () {
  137. return __('Reset');
  138. },
  139. formatCommonCloseButton: function () {
  140. return __('Close');
  141. },
  142. formatCommonChoose: function () {
  143. return __('Choose');
  144. },
  145. formatJumpto: function () {
  146. return __('Go');
  147. }
  148. }, locales);
  149. // 如果是iOS设备则判断是否启用卡片视图
  150. if ($.fn.bootstrapTable.defaults.iosCardView && navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
  151. Table.defaults.cardView = true;
  152. $.fn.bootstrapTable.defaults.cardView = true;
  153. }
  154. if (typeof defaults.exportTypes != 'undefined') {
  155. $.fn.bootstrapTable.defaults.exportTypes = defaults.exportTypes;
  156. }
  157. },
  158. // 绑定事件
  159. bindevent: function (table) {
  160. //Bootstrap-table的父元素,包含table,toolbar,pagnation
  161. var parenttable = table.closest('.bootstrap-table');
  162. //Bootstrap-table配置
  163. var options = table.bootstrapTable('getOptions');
  164. //Bootstrap操作区
  165. var toolbar = $(options.toolbar, parenttable);
  166. //跨页提示按钮
  167. var tipsBtn = $(".btn-selected-tips", parenttable);
  168. if (tipsBtn.length === 0) {
  169. tipsBtn = $('<a href="javascript:" class="btn btn-warning-light btn-selected-tips hide" data-animation="false" data-toggle="tooltip" data-title="' + __("Click to uncheck all") + '"><i class="fa fa-info-circle"></i> ' + __("Multiple selection mode: %s checked", "<b>0</b>") + '</a>').appendTo(toolbar);
  170. }
  171. //点击提示按钮
  172. tipsBtn.off("click").on("click", function (e) {
  173. table.trigger("uncheckbox");
  174. table.bootstrapTable("refresh");
  175. });
  176. //当刷新表格时
  177. table.on('uncheckbox', function (status, res, e) {
  178. options.selectedIds = [];
  179. options.selectedData = [];
  180. tipsBtn.tooltip('hide');
  181. tipsBtn.addClass('hide');
  182. });
  183. //表格加载出错时
  184. table.on('load-error.bs.table', function (status, res, e) {
  185. if (e.status === 0) {
  186. return;
  187. }
  188. Toastr.error(__('Unknown data format'));
  189. });
  190. //当加载数据成功时
  191. table.on('load-success.bs.table', function (e, data) {
  192. if (typeof data.rows === 'undefined' && typeof data.code != 'undefined') {
  193. Toastr.error(data.msg);
  194. }
  195. });
  196. //当刷新表格时
  197. table.on('refresh.bs.table', function (e, settings, data) {
  198. $(Table.config.refreshbtn, toolbar).find(".fa").addClass("fa-spin");
  199. });
  200. //当执行搜索时
  201. table.on('search.bs.table common-search.bs.table', function (e, settings, data) {
  202. table.trigger("uncheckbox");
  203. });
  204. if (options.dblClickToEdit) {
  205. //当双击单元格时
  206. table.on('dbl-click-row.bs.table', function (e, row, element, field) {
  207. $(Table.config.editonebtn, element).trigger("click");
  208. });
  209. }
  210. //渲染内容前
  211. table.on('pre-body.bs.table', function (e, data) {
  212. if (options.maintainSelected) {
  213. $.each(data, function (i, row) {
  214. row[options.stateField] = $.inArray(row[options.pk], options.selectedIds) > -1;
  215. });
  216. }
  217. });
  218. //当内容渲染完成后
  219. table.on('post-body.bs.table', function (e, data) {
  220. $(Table.config.refreshbtn, toolbar).find(".fa").removeClass("fa-spin");
  221. if ($(Table.config.checkboxtd + ":first", table).find("input[type='checkbox'][data-index]").length > 0) {
  222. //拖拽选择复选框
  223. var posx, posy, dragdiv, drag = false, prepare = false;
  224. var mousemove = function (e) {
  225. if (drag) {
  226. var left = Math.min(e.pageX, posx);
  227. var top = Math.min(e.pageY, posy);
  228. var width = Math.abs(posx - e.pageX);
  229. var height = Math.abs(posy - e.pageY);
  230. dragdiv.css({left: left + "px", top: top + "px", width: width + "px", height: height + "px"});
  231. var dragrect = {x: left, y: top, width: width, height: height};
  232. $(Table.config.checkboxtd, table).each(function () {
  233. var checkbox = $("input:checkbox", this);
  234. var tdrect = this.getBoundingClientRect();
  235. tdrect.x += document.documentElement.scrollLeft;
  236. tdrect.y += document.documentElement.scrollTop;
  237. var td_min_x = tdrect.x;
  238. var td_min_y = tdrect.y;
  239. var td_max_x = tdrect.x + tdrect.width;
  240. var td_max_y = tdrect.y + tdrect.height;
  241. var drag_min_x = dragrect.x;
  242. var drag_min_y = dragrect.y;
  243. var drag_max_x = dragrect.x + dragrect.width;
  244. var drag_max_y = dragrect.y + dragrect.height;
  245. var overlapped = td_min_x <= drag_max_x && td_max_x >= drag_min_x && td_min_y <= drag_max_y && td_max_y >= drag_min_y;
  246. if (overlapped) {
  247. if (!$(this).hasClass("overlaped")) {
  248. $(this).addClass("overlaped");
  249. checkbox.prop("checked", !checkbox.prop("checked"));
  250. }
  251. } else {
  252. if ($(this).hasClass("overlaped")) {
  253. $(this).removeClass("overlaped");
  254. checkbox.prop("checked", !checkbox.prop("checked"));
  255. }
  256. }
  257. });
  258. }
  259. };
  260. var selectstart = function () {
  261. return false;
  262. };
  263. var mouseup = function () {
  264. if (drag) {
  265. $(document).off("mousemove", mousemove);
  266. $(document).off("selectstart", selectstart);
  267. dragdiv.remove();
  268. }
  269. drag = false;
  270. prepare = false;
  271. $(document.body).css({'MozUserSelect': '', 'webkitUserSelect': ''}).attr('unselectable', 'off');
  272. };
  273. $(Table.config.checkboxtd, table).on("mousedown", function (e) {
  274. //禁止鼠标右键事件
  275. if (e.button === 2) {
  276. return false;
  277. }
  278. posx = e.pageX;
  279. posy = e.pageY;
  280. prepare = true;
  281. }).on("mousemove", function (e) {
  282. if (prepare && !drag) {
  283. drag = true;
  284. dragdiv = $("<div />");
  285. dragdiv.css({position: 'absolute', width: 0, height: 0, border: "1px dashed blue", background: "#0029ff", left: e.pageX + "px", top: e.pageY + "px", opacity: .1});
  286. dragdiv.appendTo(document.body);
  287. $(document.body).css({'MozUserSelect': 'none', 'webkitUserSelect': 'none'}).attr('unselectable', 'on');
  288. $(document).on("mousemove", mousemove).on("mouseup", mouseup).on("selectstart", selectstart);
  289. if (options.dragCheckboxMultiselect) {
  290. $(Table.config.checkboxtd, table).removeClass("overlaped");
  291. }
  292. }
  293. });
  294. }
  295. });
  296. var exportDataType = options.exportDataType;
  297. // 处理选中筛选框后按钮的状态统一变更
  298. table.on('check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table post-body.bs.table', function (e) {
  299. var allIds = [];
  300. $.each(table.bootstrapTable("getData"), function (i, item) {
  301. allIds.push(typeof item[options.pk] != 'undefined' ? item[options.pk] : '');
  302. });
  303. var selectedIds = Table.api.selectedids(table, true),
  304. selectedData = Table.api.selecteddata(table, true);
  305. //开启分页checkbox分页记忆
  306. if (options.maintainSelected) {
  307. options.selectedIds = options.selectedIds.filter(function (element, index, self) {
  308. return $.inArray(element, allIds) === -1;
  309. }).concat(selectedIds);
  310. options.selectedData = options.selectedData.filter(function (element, index, self) {
  311. return $.inArray(element[options.pk], allIds) === -1;
  312. }).concat(selectedData);
  313. if (options.selectedIds.length > selectedIds.length) {
  314. $("b", tipsBtn).text(options.selectedIds.length);
  315. tipsBtn.removeClass('hide');
  316. } else {
  317. tipsBtn.addClass('hide');
  318. }
  319. } else {
  320. options.selectedIds = selectedIds;
  321. options.selectedData = selectedData;
  322. }
  323. //如果导出类型为auto时则自动判断
  324. if (exportDataType === 'auto') {
  325. options.exportDataType = selectedIds.length > 0 ? 'selected' : 'all';
  326. }
  327. $(Table.config.disabledbtn, toolbar).toggleClass('disabled', !options.selectedIds.length);
  328. });
  329. // 绑定TAB事件
  330. $('.panel-heading [data-field] a[data-toggle="tab"]', table.closest(".panel-intro")).on('shown.bs.tab', function (e) {
  331. var field = $(this).closest("[data-field]").data("field");
  332. var value = $(this).data("value");
  333. var object = $("[name='" + field + "']", table.closest(".bootstrap-table").find(".commonsearch-table"));
  334. if (object.prop('tagName') == "SELECT") {
  335. $("option[value='" + value + "']", object).prop("selected", true);
  336. } else {
  337. object.val(value);
  338. }
  339. table.trigger("uncheckbox");
  340. table.bootstrapTable('refresh', {pageNumber: 1});
  341. return false;
  342. });
  343. // 修复重置事件
  344. $("form", table.closest(".bootstrap-table").find(".commonsearch-table")).on('reset', function () {
  345. setTimeout(function () {
  346. // $('.panel-heading [data-field] li.active a[data-toggle="tab"]').trigger('shown.bs.tab');
  347. }, 0);
  348. $('.panel-heading [data-field] li', table.closest(".panel-intro")).removeClass('active');
  349. $('.panel-heading [data-field] li:first', table.closest(".panel-intro")).addClass('active');
  350. });
  351. // 刷新按钮事件
  352. toolbar.on('click', Table.config.refreshbtn, function () {
  353. table.bootstrapTable('refresh');
  354. });
  355. // 添加按钮事件
  356. toolbar.on('click', Table.config.addbtn, function () {
  357. var ids = Table.api.selectedids(table);
  358. var url = options.extend.add_url;
  359. if (url.indexOf("{ids}") !== -1) {
  360. url = Table.api.replaceurl(url, {ids: ids.length > 0 ? ids.join(",") : 0}, table);
  361. }
  362. Fast.api.open(url, $(this).data("original-title") || $(this).attr("title") || __('Add'), $(this).data() || {});
  363. });
  364. // 导入按钮事件
  365. if ($(Table.config.importbtn, toolbar).length > 0) {
  366. require(['upload'], function (Upload) {
  367. Upload.api.upload($(Table.config.importbtn, toolbar), function (data, ret) {
  368. Fast.api.ajax({
  369. url: options.extend.import_url,
  370. data: {file: data.url},
  371. }, function (data, ret) {
  372. table.trigger("uncheckbox");
  373. table.bootstrapTable('refresh');
  374. });
  375. });
  376. });
  377. }
  378. // 批量编辑按钮事件
  379. toolbar.on('click', Table.config.editbtn, function () {
  380. var that = this;
  381. var ids = Table.api.selectedids(table);
  382. if (ids.length > 10) {
  383. return;
  384. }
  385. var title = $(that).data('title') || $(that).attr("title") || __('Edit');
  386. var data = $(that).data() || {};
  387. delete data.title;
  388. //循环弹出多个编辑框
  389. $.each(Table.api.selecteddata(table), function (index, row) {
  390. var url = options.extend.edit_url;
  391. row = $.extend({}, row ? row : {}, {ids: row[options.pk]});
  392. url = Table.api.replaceurl(url, row, table);
  393. Fast.api.open(url, typeof title === 'function' ? title.call(table, row) : title, data);
  394. });
  395. });
  396. //清空回收站
  397. $(document).on('click', Table.config.destroyallbtn, function () {
  398. var that = this;
  399. Layer.confirm(__('Are you sure you want to truncate?'), function () {
  400. var url = $(that).data("url") ? $(that).data("url") : $(that).attr("href");
  401. Fast.api.ajax(url, function () {
  402. Layer.closeAll();
  403. table.trigger("uncheckbox");
  404. table.bootstrapTable('refresh');
  405. }, function () {
  406. Layer.closeAll();
  407. });
  408. });
  409. return false;
  410. });
  411. //全部还原
  412. $(document).on('click', Table.config.restoreallbtn, function () {
  413. var that = this;
  414. var url = $(that).data("url") ? $(that).data("url") : $(that).attr("href");
  415. Fast.api.ajax(url, function () {
  416. Layer.closeAll();
  417. table.trigger("uncheckbox");
  418. table.bootstrapTable('refresh');
  419. }, function () {
  420. Layer.closeAll();
  421. });
  422. return false;
  423. });
  424. //销毁或删除
  425. $(document).on('click', Table.config.restoreonebtn + ',' + Table.config.destroyonebtn, function () {
  426. var that = this;
  427. var url = $(that).data("url") ? $(that).data("url") : $(that).attr("href");
  428. var row = Fast.api.getrowbyindex(table, $(that).data("row-index"));
  429. Fast.api.ajax({
  430. url: url,
  431. data: {ids: row[options.pk]}
  432. }, function () {
  433. table.trigger("uncheckbox");
  434. table.bootstrapTable('refresh');
  435. });
  436. return false;
  437. });
  438. // 批量操作按钮事件
  439. toolbar.on('click', Table.config.multibtn, function () {
  440. var ids = Table.api.selectedids(table);
  441. Table.api.multi($(this).data("action"), ids, table, this);
  442. });
  443. // 批量删除按钮事件
  444. toolbar.on('click', Table.config.delbtn, function () {
  445. var that = this;
  446. var ids = Table.api.selectedids(table);
  447. Layer.confirm(
  448. __('Are you sure you want to delete the %s selected item?', ids.length),
  449. {icon: 3, title: __('Warning'), offset: 0, shadeClose: true, btn: [__('OK'), __('Cancel')]},
  450. function (index) {
  451. Table.api.multi("del", ids, table, that);
  452. Layer.close(index);
  453. }
  454. );
  455. });
  456. // 拖拽排序
  457. require(['dragsort'], function () {
  458. //绑定拖动排序
  459. $("tbody", table).dragsort({
  460. itemSelector: 'tr:visible',
  461. dragSelector: "a.btn-dragsort",
  462. dragEnd: function (a, b) {
  463. var element = $("a.btn-dragsort", this);
  464. var data = table.bootstrapTable('getData');
  465. var current = data[parseInt($(this).data("index"))];
  466. var options = table.bootstrapTable('getOptions');
  467. //改变的值和改变的ID集合
  468. var ids = $.map($("tbody tr:visible", table), function (tr) {
  469. return data[parseInt($(tr).data("index"))][options.pk];
  470. });
  471. var changeid = current[options.pk];
  472. var pid = typeof current.pid != 'undefined' ? current.pid : '';
  473. var params = {
  474. url: table.bootstrapTable('getOptions').extend.dragsort_url,
  475. data: {
  476. ids: ids.join(','),
  477. changeid: changeid,
  478. pid: pid,
  479. field: Table.config.dragsortfield,
  480. orderway: options.sortOrder,
  481. table: options.extend.table,
  482. pk: options.pk
  483. }
  484. };
  485. Fast.api.ajax(params, function (data, ret) {
  486. var success = $(element).data("success") || $.noop;
  487. if (typeof success === 'function') {
  488. if (false === success.call(element, data, ret)) {
  489. return false;
  490. }
  491. }
  492. table.bootstrapTable('refresh');
  493. }, function (data, ret) {
  494. var error = $(element).data("error") || $.noop;
  495. if (typeof error === 'function') {
  496. if (false === error.call(element, data, ret)) {
  497. return false;
  498. }
  499. }
  500. table.bootstrapTable('refresh');
  501. });
  502. },
  503. placeHolderTemplate: ""
  504. });
  505. });
  506. table.on("click", "input[data-id][name='checkbox']", function (e) {
  507. var ids = $(this).data("id");
  508. table.bootstrapTable($(this).prop("checked") ? 'checkBy' : 'uncheckBy', {field: options.pk, values: [ids]});
  509. });
  510. table.on("click", "[data-id].btn-change", function (e) {
  511. e.preventDefault();
  512. var changer = $.proxy(function () {
  513. Table.api.multi($(this).data("action") ? $(this).data("action") : '', [$(this).data("id")], table, this);
  514. }, this);
  515. if (typeof $(this).data("confirm") !== 'undefined') {
  516. Layer.confirm($(this).data("confirm"), function (index) {
  517. changer();
  518. Layer.close(index);
  519. });
  520. } else {
  521. changer();
  522. }
  523. });
  524. table.on("click", "[data-id].btn-edit", function (e) {
  525. e.preventDefault();
  526. var ids = $(this).data("id");
  527. var row = Table.api.getrowbyid(table, ids);
  528. row.ids = ids;
  529. var url = Table.api.replaceurl(options.extend.edit_url, row, table);
  530. Fast.api.open(url, $(this).data("original-title") || $(this).attr("title") || __('Edit'), $(this).data() || {});
  531. });
  532. table.on("click", "[data-id].btn-del", function (e) {
  533. e.preventDefault();
  534. var id = $(this).data("id");
  535. var that = this;
  536. Layer.confirm(
  537. __('Are you sure you want to delete this item?'),
  538. {icon: 3, title: __('Warning'), shadeClose: true, btn: [__('OK'), __('Cancel')]},
  539. function (index) {
  540. Table.api.multi("del", id, table, that);
  541. Layer.close(index);
  542. }
  543. );
  544. });
  545. //修复dropdown定位溢出的情况
  546. if (options.fixDropdownPosition) {
  547. var tableBody = table.closest(".fixed-table-body");
  548. table.on('show.bs.dropdown fa.event.refreshdropdown', ".btn-group", function (e) {
  549. var dropdownMenu = $(".dropdown-menu", this);
  550. var btnGroup = $(this);
  551. var isPullRight = dropdownMenu.hasClass("pull-right") || dropdownMenu.hasClass("dropdown-menu-right");
  552. var left, top, position;
  553. if (true || dropdownMenu.outerHeight() + btnGroup.outerHeight() > tableBody.outerHeight() - 41) {
  554. position = 'fixed';
  555. top = btnGroup.offset().top - $(window).scrollTop() + btnGroup.outerHeight();
  556. if ((top + dropdownMenu.outerHeight()) > $(window).height()) {
  557. top = btnGroup.offset().top - dropdownMenu.outerHeight() - 5;
  558. }
  559. left = isPullRight ? btnGroup.offset().left + btnGroup.outerWidth() - dropdownMenu.outerWidth() : btnGroup.offset().left;
  560. }
  561. if (left || top) {
  562. dropdownMenu.css({
  563. position: position, left: left, top: top, right: 'inherit'
  564. });
  565. }
  566. });
  567. var checkdropdown = function () {
  568. if ($(".btn-group.open", table).length > 0 && $(".btn-group.open .dropdown-menu", table).css("position") == 'fixed') {
  569. $(".btn-group.open", table).trigger("fa.event.refreshdropdown");
  570. }
  571. };
  572. $(window).on("scroll", function () {
  573. checkdropdown();
  574. });
  575. tableBody.on("scroll", function () {
  576. checkdropdown();
  577. });
  578. }
  579. var id = table.attr("id");
  580. Table.list[id] = table;
  581. return table;
  582. },
  583. // 批量操作请求
  584. multi: function (action, ids, table, element) {
  585. var options = table.bootstrapTable('getOptions');
  586. var data = element ? $(element).data() : {};
  587. ids = ($.isArray(ids) ? ids.join(",") : ids);
  588. var url = typeof data.url !== "undefined" ? data.url : (action == "del" ? options.extend.del_url : options.extend.multi_url);
  589. var params = typeof data.params !== "undefined" ? (typeof data.params == 'object' ? $.param(data.params) : data.params) : '';
  590. options = {url: url, data: {action: action, ids: ids, params: params}};
  591. Fast.api.ajax(options, function (data, ret) {
  592. table.trigger("uncheckbox");
  593. var success = $(element).data("success") || $.noop;
  594. if (typeof success === 'function') {
  595. if (false === success.call(element, data, ret)) {
  596. return false;
  597. }
  598. }
  599. table.bootstrapTable('refresh');
  600. }, function (data, ret) {
  601. var error = $(element).data("error") || $.noop;
  602. if (typeof error === 'function') {
  603. if (false === error.call(element, data, ret)) {
  604. return false;
  605. }
  606. }
  607. });
  608. },
  609. // 单元格元素事件
  610. events: {
  611. operate: {
  612. 'click .btn-editone': function (e, value, row, index) {
  613. e.stopPropagation();
  614. e.preventDefault();
  615. var table = $(this).closest('table');
  616. var options = table.bootstrapTable('getOptions');
  617. var ids = row[options.pk];
  618. row = $.extend({}, row ? row : {}, {ids: ids});
  619. var url = options.extend.edit_url;
  620. Fast.api.open(Table.api.replaceurl(url, row, table), $(this).data("original-title") || $(this).attr("title") || __('Edit'), $(this).data() || {});
  621. },
  622. 'click .btn-delone': function (e, value, row, index) {
  623. e.stopPropagation();
  624. e.preventDefault();
  625. var that = this;
  626. var top = $(that).offset().top - $(window).scrollTop();
  627. var left = $(that).offset().left - $(window).scrollLeft() - 260;
  628. if (top + 154 > $(window).height()) {
  629. top = top - 154;
  630. }
  631. if ($(window).width() < 480) {
  632. top = left = undefined;
  633. }
  634. Layer.confirm(
  635. __('Are you sure you want to delete this item?'),
  636. {icon: 3, title: __('Warning'), offset: [top, left], shadeClose: true, btn: [__('OK'), __('Cancel')]},
  637. function (index) {
  638. var table = $(that).closest('table');
  639. var options = table.bootstrapTable('getOptions');
  640. Table.api.multi("del", row[options.pk], table, that);
  641. Layer.close(index);
  642. }
  643. );
  644. }
  645. },//单元格图片预览
  646. image: {
  647. 'click .img-center': function (e, value, row, index) {
  648. var data = [];
  649. value = value === null ? '' : value.toString();
  650. var arr = value != '' ? value.split(",") : [];
  651. var url;
  652. $.each(arr, function (index, value) {
  653. url = Fast.api.cdnurl(value);
  654. data.push({
  655. src: url,
  656. thumb: url.match(/^(\/|data:image\\)/) ? url : url + Config.upload.thumbstyle
  657. });
  658. });
  659. Layer.photos({
  660. photos: {
  661. "start": $(this).parent().index(),
  662. "data": data
  663. },
  664. anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)
  665. });
  666. },
  667. }
  668. },
  669. // 单元格数据格式化
  670. formatter: {
  671. icon: function (value, row, index) {
  672. value = value === null ? '' : value.toString();
  673. value = value.indexOf(" ") > -1 ? value : "fa fa-" + value;
  674. //渲染fontawesome图标
  675. return '<i class="' + value + '"></i> ' + value;
  676. },
  677. image: function (value, row, index) {
  678. value = value == null || value.length === 0 ? '' : value.toString();
  679. value = value ? value : '/assets/img/blank.gif';
  680. var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center';
  681. var url = Fast.api.cdnurl(value, true);
  682. url = url.match(/^(\/|data:image\\)/) ? url : url + Config.upload.thumbstyle;
  683. return '<a href="javascript:"><img class="' + classname + '" src="' + url + '" /></a>';
  684. },
  685. images: function (value, row, index) {
  686. value = value == null || value.length === 0 ? '' : value.toString();
  687. var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center';
  688. var arr = value != '' ? value.split(',') : [];
  689. var html = [];
  690. var url;
  691. $.each(arr, function (i, value) {
  692. value = value ? value : '/assets/img/blank.gif';
  693. url = Fast.api.cdnurl(value, true);
  694. url = url.match(/^(\/|data:image\\)/) ? url : url + Config.upload.thumbstyle;
  695. html.push('<a href="javascript:"><img class="' + classname + '" src="' + url + '" /></a>');
  696. });
  697. return html.join(' ');
  698. },
  699. file: function (value, row, index) {
  700. value = value == null || value.length === 0 ? '' : value.toString();
  701. value = Fast.api.cdnurl(value, true);
  702. var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center';
  703. var suffix = /[\.]?([a-zA-Z0-9]+)$/.exec(value);
  704. suffix = suffix ? suffix[1] : 'file';
  705. var url = Fast.api.fixurl("ajax/icon?suffix=" + suffix);
  706. return '<a href="' + value + '" target="_blank"><img src="' + url + '" class="' + classname + '"></a>';
  707. },
  708. files: function (value, row, index) {
  709. value = value == null || value.length === 0 ? '' : value.toString();
  710. var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center';
  711. var arr = value != '' ? value.split(',') : [];
  712. var html = [];
  713. var suffix, url;
  714. $.each(arr, function (i, value) {
  715. value = Fast.api.cdnurl(value, true);
  716. suffix = /[\.]?([a-zA-Z0-9]+)$/.exec(value);
  717. suffix = suffix ? suffix[1] : 'file';
  718. url = Fast.api.fixurl("ajax/icon?suffix=" + suffix);
  719. html.push('<a href="' + value + '" target="_blank"><img src="' + url + '" class="' + classname + '"></a>');
  720. });
  721. return html.join(' ');
  722. },
  723. content: function (value, row, index) {
  724. var width = this.width != undefined ? (this.width.match(/^\d+$/) ? this.width + "px" : this.width) : "250px";
  725. return "<div style='white-space: nowrap; text-overflow:ellipsis; overflow: hidden; max-width:" + width + ";'>" + value + "</div>";
  726. },
  727. status: function (value, row, index) {
  728. var custom = {normal: 'success', hidden: 'gray', deleted: 'danger', locked: 'info'};
  729. if (typeof this.custom !== 'undefined') {
  730. custom = $.extend(custom, this.custom);
  731. }
  732. this.custom = custom;
  733. this.icon = 'fa fa-circle';
  734. return Table.api.formatter.normal.call(this, value, row, index);
  735. },
  736. normal: function (value, row, index) {
  737. var colorArr = ["primary", "success", "danger", "warning", "info", "gray", "red", "yellow", "aqua", "blue", "navy", "teal", "olive", "lime", "fuchsia", "purple", "maroon"];
  738. var custom = {};
  739. if (typeof this.custom !== 'undefined') {
  740. custom = $.extend(custom, this.custom);
  741. }
  742. value = value == null || value.length === 0 ? '' : value.toString();
  743. var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : [];
  744. var index = keys.indexOf(value);
  745. var color = value && typeof custom[value] !== 'undefined' ? custom[value] : null;
  746. var display = index > -1 ? this.searchList[value] : null;
  747. var icon = typeof this.icon !== 'undefined' ? this.icon : null;
  748. if (!color) {
  749. color = index > -1 && typeof colorArr[index] !== 'undefined' ? colorArr[index] : 'primary';
  750. }
  751. if (!display) {
  752. display = __(value.charAt(0).toUpperCase() + value.slice(1));
  753. }
  754. var html = '<span class="text-' + color + '">' + (icon ? '<i class="' + icon + '"></i> ' : '') + display + '</span>';
  755. if (this.operate != false) {
  756. html = '<a href="javascript:;" class="searchit" data-toggle="tooltip" title="' + __('Click to search %s', display) + '" data-field="' + this.field + '" data-value="' + value + '">' + html + '</a>';
  757. }
  758. return html;
  759. },
  760. toggle: function (value, row, index) {
  761. var table = this.table;
  762. var options = table ? table.bootstrapTable('getOptions') : {};
  763. var pk = options.pk || "id";
  764. var color = typeof this.color !== 'undefined' ? this.color : 'success';
  765. var yes = typeof this.yes !== 'undefined' ? this.yes : 1;
  766. var no = typeof this.no !== 'undefined' ? this.no : 0;
  767. var url = typeof this.url !== 'undefined' ? this.url : '';
  768. var confirm = '';
  769. var disable = false;
  770. if (typeof this.confirm !== "undefined") {
  771. confirm = typeof this.confirm === "function" ? this.confirm.call(this, value, row, index) : this.confirm;
  772. }
  773. if (typeof this.disable !== "undefined") {
  774. disable = typeof this.disable === "function" ? this.disable.call(this, value, row, index) : this.disable;
  775. }
  776. return "<a href='javascript:;' data-toggle='tooltip' title='" + __('Click to toggle') + "' class='btn-change " + (disable ? 'btn disabled no-padding' : '') + "' data-index='" + index + "' data-id='"
  777. + row[pk] + "' " + (url ? "data-url='" + url + "'" : "") + (confirm ? "data-confirm='" + confirm + "'" : "") + " data-params='" + this.field + "=" + (value == yes ? no : yes) + "'><i class='fa fa-toggle-on text-success text-" + color + " " + (value == yes ? '' : 'fa-flip-horizontal text-gray') + " fa-2x'></i></a>";
  778. },
  779. url: function (value, row, index) {
  780. value = value == null || value.length === 0 ? '' : value.toString();
  781. return '<div class="input-group input-group-sm" style="width:250px;margin:0 auto;"><input type="text" class="form-control input-sm" value="' + value + '"><span class="input-group-btn input-group-sm"><a href="' + value + '" target="_blank" class="btn btn-default btn-sm"><i class="fa fa-link"></i></a></span></div>';
  782. },
  783. search: function (value, row, index) {
  784. var field = this.field;
  785. if (typeof this.customField !== 'undefined' && typeof row[this.customField] !== 'undefined') {
  786. value = row[this.customField];
  787. field = this.customField;
  788. }
  789. return '<a href="javascript:;" class="searchit" data-toggle="tooltip" title="' + __('Click to search %s', value) + '" data-field="' + field + '" data-value="' + value + '">' + value + '</a>';
  790. },
  791. addtabs: function (value, row, index) {
  792. var url = Table.api.replaceurl(this.url || '', row, this.table);
  793. var title = this.atitle ? this.atitle : __("Search %s", value);
  794. return '<a href="' + Fast.api.fixurl(url) + '" class="addtabsit" data-value="' + value + '" title="' + title + '">' + value + '</a>';
  795. },
  796. dialog: function (value, row, index) {
  797. var url = Table.api.replaceurl(this.url || '', row, this.table);
  798. var title = this.atitle ? this.atitle : __("View %s", value);
  799. return '<a href="' + Fast.api.fixurl(url) + '" class="dialogit" data-value="' + value + '" title="' + title + '">' + value + '</a>';
  800. },
  801. flag: function (value, row, index) {
  802. var that = this;
  803. value = value == null || value.length === 0 ? '' : value.toString();
  804. var colorArr = {index: 'success', hot: 'warning', recommend: 'danger', 'new': 'info'};
  805. //如果字段列有定义custom
  806. if (typeof this.custom !== 'undefined') {
  807. colorArr = $.extend(colorArr, this.custom);
  808. }
  809. var field = this.field;
  810. if (typeof this.customField !== 'undefined' && typeof row[this.customField] !== 'undefined') {
  811. value = row[this.customField];
  812. field = this.customField;
  813. }
  814. if (typeof that.searchList === 'object' && typeof that.custom === 'undefined') {
  815. var i = 0;
  816. var searchValues = Object.values(colorArr);
  817. $.each(that.searchList, function (key, val) {
  818. if (typeof colorArr[key] == 'undefined') {
  819. colorArr[key] = searchValues[i];
  820. i = typeof searchValues[i + 1] === 'undefined' ? 0 : i + 1;
  821. }
  822. });
  823. }
  824. //渲染Flag
  825. var html = [];
  826. var arr = value != '' ? value.split(',') : [];
  827. var color, display, label;
  828. $.each(arr, function (i, value) {
  829. value = value == null || value.length === 0 ? '' : value.toString();
  830. if (value == '')
  831. return true;
  832. color = value && typeof colorArr[value] !== 'undefined' ? colorArr[value] : 'primary';
  833. display = typeof that.searchList !== 'undefined' && typeof that.searchList[value] !== 'undefined' ? that.searchList[value] : __(value.charAt(0).toUpperCase() + value.slice(1));
  834. label = '<span class="label label-' + color + '">' + display + '</span>';
  835. if (that.operate) {
  836. html.push('<a href="javascript:;" class="searchit" data-toggle="tooltip" title="' + __('Click to search %s', display) + '" data-field="' + field + '" data-value="' + value + '">' + label + '</a>');
  837. } else {
  838. html.push(label);
  839. }
  840. });
  841. return html.join(' ');
  842. },
  843. label: function (value, row, index) {
  844. return Table.api.formatter.flag.call(this, value, row, index);
  845. },
  846. datetime: function (value, row, index) {
  847. var datetimeFormat = typeof this.datetimeFormat === 'undefined' ? 'YYYY-MM-DD HH:mm:ss' : this.datetimeFormat;
  848. if (isNaN(value)) {
  849. return value ? Moment(value).format(datetimeFormat) : __('None');
  850. } else {
  851. return value ? Moment(parseInt(value) * 1000).format(datetimeFormat) : __('None');
  852. }
  853. },
  854. operate: function (value, row, index) {
  855. var table = this.table;
  856. // 操作配置
  857. var options = table ? table.bootstrapTable('getOptions') : {};
  858. // 默认按钮组
  859. var buttons = $.extend([], this.buttons || []);
  860. // 所有按钮名称
  861. var names = [];
  862. buttons.forEach(function (item) {
  863. names.push(item.name);
  864. });
  865. if (options.extend.dragsort_url !== '' && names.indexOf('dragsort') === -1) {
  866. buttons.push(Table.button.dragsort);
  867. }
  868. if (options.extend.edit_url !== '' && names.indexOf('edit') === -1) {
  869. Table.button.edit.url = options.extend.edit_url;
  870. buttons.push(Table.button.edit);
  871. }
  872. if (options.extend.del_url !== '' && names.indexOf('del') === -1) {
  873. buttons.push(Table.button.del);
  874. }
  875. return Table.api.buttonlink(this, buttons, value, row, index, 'operate');
  876. }
  877. ,
  878. buttons: function (value, row, index) {
  879. // 默认按钮组
  880. var buttons = $.extend([], this.buttons || []);
  881. return Table.api.buttonlink(this, buttons, value, row, index, 'buttons');
  882. }
  883. },
  884. buttonlink: function (column, buttons, value, row, index, type) {
  885. var table = column.table;
  886. column.clickToSelect = false;
  887. type = typeof type === 'undefined' ? 'buttons' : type;
  888. var options = table ? table.bootstrapTable('getOptions') : {};
  889. var html = [];
  890. var hidden, visible, disable, url, classname, icon, text, title, refresh, confirm, extend,
  891. dropdown, link;
  892. var fieldIndex = column.fieldIndex;
  893. var dropdowns = {};
  894. $.each(buttons, function (i, j) {
  895. if (type === 'operate') {
  896. if (j.name === 'dragsort' && typeof row[Table.config.dragsortfield] === 'undefined') {
  897. return true;
  898. }
  899. if (['add', 'edit', 'del', 'multi', 'dragsort'].indexOf(j.name) > -1 && !options.extend[j.name + "_url"]) {
  900. return true;
  901. }
  902. }
  903. var attr = table.data(type + "-" + j.name);
  904. if (typeof attr === 'undefined' || attr) {
  905. hidden = typeof j.hidden === 'function' ? j.hidden.call(table, row, j) : (typeof j.hidden !== 'undefined' ? j.hidden : false);
  906. if (hidden) {
  907. return true;
  908. }
  909. visible = typeof j.visible === 'function' ? j.visible.call(table, row, j) : (typeof j.visible !== 'undefined' ? j.visible : true);
  910. if (!visible) {
  911. return true;
  912. }
  913. dropdown = j.dropdown ? j.dropdown : '';
  914. url = j.url ? j.url : '';
  915. url = typeof url === 'function' ? url.call(table, row, j) : (url ? Fast.api.fixurl(Table.api.replaceurl(url, row, table)) : 'javascript:;');
  916. classname = j.classname ? j.classname : (dropdown ? 'btn-' + name + 'one' : 'btn-primary btn-' + name + 'one');
  917. icon = j.icon ? j.icon : '';
  918. text = typeof j.text === 'function' ? j.text.call(table, row, j) : j.text ? j.text : '';
  919. title = typeof j.title === 'function' ? j.title.call(table, row, j) : j.title ? j.title : text;
  920. refresh = j.refresh ? 'data-refresh="' + j.refresh + '"' : '';
  921. confirm = typeof j.confirm === 'function' ? j.confirm.call(table, row, j) : (typeof j.confirm !== 'undefined' ? j.confirm : false);
  922. confirm = confirm ? 'data-confirm="' + confirm + '"' : '';
  923. extend = typeof j.extend === 'function' ? j.extend.call(table, row, j) : (typeof j.extend !== 'undefined' ? j.extend : '');
  924. disable = typeof j.disable === 'function' ? j.disable.call(table, row, j) : (typeof j.disable !== 'undefined' ? j.disable : false);
  925. if (disable) {
  926. classname = classname + ' disabled';
  927. }
  928. link = '<a href="' + url + '" class="' + classname + '" ' + (confirm ? confirm + ' ' : '') + (refresh ? refresh + ' ' : '') + extend + ' title="' + title + '" data-table-id="' + (table ? table.attr("id") : '') + '" data-field-index="' + fieldIndex + '" data-row-index="' + index + '" data-button-index="' + i + '"><i class="' + icon + '"></i>' + (text ? ' ' + text : '') + '</a>';
  929. if (dropdown) {
  930. if (typeof dropdowns[dropdown] == 'undefined') {
  931. dropdowns[dropdown] = [];
  932. }
  933. dropdowns[dropdown].push(link);
  934. } else {
  935. html.push(link);
  936. }
  937. }
  938. });
  939. if (!$.isEmptyObject(dropdowns)) {
  940. var dropdownHtml = [];
  941. $.each(dropdowns, function (i, j) {
  942. dropdownHtml.push('<div class="btn-group"><button type="button" class="btn btn-primary dropdown-toggle btn-xs" data-toggle="dropdown">' + i + '</button><button type="button" class="btn btn-primary dropdown-toggle btn-xs" data-toggle="dropdown"><span class="caret"></span></button><ul class="dropdown-menu dropdown-menu-right"><li>' + j.join('</li><li>') + '</li></ul></div>');
  943. });
  944. html.unshift(dropdownHtml);
  945. }
  946. return html.join(' ');
  947. },
  948. //替换URL中的数据
  949. replaceurl: function (url, row, table) {
  950. var options = table ? table.bootstrapTable('getOptions') : null;
  951. var ids = options ? row[options.pk] : 0;
  952. row.ids = ids ? ids : (typeof row.ids !== 'undefined' ? row.ids : 0);
  953. url = url == null || url.length === 0 ? '' : url.toString();
  954. //自动添加ids参数
  955. url = !url.match(/(?=([?&]ids=)|(\/ids\/)|(\{ids}))/i) ?
  956. url + (url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + '{ids}' : url;
  957. url = url.replace(/\{(.*?)\}/gi, function (matched) {
  958. matched = matched.substring(1, matched.length - 1);
  959. if (matched.indexOf(".") !== -1) {
  960. var temp = row;
  961. var arr = matched.split(/\./);
  962. for (var i = 0; i < arr.length; i++) {
  963. if (typeof temp[arr[i]] !== 'undefined') {
  964. temp = temp[arr[i]];
  965. }
  966. }
  967. return typeof temp === 'object' ? '' : temp;
  968. }
  969. return row[matched];
  970. });
  971. return url;
  972. },
  973. // 获取选中的条目ID集合
  974. selectedids: function (table, current) {
  975. var options = table.bootstrapTable('getOptions');
  976. //如果有设置翻页记忆模式
  977. if (!current && options.maintainSelected) {
  978. return options.selectedIds;
  979. }
  980. return $.map(table.bootstrapTable('getSelections'), function (row) {
  981. return row[options.pk];
  982. });
  983. },
  984. //获取选中的数据
  985. selecteddata: function (table, current) {
  986. var options = table.bootstrapTable('getOptions');
  987. //如果有设置翻页记忆模式
  988. if (!current && options.maintainSelected) {
  989. return options.selectedData;
  990. }
  991. return table.bootstrapTable('getSelections');
  992. },
  993. // 切换复选框状态
  994. toggleattr: function (table) {
  995. $("input[type='checkbox']", table).trigger('click');
  996. },
  997. // 根据行索引获取行数据
  998. getrowdata: function (table, index) {
  999. index = parseInt(index);
  1000. var data = table.bootstrapTable('getData');
  1001. return typeof data[index] !== 'undefined' ? data[index] : null;
  1002. },
  1003. // 根据行索引获取行数据
  1004. getrowbyindex: function (table, index) {
  1005. return Table.api.getrowdata(table, index);
  1006. },
  1007. // 根据主键ID获取行数据
  1008. getrowbyid: function (table, id) {
  1009. var row = {};
  1010. var options = table.bootstrapTable("getOptions");
  1011. $.each(Table.api.selecteddata(table), function (i, j) {
  1012. if (j[options.pk] == id) {
  1013. row = j;
  1014. return false;
  1015. }
  1016. });
  1017. return row;
  1018. }
  1019. },
  1020. };
  1021. return Table;
  1022. });