rule.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. columns: [
  22. [
  23. {checkbox: true},
  24. {field: 'id', title: __('Id')},
  25. {field: 'pid', title: __('Pid'), visible: false},
  26. {field: 'title', title: __('Title'), align: 'left', formatter:function (value, row, index) {
  27. return value.toString().replace(/(&|&)nbsp;/g, ' ');
  28. }
  29. },
  30. {field: 'name', title: __('Name'), align: 'left'},
  31. {field: 'remark', title: __('Remark')},
  32. {field: 'ismenu', title: __('Ismenu'), formatter: Table.api.formatter.toggle},
  33. {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true, visible: false},
  34. {field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true, visible: false},
  35. {field: 'weigh', title: __('Weigh')},
  36. {field: 'status', title: __('Status'), formatter: Table.api.formatter.status},
  37. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  38. ]
  39. ],
  40. pagination: false,
  41. search: false,
  42. commonSearch: false,
  43. });
  44. // 为表格绑定事件
  45. Table.api.bindevent(table);
  46. },
  47. add: function () {
  48. Controller.api.bindevent();
  49. },
  50. edit: function () {
  51. Controller.api.bindevent();
  52. },
  53. api: {
  54. bindevent: function () {
  55. $(document).on('click', "input[name='row[ismenu]']", function () {
  56. var name = $("input[name='row[name]']");
  57. name.prop("placeholder", $(this).val() == 1 ? name.data("placeholder-menu") : name.data("placeholder-node"));
  58. });
  59. $("input[name='row[ismenu]']:checked").trigger("click");
  60. Form.api.bindevent($("form[role=form]"));
  61. }
  62. }
  63. };
  64. return Controller;
  65. });