nav_info.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. <button class="layui-btn layui-btn-primary layui-btn-sm add-back">返回</button>
  8. </div>
  9. <div>
  10. <table class="layui-hide" id="treeTable" lay-filter="treeTable"></table>
  11. </div>
  12. </div>
  13. <script type="text/html" id="target">
  14. <i class="layui-icon {{# if(d.target == 1){ }}layui-icon-ok{{# } else { }}layui-icon-close{{# } }}"></i>
  15. </script>
  16. <script type="text/html" id="status">
  17. <i class="layui-icon {{# if(d.status == 1){ }}layui-icon-ok{{# } else { }}layui-icon-close{{# } }}"></i>
  18. </script>
  19. {/block}
  20. <!-- /主体 -->
  21. <!-- 脚本 -->
  22. {block name="script"}
  23. <script>
  24. var nid = {$nav_id};
  25. const moduleInit = ['tool', 'treeGrid'];
  26. function gouguInit() {
  27. var treeGrid = layui.treeGrid,table = layui.table, tool = layui.tool;
  28. var pageTable = treeGrid.render({
  29. id: 'treeTable',
  30. elem: '#treeTable',
  31. idField: 'id',
  32. url: '/admin/nav/nav_info', //数据接口
  33. where: {
  34. id:nid
  35. },
  36. cellMinWidth: 100,
  37. treeId: 'id', //树形id字段名称
  38. treeUpId: 'pid', //树形父id字段名称
  39. treeShowName: 'title', //以树形式显示的字段
  40. cols: [
  41. [{
  42. field: 'sort',
  43. width: 80,
  44. title: '排序',
  45. align: 'center'
  46. }, {
  47. field: 'id',
  48. width: 80,
  49. title: 'ID号',
  50. align: 'center'
  51. }, {
  52. field: 'title',
  53. width: 220,
  54. title: '名称',
  55. }, {
  56. field: 'pid',
  57. title: '父级ID',
  58. width: 80,
  59. align: 'center'
  60. }, {
  61. field: 'src',
  62. title: '链接'
  63. },{
  64. field: 'target',
  65. title: '新窗口打开',
  66. toolbar: '#target',
  67. align: 'center',
  68. width: 100
  69. },{
  70. field: 'status',
  71. title: '状态',
  72. toolbar: '#status',
  73. align: 'center',
  74. width: 60
  75. }, {
  76. width: 160,
  77. title: '操作',
  78. align: 'center',
  79. templet: function (d) {
  80. var html = '';
  81. var addBtn =
  82. '<span class="layui-btn-group"><button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="add">添加子导航</button><button class="layui-btn layui-btn-xs" lay-event="edit">编辑</button><button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button></span>';
  83. return addBtn;
  84. }
  85. }]
  86. ],
  87. page: false
  88. });
  89. //表头工具栏事件
  90. $('.add-menu').on('click',function(){
  91. tool.side("/admin/nav/nav_info_add?nid="+nid);
  92. return;
  93. });
  94. //监听返回
  95. $('.add-back').on('click',function () {
  96. history.back(-1);
  97. return false;
  98. });
  99. //删除
  100. treeGrid.on('tool(treeTable)', function (obj) {
  101. if (obj.event === 'add') {
  102. tool.side('/admin/nav/nav_info_add?nid='+nid+'&pid='+obj.data.id);
  103. return;
  104. }
  105. if (obj.event === 'edit') {
  106. tool.side('/admin/nav/nav_info_add?nid='+nid+'&id='+obj.data.id);
  107. return;
  108. }
  109. if (obj.event === 'del') {
  110. layer.confirm('确定要删除吗?', {
  111. icon: 3,
  112. title: '提示'
  113. }, function (index) {
  114. let callback = function (e) {
  115. layer.msg(e.msg);
  116. if (e.code == 0) {
  117. obj.del();
  118. }
  119. }
  120. tool.delete("/admin/nav/nav_info_delete", { id: obj.data.id }, callback);
  121. layer.close(index);
  122. });
  123. }
  124. });
  125. }
  126. </script>
  127. {/block}
  128. <!-- /脚本 -->