steps.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'task/steps/index' + location.search,
  8. add_url: 'task/steps/add',
  9. edit_url: 'task/steps/edit',
  10. del_url: 'task/steps/del',
  11. multi_url: 'task/steps/multi',
  12. import_url: 'task/steps/import',
  13. table: 'task_steps',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'weigh',
  22. fixedColumns: true,
  23. fixedRightNumber: 1,
  24. columns: [
  25. [
  26. {field: 'state', checkbox: true,},
  27. {field: 'id', title: 'ID'},
  28. {
  29. field: 'name',
  30. title: __('名称'),
  31. align: 'left',
  32. },
  33. {field: 'start_time', title: __('开始时间'), align: 'left',},
  34. {field: 'end_time', title: __('结束时间'), align: 'left'},
  35. {
  36. field: 'operate',
  37. title: __('Operate'),
  38. table: table,
  39. events: Table.api.events.operate,
  40. formatter: Table.api.formatter.operate
  41. }
  42. ]
  43. ]
  44. });
  45. // 为表格绑定事件
  46. Table.api.bindevent(table);
  47. },
  48. add: function () {
  49. Controller.api.bindevent();
  50. },
  51. edit: function () {
  52. Controller.api.bindevent();
  53. },
  54. a:function () {
  55. // 初始化表格参数配置
  56. Table.api.init({
  57. extend: {
  58. "index_url": "task/task/detail",
  59. "add_url": "auth/rule/add",
  60. "edit_url": "auth/rule/edit",
  61. "del_url": "auth/rule/del",
  62. "multi_url": "auth/rule/multi",
  63. "table": "task_steps"
  64. }
  65. });
  66. var table = $("#table");
  67. // 初始化表格
  68. table.bootstrapTable({
  69. url: $.fn.bootstrapTable.defaults.extend.index_url,
  70. sortName: '',
  71. escape: false,
  72. columns: [
  73. [
  74. {field: 'state', checkbox: true,},
  75. {field: 'id', title: 'ID'},
  76. {
  77. field: 'name',
  78. title: __('名称'),
  79. align: 'left',
  80. },
  81. // {field: 'start-time', title: __('开始时间'), align: 'left',},
  82. // {field: 'end-time', title: __('结束时间'), align: 'left'},
  83. {
  84. field: 'operate',
  85. title: __('Operate'),
  86. table: table,
  87. events: Table.api.events.operate,
  88. formatter: Table.api.formatter.operate
  89. }
  90. ]
  91. ],
  92. pagination: false,
  93. search: false,
  94. commonSearch: false,
  95. rowAttributes: function (row, index) {
  96. return row.pid == 0 ? {} : {style: "display:none"};
  97. }
  98. });
  99. // 为表格绑定事件
  100. Table.api.bindevent(table);
  101. var btnSuccessEvent = function (data, ret) {
  102. if ($(this).hasClass("btn-change")) {
  103. var index = $(this).data("index");
  104. var row = Table.api.getrowbyindex(table, index);
  105. row.ismenu = $("i.fa.text-gray", this).length > 0 ? 1 : 0;
  106. table.bootstrapTable("updateRow", {index: index, row: row});
  107. } else if ($(this).hasClass("btn-delone")) {
  108. if ($(this).closest("tr[data-index]").find("a.btn-node-sub.disabled").length > 0) {
  109. $(this).closest("tr[data-index]").remove();
  110. } else {
  111. table.bootstrapTable('refresh');
  112. }
  113. } else if ($(this).hasClass("btn-dragsort")) {
  114. table.bootstrapTable('refresh');
  115. }
  116. Fast.api.refreshmenu();
  117. return false;
  118. };
  119. //表格内容渲染前
  120. table.on('pre-body.bs.table', function (e, data) {
  121. var options = table.bootstrapTable("getOptions");
  122. options.escape = true;
  123. });
  124. //当内容渲染完成后
  125. table.on('post-body.bs.table', function (e, data) {
  126. var options = table.bootstrapTable("getOptions");
  127. options.escape = false;
  128. //点击切换/排序/删除操作后刷新左侧菜单
  129. $(".btn-change[data-id],.btn-delone,.btn-dragsort").data("success", btnSuccessEvent);
  130. });
  131. table.on('post-body.bs.table', function (e, settings, json, xhr) {
  132. //显示隐藏子节点
  133. $(">tbody>tr[data-index] > td", this).on('click', "a.btn-node-sub", function () {
  134. var status = $(this).data("shown") ? true : false;
  135. $("a[data-pid='" + $(this).data("id") + "']").each(function () {
  136. $(this).closest("tr").toggle(!status);
  137. });
  138. if (status) {
  139. $("a[data-pid='" + $(this).data("id") + "']").trigger("collapse");
  140. }
  141. $(this).data("shown", !status);
  142. $("i", this).toggleClass("fa-caret-down").toggleClass("fa-caret-right");
  143. return false;
  144. });
  145. });
  146. //隐藏子节点
  147. $(document).on("collapse", ".btn-node-sub", function () {
  148. if ($("i", this).length > 0) {
  149. $("a[data-pid='" + $(this).data("id") + "']").trigger("collapse");
  150. }
  151. $("i", this).removeClass("fa-caret-down").addClass("fa-caret-right");
  152. $(this).data("shown", false);
  153. $(this).closest("tr").toggle(false);
  154. });
  155. //批量删除后的回调
  156. $(".toolbar > .btn-del,.toolbar .btn-more~ul>li>a").data("success", function (e) {
  157. Fast.api.refreshmenu();
  158. });
  159. //展开隐藏一级
  160. $(document.body).on("click", ".btn-toggle", function (e) {
  161. $("a[data-id][data-pid][data-pid!=0].disabled").closest("tr").hide();
  162. var that = this;
  163. var show = $("i", that).hasClass("fa-chevron-down");
  164. $("i", that).toggleClass("fa-chevron-down", !show).toggleClass("fa-chevron-up", show);
  165. $("a[data-id][data-pid][data-pid!=0]").not('.disabled').closest("tr").toggle(show);
  166. $(".btn-node-sub[data-pid=0]").data("shown", show);
  167. });
  168. //展开隐藏全部
  169. $(document.body).on("click", ".btn-toggle-all", function (e) {
  170. var that = this;
  171. var show = $("i", that).hasClass("fa-plus");
  172. $("i", that).toggleClass("fa-plus", !show).toggleClass("fa-minus", show);
  173. $(".btn-node-sub:not([data-pid=0])").closest("tr").toggle(show);
  174. $(".btn-node-sub").data("shown", show);
  175. $(".btn-node-sub > i").toggleClass("fa-caret-down", show).toggleClass("fa-caret-right", !show);
  176. });
  177. Controller.api.bindevent();
  178. },
  179. api: {
  180. bindevent: function () {
  181. Form.api.bindevent($("form[role=form]"));
  182. }
  183. }
  184. };
  185. return Controller;
  186. });