rule.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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: 'user/rule/index',
  8. add_url: 'user/rule/add',
  9. edit_url: 'user/rule/edit',
  10. del_url: 'user/rule/del',
  11. multi_url: 'user/rule/multi',
  12. table: 'user_rule',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'weigh',
  21. escape: false,
  22. columns: [
  23. [
  24. {checkbox: true},
  25. {field: 'id', title: __('Id')},
  26. {field: 'pid', title: __('Pid'), visible: false},
  27. {field: 'title', title: __('Title'), align: 'left'},
  28. {field: 'name', title: __('Name'), align: 'left'},
  29. {field: 'remark', title: __('Remark')},
  30. {field: 'ismenu', title: __('Ismenu'), formatter: Table.api.formatter.toggle},
  31. {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true, visible: false},
  32. {field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true, visible: false},
  33. {field: 'weigh', title: __('Weigh')},
  34. {field: 'status', title: __('Status'), formatter: Table.api.formatter.status},
  35. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  36. ]
  37. ],
  38. pagination: false,
  39. search: false,
  40. commonSearch: false,
  41. });
  42. // 为表格绑定事件
  43. Table.api.bindevent(table);
  44. },
  45. add: function () {
  46. Controller.api.bindevent();
  47. },
  48. edit: function () {
  49. Controller.api.bindevent();
  50. },
  51. api: {
  52. bindevent: function () {
  53. $(document).on('click', "input[name='row[ismenu]']", function () {
  54. var name = $("input[name='row[name]']");
  55. name.prop("placeholder", $(this).val() == 1 ? name.data("placeholder-menu") : name.data("placeholder-node"));
  56. });
  57. $("input[name='row[ismenu]']:checked").trigger("click");
  58. Form.api.bindevent($("form[role=form]"));
  59. }
  60. }
  61. };
  62. return Controller;
  63. });