index.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. {extend name="../../base/view/common/base" /}
  2. <!-- 主体 -->
  3. {block name="body"}
  4. <div class="p-page">
  5. <div class="gg-form-bar border-t border-x" style="padding-bottom:12px;">
  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'];
  18. function gouguInit() {
  19. var treeTable = layui.treeTable, tool = layui.tool;
  20. layui.trees = treeTable.render({
  21. elem: '#treeTable'
  22. ,url: "/home/rule/index"
  23. ,tree: { // treeTable 特定属性集
  24. customName: {name:'title'},
  25. data: {},
  26. view: {showIcon:false},
  27. async: {},
  28. callback: {}
  29. }
  30. , cellMinWidth: 80
  31. , cols: [[
  32. { field: 'id', width: 80, title: 'ID号', align: 'center' }
  33. , { field: 'sort', width: 60, title: '排序', align: 'center' }
  34. ,{field:'icon',title: '菜单图标',width: 80, align: 'center' ,templet: function(d){
  35. var html='<strong class="iconfont '+d.icon+'"></strong>';
  36. return html;
  37. }}
  38. , { field: 'title', width: 200, title: '菜单/节点名称' }
  39. , { field: 'pid', title: '父ID', width: 80, align: 'center' }
  40. , { field: 'src', title: 'URL链接' }
  41. , {
  42. field: 'menu', width: 100, title: '是否是菜单', align: 'center', templet: function (d) {
  43. var html = '<span style="color:#fbbc05">否</span>';
  44. if (d.menu == '1') {
  45. html = '<span style="color:#12bb37">是</span>';
  46. }
  47. return html;
  48. }
  49. }
  50. , { field: 'name', width: 110, title: '操作日志名称', align: 'center' }
  51. , {
  52. width: 188, title: '操作', align: 'center'
  53. , templet: function (d) {
  54. 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>';
  55. return html;
  56. }
  57. }
  58. ]]
  59. , page: false
  60. });
  61. //表头工具栏事件
  62. $('.add-menu').on('click', function () {
  63. tool.side("/home/rule/add");
  64. return;
  65. });
  66. //操作按钮
  67. treeTable.on('tool(treeTable)', function (obj) {
  68. console.log(obj);
  69. if (obj.event === 'add') {
  70. tool.side('/home/rule/add?pid=' + obj.data.id);
  71. return;
  72. }
  73. if (obj.event === 'edit') {
  74. tool.side('/home/rule/add?id=' + obj.data.id);
  75. return;
  76. }
  77. if (obj.event === 'del') {
  78. layer.confirm('确定要删除吗?', { icon: 3, title: '提示' }, function (index) {
  79. let callback = function (e) {
  80. layer.msg(e.msg);
  81. if (e.code == 0) {
  82. obj.del();
  83. }
  84. }
  85. tool.delete("/home/rule/delete", { id: obj.data.id }, callback);
  86. layer.close(index);
  87. });
  88. }
  89. });
  90. }
  91. </script>
  92. {/block}
  93. <!-- /脚本 -->