block.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. showToggle:false,
  7. showColumns:false,
  8. showExport:false,
  9. commonSearch:false,
  10. });
  11. //绑定事件
  12. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  13. var panel = $($(this).attr("href"));
  14. if (panel.size() > 0) {
  15. Controller.table[panel.attr("id")].call(this);
  16. $(this).on('click', function (e) {
  17. $($(this).attr("href")).find(".btn-refresh").trigger("click");
  18. });
  19. }
  20. //移除绑定的事件
  21. $(this).unbind('shown.bs.tab');
  22. });
  23. //必须默认触发shown.bs.tab事件
  24. $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
  25. },
  26. table: {
  27. first: function () {
  28. // 表格1
  29. var table = $("#table");
  30. table.bootstrapTable({
  31. url: 'clientmanage/bookcity/block/index?page_id=1',
  32. extend:{
  33. index_url: 'clientmanage/bookcity/block/index',
  34. add_url: 'clientmanage/bookcity/block/add?page_id=1',
  35. edit_url: 'clientmanage/bookcity/block/edit',
  36. del_url: 'clientmanage/bookcity/block/del',
  37. table: 'client_manage_block',
  38. },
  39. pk: 'id',
  40. toolbar: '#toolbar1',
  41. sortName: 'weigh',
  42. search: false,
  43. columns: [
  44. [
  45. {checkbox: true},
  46. {field: 'id', title: __('Id')},
  47. {field: 'name', title: __('Name')},
  48. {field: 'second_name', title: __('Second_name')},
  49. {field: 'type_text', title: __('Type')},
  50. {field: 'weigh', title: __('Weigh')},
  51. {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime},
  52. {field: 'id', title: __('Blocklist'),formatter: Controller.api.formatter.id},
  53. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  54. ]
  55. ]
  56. });
  57. // 为表格1绑定事件
  58. Table.api.bindevent(table);
  59. Controller.api.bindevent();
  60. },
  61. second: function () {
  62. // 表格2
  63. var table2 = $("#table2");
  64. table2.bootstrapTable({
  65. url: 'clientmanage/bookcity/block/index?page_id=2',
  66. extend:{
  67. index_url: 'clientmanage/bookcity/block/index',
  68. add_url: 'clientmanage/bookcity/block/add?page_id=2',
  69. edit_url: 'clientmanage/bookcity/block/edit',
  70. del_url: 'clientmanage/bookcity/block/del',
  71. table: 'client_manage_block',
  72. },
  73. pk: 'id',
  74. toolbar: '#toolbar2',
  75. sortName: 'weigh',
  76. search: false,
  77. columns: [
  78. [
  79. {checkbox: true},
  80. {field: 'id', title: __('Id')},
  81. {field: 'name', title: __('Name')},
  82. {field: 'second_name', title: __('Second_name')},
  83. {field: 'type_text', title: __('Type')},
  84. {field: 'weigh', title: __('Weigh')},
  85. {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime},
  86. {field: 'id', title: __('Blocklist'),formatter: Controller.api.formatter.id},
  87. {field: 'operate', title: __('Operate'), table: table2, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  88. ]
  89. ]
  90. });
  91. // 为表格2绑定事件
  92. Table.api.bindevent(table2);
  93. Controller.api.bindevent();
  94. },
  95. three: function () {
  96. // 表格3
  97. var table3 = $("#table3");
  98. table3.bootstrapTable({
  99. url: 'clientmanage/bookcity/block/index?page_id=3',
  100. extend:{
  101. index_url: 'clientmanage/bookcity/block/index',
  102. add_url: 'clientmanage/bookcity/block/add?page_id=3',
  103. edit_url: 'clientmanage/bookcity/block/edit?page_id=3',
  104. del_url: 'clientmanage/bookcity/block/del?page_id=3',
  105. table: 'client_manage_block',
  106. },
  107. pk: 'id',
  108. toolbar: '#toolbar3',
  109. sortName: 'weigh',
  110. search: false,
  111. columns: [
  112. [
  113. {checkbox: true},
  114. {field: 'id', title: __('Id')},
  115. {field: 'name', title: __('Name')},
  116. {field: 'second_name', title: __('Second_name')},
  117. {field: 'type_text', title: __('Type')},
  118. {field: 'weigh', title: __('Weigh')},
  119. {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime},
  120. {field: 'id', title: __('Blocklist'),formatter: Controller.api.formatter.id},
  121. {field: 'operate', title: __('Operate'), table: table3, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  122. ]
  123. ]
  124. });
  125. // 为表格3绑定事件
  126. Table.api.bindevent(table3);
  127. Controller.api.bindevent();
  128. },
  129. four: function () {
  130. // 表格4
  131. var table4 = $("#table4");
  132. table4.bootstrapTable({
  133. url: 'clientmanage/bookcity/block/index?page_id=4',
  134. extend:{
  135. index_url: 'clientmanage/bookcity/block/index',
  136. add_url: 'clientmanage/bookcity/block/add?page_id=4',
  137. edit_url: 'clientmanage/bookcity/block/edit?page_id=4',
  138. del_url: 'clientmanage/bookcity/block/del?page_id=4',
  139. table: 'client_manage_block',
  140. },
  141. pk: 'id',
  142. toolbar: '#toolbar4',
  143. sortName: 'weigh',
  144. search: false,
  145. columns: [
  146. [
  147. {checkbox: true},
  148. {field: 'id', title: __('Id')},
  149. {field: 'name', title: __('Name')},
  150. {field: 'second_name', title: __('Second_name')},
  151. {field: 'type_text', title: __('Type')},
  152. {field: 'weigh', title: __('Weigh')},
  153. {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime},
  154. {field: 'id', title: __('Blocklist'),formatter: Controller.api.formatter.id},
  155. {field: 'operate', title: __('Operate'), table: table4, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  156. ]
  157. ]
  158. });
  159. // 为表格4绑定事件
  160. Table.api.bindevent(table4);
  161. Controller.api.bindevent();
  162. }
  163. },
  164. add: function () {
  165. Controller.api.bindevent();
  166. },
  167. edit: function () {
  168. Controller.api.bindevent();
  169. },
  170. api: {
  171. bindevent: function () {
  172. Form.api.bindevent($("form[role=form]"));
  173. },
  174. formatter: {
  175. id: function (value, row, index) {
  176. //这里手动构造URL
  177. url = "clientmanage/bookcity/blockresource?block_id=" + value+'&page_id='+row.page_id;
  178. return '<a href="' + url + '" class="label label-success addtabsit" title="' + __("Search %s", value) + '">资源列表</a>';
  179. }
  180. }
  181. }
  182. };
  183. return Controller;
  184. });