menu.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>menu</title>
  6. <link rel="stylesheet" href="../lib/layui-v2.5.4/css/layui.css" media="all">
  7. <link rel="stylesheet" href="../css/public.css" media="all">
  8. <style>
  9. .layui-btn:not(.layui-btn-lg ):not(.layui-btn-sm):not(.layui-btn-xs) {
  10. height: 34px;
  11. line-height: 34px;
  12. padding: 0 8px;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <div class="layuimini-container">
  18. <div class="layuimini-main">
  19. <div>
  20. <div class="layui-btn-group">
  21. <button class="layui-btn" id="btn-expand">全部展开</button>
  22. <button class="layui-btn" id="btn-fold">全部折叠</button>
  23. </div>
  24. <table id="munu-table" class="layui-table" lay-filter="munu-table"></table>
  25. </div>
  26. </div>
  27. </div>
  28. <!-- 操作列 -->
  29. <script type="text/html" id="auth-state">
  30. <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
  31. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
  32. </script>
  33. <script src="../lib/layui-v2.5.4/layui.js" charset="utf-8"></script>
  34. <script src="../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
  35. <script>
  36. layui.use(['table', 'treetable'], function () {
  37. var $ = layui.jquery;
  38. var table = layui.table;
  39. var treetable = layui.treetable;
  40. // 渲染表格
  41. layer.load(2);
  42. treetable.render({
  43. treeColIndex: 1,
  44. treeSpid: -1,
  45. treeIdName: 'authorityId',
  46. treePidName: 'parentId',
  47. elem: '#munu-table',
  48. url: '../api/menus.json',
  49. page: false,
  50. cols: [[
  51. {type: 'numbers'},
  52. {field: 'authorityName', minWidth: 200, title: '权限名称'},
  53. {field: 'authority', title: '权限标识'},
  54. {field: 'menuUrl', title: '菜单url'},
  55. {field: 'orderNumber', width: 80, align: 'center', title: '排序号'},
  56. {
  57. field: 'isMenu', width: 80, align: 'center', templet: function (d) {
  58. if (d.isMenu == 1) {
  59. return '<span class="layui-badge layui-bg-gray">按钮</span>';
  60. }
  61. if (d.parentId == -1) {
  62. return '<span class="layui-badge layui-bg-blue">目录</span>';
  63. } else {
  64. return '<span class="layui-badge-rim">菜单</span>';
  65. }
  66. }, title: '类型'
  67. },
  68. {templet: '#auth-state', width: 120, align: 'center', title: '操作'}
  69. ]],
  70. done: function () {
  71. layer.closeAll('loading');
  72. }
  73. });
  74. $('#btn-expand').click(function () {
  75. treetable.expandAll('#munu-table');
  76. });
  77. $('#btn-fold').click(function () {
  78. treetable.foldAll('#munu-table');
  79. });
  80. //监听工具条
  81. table.on('tool(munu-table)', function (obj) {
  82. var data = obj.data;
  83. var layEvent = obj.event;
  84. if (layEvent === 'del') {
  85. layer.msg('删除' + data.id);
  86. } else if (layEvent === 'edit') {
  87. layer.msg('修改' + data.id);
  88. }
  89. });
  90. });
  91. </script>
  92. </body>
  93. </html>