rule.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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', align: 'left', formatter: Controller.api.formatter.title},
  25. {field: 'icon', title: __('Icon'), formatter: Controller.api.formatter.icon},
  26. {field: 'name', title: __('Name'), align: 'left', formatter: Controller.api.formatter.name},
  27. {field: 'weigh', title: __('Weigh')},
  28. {field: 'status', title: __('Status'), formatter: Table.api.formatter.status},
  29. {field: 'ismenu', title: __('Ismenu'), align: 'center', formatter: Controller.api.formatter.menu},
  30. {field: 'id', title: '<a href="javascript:;" class="btn btn-success btn-xs btn-toggle"><i class="fa fa-chevron-up"></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. $(".btn-node-sub.disabled").closest("tr").hide();
  44. //显示隐藏子节点
  45. $(".btn-node-sub").off("click").on("click", function (e) {
  46. var status = $(this).data("shown") ? true : false;
  47. $("a.btn[data-pid='" + $(this).data("id") + "']").each(function () {
  48. $(this).closest("tr").toggle(!status);
  49. });
  50. $(this).data("shown", !status);
  51. return false;
  52. });
  53. });
  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. $(".btn-node-sub[data-pid=0]").data("shown", show);
  63. });
  64. //展开隐藏全部
  65. $(document.body).on("click", ".btn-toggle-all", function (e) {
  66. var that = this;
  67. var show = $("i", that).hasClass("fa-plus");
  68. $("i", that).toggleClass("fa-plus", !show);
  69. $("i", that).toggleClass("fa-minus", show);
  70. $(".btn-node-sub.disabled").closest("tr").toggle(show);
  71. $(".btn-node-sub").data("shown", show);
  72. });
  73. },
  74. add: function () {
  75. Controller.api.bindevent();
  76. },
  77. edit: function () {
  78. Controller.api.bindevent();
  79. },
  80. api: {
  81. formatter: {
  82. title: function (value, row, index) {
  83. return !row.ismenu ? "<span class='text-muted'>" + value + "</span>" : value;
  84. },
  85. name: function (value, row, index) {
  86. return !row.ismenu ? "<span class='text-muted'>" + value + "</span>" : value;
  87. },
  88. menu: function (value, row, index) {
  89. return "<a href='javascript:;' class='btn btn-" + (value ? "info" : "default") + " btn-xs btn-change' data-id='"
  90. + row.id + "' data-params='ismenu=" + (value ? 0 : 1) + "'>" + (value ? __('Yes') : __('No')) + "</a>";
  91. },
  92. icon: function (value, row, index) {
  93. return '<i class="' + value + '"></i>';
  94. },
  95. subnode: function (value, row, index) {
  96. return '<a href="javascript:;" data-id="' + row['id'] + '" data-pid="' + row['pid'] + '" class="btn btn-xs '
  97. + (row['haschild'] == 1 ? 'btn-success' : 'btn-default disabled') + ' btn-node-sub"><i class="fa fa-sitemap"></i></a>';
  98. }
  99. },
  100. bindevent: function () {
  101. var iconlist = [];
  102. Form.api.bindevent($("form[role=form]"));
  103. $(document).on('click', ".btn-search-icon", function () {
  104. if (iconlist.length == 0) {
  105. $.get(Config.site.cdnurl + "/assets/libs/font-awesome/less/variables.less", function (ret) {
  106. var exp = /fa-var-(.*):/ig;
  107. var result;
  108. while ((result = exp.exec(ret)) != null) {
  109. iconlist.push(result[1]);
  110. }
  111. Layer.open({
  112. type: 1,
  113. area: ['460px', '300px'], //宽高
  114. content: Template('chooseicontpl', {iconlist: iconlist})
  115. });
  116. });
  117. } else {
  118. Layer.open({
  119. type: 1,
  120. area: ['460px', '300px'], //宽高
  121. content: Template('chooseicontpl', {iconlist: iconlist})
  122. });
  123. }
  124. });
  125. $(document).on('click', '#chooseicon ul li', function () {
  126. $("input[name='row[icon]']").val('fa fa-' + $(this).data("font"));
  127. Layer.closeAll();
  128. });
  129. $(document).on('keyup', 'input.js-icon-search', function () {
  130. $("#chooseicon ul li").show();
  131. if ($(this).val() != '') {
  132. $("#chooseicon ul li:not([data-font*='" + $(this).val() + "'])").hide();
  133. }
  134. });
  135. }
  136. }
  137. };
  138. return Controller;
  139. });