admin_rule.html 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. {include file="common/header"/}
  2. <div class="LM-container">
  3. <div class="LM-main">
  4. <div class="admin-main layui-anim layui-anim-upbit">
  5. <fieldset class="layui-elem-field layui-field-title">
  6. <legend>权限{:lang('list')}</legend>
  7. </fieldset>
  8. <blockquote class="layui-elem-quote">
  9. <a href="{:url('ruleAdd')}" class="layui-btn layui-btn-sm LM-add">{:lang('add')}路由</a>
  10. <a class="layui-btn layui-btn-normal layui-btn-sm" onclick="openAll();">展开或折叠全部</a>
  11. </blockquote>
  12. <table class="layui-table" id="treeGrid" lay-filter="treeGrid"></table>
  13. </div>
  14. </div>
  15. </div>
  16. <script type="text/html" id="auth">
  17. <input type="checkbox" name="auth_open" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="auth_open" {{ d.auth_open == 0 ? 'checked' : '' }}>
  18. </script>
  19. <script type="text/html" id="status">
  20. <input type="checkbox" name="menu_status" value="{{d.id}}" lay-skin="switch" lay-text="显示|隐藏" lay-filter="menu_status" {{ d.menu_status == 1 ? 'checked' : '' }}>
  21. </script>
  22. <script type="text/html" id="order">
  23. <input name="{{d.id}}" data-id="{{d.id}}" class="list_order layui-input" value=" {{d.sort}}" size="10"/>
  24. </script>
  25. <script type="text/html" id="icon">
  26. <span class="icon {{d.icon}}"></span>
  27. </script>
  28. <script type="text/html" id="action">
  29. <a href="{:url('ruleEdit')}?id={{d.id}}" class="layui-btn layui-btn-xs">{:lang('edit')}</a>
  30. <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="add">{:lang('add')}{:lang('child')}</a>
  31. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">{:lang('del')}</a>
  32. </script>
  33. <script type="text/html" id="topBtn">
  34. <a href="{:url('ruleAdd')}" class="layui-btn layui-btn-sm">{:lang('add')}权限</a>
  35. </script>
  36. {include file="common/footer"/}
  37. <script>
  38. var editObj=null,ptable=null,treeGrid=null,tableId='treeGrid',layer=null;
  39. layui.config({
  40. base: '/static/plugins/layui/extend/'
  41. }).extend({
  42. treeGrid: 'treeGrid/treeGrid'
  43. }).use(['jquery','treeGrid','layer','form'], function(){
  44. var $=layui.jquery ,form = layui.form;
  45. treeGrid = layui.treeGrid;
  46. layer=layui.layer;
  47. ptable=treeGrid.render({
  48. id:tableId
  49. ,elem: '#'+tableId
  50. ,idField:'id'
  51. ,url:'{:url("adminRule")}'
  52. ,cellMinWidth: 100
  53. ,treeId:'id'//树形id字段名称
  54. ,treeUpId:'pid'//树形父id字段名称
  55. ,treeShowName:'title'//以树形式显示的字段
  56. ,height:'full-140'
  57. ,isFilter:false
  58. ,iconOpen:true//是否显示图标【默认显示】
  59. ,isOpenDefault:true//节点默认是展开还是折叠【默认展开】
  60. ,cols: [[
  61. {field: 'id', title: '{:lang("id")}', width: 70, fixed: true},
  62. {field: 'icon', align: 'center',title: '{:lang("icon")}', width: 60,templet: '#icon'},
  63. {field: 'title', title: '权限名称', width: 200},
  64. {field: 'href', title: '控制器/方法', width: 200},
  65. {field: 'auth_open',align: 'center', title: '是否验证权限', width: 150,toolbar: '#auth'},
  66. {field: 'menu_status',align: 'center',title: '菜单{:lang("status")}', width: 150,toolbar: '#status'},
  67. {field: 'sort',align: 'center', title: '{:lang("order")}', width: 80, templet: '#order'},
  68. {title:'操作',width:200, toolbar: '#action',align:"center"},
  69. ]]
  70. ,page:false
  71. });
  72. treeGrid.on('tool('+tableId+')',function (obj) {
  73. var data = obj.data;
  74. if(obj.event === 'del'){
  75. layer.confirm('{:lang("Are you sure you want to delete it")}', function(index){
  76. var loading = layer.load(1, {shade: [0.1, '#fff']});
  77. $.post("{:url('ruleDel')}",{id:data.id},function(res){
  78. layer.close(loading);
  79. if(res.code==1){
  80. layer.msg(res.msg,{time:1000,icon:1});
  81. obj.del();
  82. }else{
  83. layer.msg(res.msg,{time:1000,icon:2});
  84. }
  85. });
  86. layer.close(index);
  87. });
  88. }else if(obj.event === 'add'){
  89. var index = layer.open({
  90. type: 2,
  91. content: '{:url("ruleAdd")}'+'?rule_id='+data.id,
  92. area: ['800px', '600px'],
  93. maxmin: true
  94. });
  95. layer.full(index);
  96. }
  97. });
  98. form.on('switch(auth_open)', function(obj){
  99. loading =layer.load(1, {shade: [0.1,'#fff']});
  100. var id = this.value;
  101. var auth_open = obj.elem.checked===true?0:1;
  102. $.post('{:url("ruleOpen")}',{'id':id,'auth_open':auth_open},function (res) {
  103. layer.close(loading);
  104. if (res.code==1) {
  105. treeGrid.render;
  106. }else{
  107. layer.msg(res.msg,{time:1000,icon:2});
  108. treeGrid.render;
  109. return false;
  110. }
  111. })
  112. });
  113. form.on('switch(menu_status)', function(obj){
  114. loading =layer.load(1, {shade: [0.1,'#fff']});
  115. var id = this.value;
  116. var menu_status = obj.elem.checked===true?1:0;
  117. $.post('{:url("ruleState")}',{'id':id,'menu_status':menu_status},function (res) {
  118. layer.close(loading);
  119. if (res.code==1) {
  120. treeGrid.render;
  121. }else{
  122. layer.msg(res.msg,{time:1000,icon:2});
  123. treeGrid.render;
  124. return false;
  125. }
  126. })
  127. });
  128. $('body').on('blur','.list_order',function() {
  129. var id = $(this).attr('data-id');
  130. var sort = $(this).val();
  131. $.post('{:url("ruleSort")}',{id:id,sort:sort},function(res){
  132. if(res.code > 0){
  133. layer.msg(res.msg,{time:1000,icon:1},function(){
  134. location.href = res.url;
  135. });
  136. }else{
  137. layer.msg(res.msg,{time:1000,icon:2});
  138. treeGrid.render;
  139. }
  140. })
  141. })
  142. });
  143. function openAll() {
  144. var treedata=treeGrid.getDataTreeList(tableId);
  145. treeGrid.treeOpenAll(tableId,!treedata[0][treeGrid.config.cols.isOpen]);
  146. }
  147. </script>