index.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. {extend name="common/base" /}
  2. <!-- 主体 -->
  3. {block name="body"}
  4. <div class="p-3">
  5. <table class="layui-hide" id="list" lay-filter="list"></table>
  6. </div>
  7. <script type="text/html" id="toolbarDemo">
  8. <div>
  9. <span class="red">模块功能即将推出,该列表目前只是预设数据,不影响开发者进行二次开发。</span>
  10. </div>
  11. </script>
  12. {/block}
  13. <!-- /主体 -->
  14. <!-- 脚本 -->
  15. {block name="script"}
  16. <script>
  17. const moduleInit = ['tool'];
  18. function gouguInit() {
  19. var tool = layui.tool, table = layui.table;
  20. layui.pageTable = table.render({
  21. elem: '#list'
  22. , toolbar: '#toolbarDemo'
  23. , title: '功能模块列表'
  24. , url: "/admin/module/index"
  25. , page: false //开启分页
  26. , cellMinWidth: 80
  27. , cols: [[
  28. { field: 'id', width: 80, title: 'ID号', align: 'center' }
  29. , { field: 'title', title: '模块名称' }
  30. , {
  31. field: 'name', title: '模块所在目录', templet: function (d) {
  32. var html = 'app/' + d.name;
  33. return html;
  34. }
  35. }
  36. , {
  37. field: 'status', title: '状态', width: 80, align: 'center', templet: function (d) {
  38. var html1 = '<span>正常</span>';
  39. var html2 = '<span style="color:#FF5722">禁用</span>';
  40. if (d.status == 1) {
  41. return html1;
  42. }
  43. else {
  44. return html2;
  45. }
  46. }
  47. }
  48. , {
  49. field: 'type', title: '类型', width: 120, align: 'center', templet: function (d) {
  50. var html1 = '<span>系统模块</span>';
  51. var html2 = '<span style="color:#FF5722">普通模块</span>';
  52. if (d.type == 1) {
  53. return html1;
  54. }
  55. else {
  56. return html2;
  57. }
  58. }
  59. }
  60. , {
  61. width: 100, title: '操作', align: 'center', templet: function (d) {
  62. var html = '';
  63. var btn = '<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>';
  64. var btn1 = '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="disable">禁用</a>';
  65. var btn2 = '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="open">启用</a>';
  66. if (d.status == 1) {
  67. html = '<div class="layui-btn-group">' + btn + btn1 + '</div>';
  68. }
  69. else {
  70. html = '<div class="layui-btn-group">' + btn + btn2 + '</div>';
  71. }
  72. return html;
  73. }
  74. }
  75. ]]
  76. });
  77. table.on('tool(list)', function (obj) {
  78. if (obj.event === 'edit') {
  79. addExpense(obj.data.id, obj.data.title, obj.data.name);
  80. }
  81. if (obj.event === 'disable') {
  82. layer.confirm('确定要禁用该模块吗?', { icon: 3, title: '提示' }, function (index) {
  83. let callback = function (e) {
  84. layer.msg(e.msg);
  85. if (e.code == 0) {
  86. layer.close(index);
  87. layui.pageTable.reload()
  88. }
  89. }
  90. tool.post("/admin/module/disable", { id: obj.data.id, status: 0 }, callback);
  91. layer.close(index);
  92. });
  93. }
  94. if (obj.event === 'open') {
  95. layer.confirm('确定要启用该模块吗?', { icon: 3, title: '提示' }, function (index) {
  96. let callback = function (e) {
  97. layer.msg(e.msg);
  98. if (e.code == 0) {
  99. layer.close(index);
  100. layui.pageTable.reload()
  101. }
  102. }
  103. tool.post("/admin/module/disable", { id: obj.data.id, status: 1 }, callback);
  104. layer.close(index);
  105. });
  106. }
  107. });
  108. $('body').on('click', '.addNew', function () {
  109. addExpense(0, '', '');
  110. });
  111. function addExpense(id, title, name) {
  112. layer.open({
  113. type: 1
  114. , title: id > 0 ? '新增模块' : '编辑模块'
  115. , area: '398px;'
  116. , id: 'GG_module' //设定一个id,防止重复弹出
  117. , btn: ['确定', '取消']
  118. , btnAlign: 'c'
  119. , content: `<div style="padding-top:16px;">
  120. <div class="layui-form-item">
  121. <label class="layui-form-label">模块名称</label>
  122. <div class="layui-input-inline">
  123. <input type="hidden" name="id" value="${id}">
  124. <input type="text" name="title" autocomplete="off" value="${title}" placeholder="请输入模块名称" class="layui-input">
  125. </div>
  126. </div>
  127. <div class="layui-form-item">
  128. <label class="layui-form-label">所在目录</label>
  129. <div class="layui-input-inline">
  130. <input type="text" name="name" autocomplete="off" value="${name}" placeholder="请输入至少2个小写字符" class="layui-input">
  131. </div>
  132. </div>
  133. <div style="padding:8px 0;text-align:center;color:red">目录如:"app/admin",只需要填写"admin"就可以了。</div>
  134. </div>`
  135. , yes: function (index) {
  136. let id = $('#GG_module').find('[name="id"]').val();
  137. let title = $('#GG_module').find('[name="title"]').val();
  138. let name = $('#GG_module').find('[name="name"]').val();
  139. let callback = function (e) {
  140. layer.msg(e.msg);
  141. if (e.code == 0) {
  142. layer.close(index);
  143. layui.pageTable.reload();
  144. }
  145. }
  146. tool.post("/admin/module/add", { id: id, title: title, name: name }, callback);
  147. }
  148. , btn2: function () {
  149. layer.closeAll();
  150. }
  151. });
  152. }
  153. }
  154. </script>
  155. {/block}
  156. <!-- /脚本 -->