index.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. {extend name="common/base"/}
  2. <!-- 主体 -->
  3. {block name="body"}
  4. <div class="p-3">
  5. <div class="gg-form-bar border-t border-x" style="padding-bottom:10px;">
  6. <button class="layui-btn layui-btn-sm add-menu">+ 添加菜单/节点</button>
  7. </div>
  8. <div>
  9. <table class="layui-hide" id="treeTable" lay-filter="treeTable"></table>
  10. </div>
  11. </div>
  12. {/block}
  13. <!-- /主体 -->
  14. <!-- 脚本 -->
  15. {block name="script"}
  16. <script>
  17. const moduleInit = ['tool', 'treeGrid'];
  18. function gouguInit() {
  19. var treeGrid = layui.treeGrid,table = layui.table, tool = layui.tool;
  20. var pageTable = treeGrid.render({
  21. id: 'treeTable'
  22. , elem: '#treeTable'
  23. , idField: 'id'
  24. , url: "/admin/rule/index"
  25. , cellMinWidth: 80
  26. , treeId: 'id'//树形id字段名称
  27. , treeUpId: 'pid'//树形父id字段名称
  28. , treeShowName: 'title'//以树形式显示的字段
  29. , cols: [[
  30. { field: 'id', width: 80, title: 'ID号', align: 'center' }
  31. , { field: 'sort', width: 60, title: '排序', align: 'center' }
  32. ,{field:'icon',title: '菜单图标',width: 80, align: 'center' ,templet: function(d){
  33. var html='<i style="font-size:20px;" class="'+d.icon+'"></i>';
  34. return html;
  35. }}
  36. , { field: 'title', width: 160, title: '菜单/节点名称' }
  37. , { field: 'pid', title: '父ID', width: 80, align: 'center' }
  38. , { field: 'src', title: 'URL链接' }
  39. , {
  40. field: 'menu', width: 100, title: '是否是菜单', align: 'center', templet: function (d) {
  41. var html = '<span style="color:#fbbc05">否</span>';
  42. if (d.menu == '1') {
  43. html = '<span style="color:#12bb37">是</span>';
  44. }
  45. return html;
  46. }
  47. }
  48. , { field: 'name', width: 110, title: '操作日志名称', align: 'center' }
  49. , {
  50. width: 188, title: '操作', align: 'center'
  51. , templet: function (d) {
  52. var html = '<span class="layui-btn-group"><button class="layui-btn layui-btn-xs" lay-event="add">添加子菜单/节点</button><button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</button><button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>';
  53. return html;
  54. }
  55. }
  56. ]]
  57. , page: false
  58. });
  59. //表头工具栏事件
  60. $('.add-menu').on('click', function () {
  61. tool.side("/admin/rule/add");
  62. return;
  63. });
  64. //操作按钮
  65. treeGrid.on('tool(treeTable)', function (obj) {
  66. console.log(obj);
  67. if (obj.event === 'add') {
  68. tool.side('/admin/rule/add?pid=' + obj.data.id);
  69. return;
  70. }
  71. if (obj.event === 'edit') {
  72. tool.side('/admin/rule/add?id=' + obj.data.id);
  73. return;
  74. }
  75. if (obj.event === 'del') {
  76. layer.confirm('确定要删除吗?', { icon: 3, title: '提示' }, function (index) {
  77. let callback = function (e) {
  78. layer.msg(e.msg);
  79. if (e.code == 0) {
  80. obj.del();
  81. }
  82. }
  83. tool.delete("/admin/rule/delete", { id: obj.data.id }, callback);
  84. layer.close(index);
  85. });
  86. }
  87. });
  88. }
  89. </script>
  90. {/block}
  91. <!-- /脚本 -->