rule.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. define(['jquery', 'table', 'form', 'iconPicker'], function($, Table, Form, iconPicker) {
  2. var Controller = {
  3. index: function() {
  4. Table.init = {
  5. table_elem: '#currentTable',
  6. table_render_id: 'currentTable',
  7. multi_url: 'auth.rule/multi',
  8. edit_url: 'auth.rule/edit',
  9. add_url: 'auth.rule/add',
  10. delete_url: 'auth.rule/del',
  11. };
  12. Table.render({
  13. init: Table.init,
  14. elem: Table.init.table_elem,
  15. search:false,
  16. toolbar: ['refresh', 'add', 'edit', 'delete', {
  17. text: '更多',
  18. auth: 'multi',
  19. icon: 'iconfont icon-more-line',
  20. class: 'layui-btn layui-btn-sm layui-btn-primary layui-border btn-disabled layui-btn-disabled',
  21. extend: 'id="dropdown-more"',
  22. },
  23. {
  24. text: '展开或折叠全部',
  25. icon: 'iconfont icon-add-fill',
  26. class: 'layui-btn layui-btn-sm',
  27. extend: 'id="openAll"',
  28. }],
  29. url: "auth.rule/index",
  30. pk:'id',
  31. tree: {
  32. customName: {
  33. children: 'childlist',
  34. pid: 'parentid',
  35. name: 'title'
  36. },
  37. view: {
  38. showIcon: false,
  39. }
  40. },
  41. cols: [
  42. [
  43. { type: 'checkbox', fixed: 'left' },
  44. { field: 'listorder', width: 60, title: '排序', edit: 'text' },
  45. { field: 'id', width: 80, title: 'ID' },
  46. { field: 'title', minWidth: 150, align: 'left', title: '菜单名称', },
  47. { width: 80, title: '图标', align: 'center', templet: "<div><i class='iconfont {{d.icon}}'></i></div>" },
  48. { field: 'name', width: 200, title: '规则' },
  49. { field: 'status', align: 'center', width: 120, title: '状态', unresize: true, templet: Table.formatter.switch, tips: "显示|隐藏" },
  50. {
  51. fixed: 'right',
  52. width: 140,
  53. title: '操作',
  54. templet: Table.formatter.tool,
  55. operat: [
  56. {
  57. text: '添加',
  58. url: Table.init.add_url+'?parentid={id}',
  59. auth:'add',
  60. class: 'layui-btn layui-btn-xs layui-btn-normal btn-dialog',
  61. },
  62. 'edit', 'delete']
  63. }
  64. ]
  65. ],
  66. done: function(res, curr, count) {
  67. $('.layui-btn[lay-event="btn-delone"]').data("success", function (data, ret) {
  68. Yzn.api.refreshmenu();
  69. layui.table.reload(Table.init.table_render_id);
  70. return false;
  71. });
  72. //更多操作
  73. layui.dropdown.render({
  74. elem: '#dropdown-more',
  75. data: [{
  76. title: '设置显示',
  77. templet: '<i class="iconfont icon-eye-line"></i>&nbsp;设置显示',
  78. params:'status=1'
  79. }, {
  80. title: '设置隐藏',
  81. templet: '<i class="iconfont icon-eye-close-line"></i>&nbsp;设置隐藏',
  82. params:'status=0'
  83. }],
  84. click: function(obj) {
  85. tableId = Table.init.table_render_id;
  86. var ids = Table.api.selectedids(tableId);
  87. if (ids.length <= 0) {
  88. Toastr.error('请勾选需要操作的数据');
  89. return false;
  90. }
  91. Yzn.api.ajax({
  92. url: Table.init.multi_url,
  93. data: { id: ids, param: obj.params }
  94. }, function(data, ret) {
  95. layui.table.reload(tableId);
  96. });
  97. }
  98. });
  99. }
  100. });
  101. $('body').on('click', '#openAll', function() {
  102. var that = this;
  103. var show = $("i", that).hasClass("icon-add-fill");
  104. layui.treeTable.expandAll(Table.init.table_render_id, show);
  105. $("i", that).toggleClass("icon-add-fill", !show);
  106. $("i", that).toggleClass("icon-subtract-fill", show);
  107. })
  108. Table.api.bindevent();
  109. },
  110. add: function() {
  111. Controller.api.bindevent();
  112. },
  113. edit: function() {
  114. Controller.api.bindevent();
  115. },
  116. api: {
  117. bindevent: function() {
  118. iconPicker.render({
  119. // 选择器,推荐使用input
  120. elem: '#iconPicker',
  121. // 数据类型:fontClass/unicode,推荐使用fontClass
  122. type: 'fontClass',
  123. // 是否开启搜索:true/false,默认true
  124. search: true,
  125. // 是否开启分页:true/false,默认true
  126. page: true,
  127. // 每页显示数量,默认12
  128. limit: 12,
  129. // 点击回调
  130. click: function(data) {
  131. //console.log(data);
  132. },
  133. // 渲染成功后的回调
  134. success: function(d) {
  135. //console.log(d);
  136. }
  137. });
  138. Form.api.bindevent($("form.layui-form"), function (data) {
  139. Yzn.api.refreshmenu();
  140. });
  141. layui.form.on('radio(ismenu)', function(data) {
  142. var name = $("input[name='row[name]']");
  143. var ismenu = data.value == 1;
  144. name.prop("placeholder", ismenu ? name.data("placeholder-menu") : name.data("placeholder-node"));
  145. $('div[data-type="menu"]').toggleClass("layui-hide", !ismenu);
  146. });
  147. $("input[name='row[ismenu]']:checked").next().trigger("click");
  148. }
  149. }
  150. };
  151. return Controller;
  152. });