rule.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function ($, undefined, Backend, Table, Form, Template) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. "index_url": "auth/rule/index",
  8. "add_url": "auth/rule/add",
  9. "edit_url": "auth/rule/edit",
  10. "del_url": "auth/rule/del",
  11. "multi_url": "auth/rule/multi",
  12. "table": "auth_rule"
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. sortName: 'weigh',
  20. columns: [
  21. [
  22. {field: 'state', checkbox: true, },
  23. {field: 'id', title: 'ID'},
  24. {field: 'title', title: __('Title'), align: 'left'},
  25. {field: 'icon', title: __('Icon'), formatter: Controller.api.formatter.icon},
  26. {field: 'name', title: __('Name'), align: 'left'},
  27. {field: 'ismenu', title: __('Ismenu'), align: 'left'},
  28. {field: 'weigh', title: __('Weigh')},
  29. {field: 'status', title: __('Status'), formatter: Table.api.formatter.status},
  30. {field: 'id', title: '<a href="javascript:;" class="btn btn-primary btn-xs btn-toggle"><i class="fa fa-chevron-down"></i></a>', operate: false, formatter: Controller.api.formatter.subnode},
  31. {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  32. ]
  33. ],
  34. pagination: false,
  35. search: false,
  36. commonSearch: false,
  37. });
  38. // 为表格绑定事件
  39. Table.api.bindevent(table);//当内容渲染完成后
  40. //默认隐藏所有子节点
  41. table.on('post-body.bs.table', function (e, settings, json, xhr) {
  42. $("a.btn[data-id][data-pid][data-pid!=0]").closest("tr").hide();
  43. });
  44. //显示隐藏子节点
  45. $(document.body).on("click", ".btn-node-sub", function (e) {
  46. var status = typeof status !== 'undefined' ? status : $(this).closest("tr").hasClass("selected");
  47. $("a.btn[data-pid='" + $(this).data("id") + "']").each(function () {
  48. $(this).closest("tr").toggle(status).toggleClass("selected", status);
  49. $(this).closest("tr").find("input[type=checkbox]").prop("checked", status);
  50. // 展示全部子节点
  51. // $(this).trigger("click", status);
  52. });
  53. return false;
  54. });
  55. $(document.body).on("click", ".btn-toggle", function (e) {
  56. $("a.btn[data-id][data-pid][data-pid!=0].disabled").closest("tr").hide();
  57. var that = this;
  58. var show = $("i", that).hasClass("fa-chevron-down");
  59. $("i", that).toggleClass("fa-chevron-down", !show);
  60. $("i", that).toggleClass("fa-chevron-up", show);
  61. $("a.btn[data-id][data-pid][data-pid!=0]").not('.disabled').closest("tr").toggle(show);
  62. });
  63. $(document.body).on("click", ".btn-toggle-all", function (e) {
  64. var that = this;
  65. var show = $("i", that).hasClass("fa-plus");
  66. $("i", that).toggleClass("fa-plus", !show);
  67. $("i", that).toggleClass("fa-minus", show);
  68. $("a.btn[data-id][data-pid][data-pid!=0]").closest("tr").toggle(show);
  69. });
  70. },
  71. add: function () {
  72. Controller.api.bindevent();
  73. },
  74. edit: function () {
  75. Controller.api.bindevent();
  76. },
  77. api: {
  78. formatter: {
  79. icon: function (value, row, index) {
  80. return '<i class="' + value + '"></i>';
  81. },
  82. subnode: function (value, row, index) {
  83. return '<a href="javascript:;" data-id="' + row['id'] + '" data-pid="' + row['pid'] + '" class="btn btn-primary btn-xs ' + (row['haschild'] == 1 ? '' : 'disabled') + ' btn-node-sub"><i class="fa fa-sitemap"></i></a>';
  84. }
  85. },
  86. bindevent: function () {
  87. var iconlist = [];
  88. Form.api.bindevent($("form[role=form]"));
  89. $(document).on('click', ".btn-search-icon", function () {
  90. if (iconlist.length == 0) {
  91. $.get(Config.site.cdnurl + "/assets/libs/font-awesome/less/variables.less", function (ret) {
  92. var exp = /fa-var-(.*):/ig;
  93. var result;
  94. while ((result = exp.exec(ret)) != null) {
  95. iconlist.push(result[1]);
  96. }
  97. Layer.open({
  98. type: 1,
  99. area: ['460px', '300px'], //宽高
  100. content: Template('chooseicontpl', {iconlist: iconlist})
  101. });
  102. });
  103. } else {
  104. Layer.open({
  105. type: 1,
  106. area: ['460px', '300px'], //宽高
  107. content: Template('chooseicontpl', {iconlist: iconlist})
  108. });
  109. }
  110. });
  111. $(document).on('click', '#chooseicon ul li', function () {
  112. $("input[name='row[icon]']").val('fa fa-' + $(this).data("font"));
  113. Layer.closeAll();
  114. });
  115. $(document).on('keyup', 'input.js-icon-search', function () {
  116. $("#chooseicon ul li").show();
  117. if ($(this).val() != '') {
  118. $("#chooseicon ul li:not([data-font*='" + $(this).val() + "'])").hide();
  119. }
  120. });
  121. }
  122. }
  123. };
  124. return Controller;
  125. });