datalist.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. {extend name="common/base"/}
  2. <!-- 主体 -->
  3. {block name="body"}
  4. <div class="p-3">
  5. <form class="layui-form gg-form-bar border-t border-x">
  6. <div class="layui-input-inline" style="width:300px;">
  7. <input type="text" name="keywords" placeholder="请输入关键字" class="layui-input" autocomplete="off" />
  8. </div>
  9. <div class="layui-input-inline">
  10. <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="searchform">提交搜索</button>
  11. </div>
  12. </form>
  13. <table class="layui-hide" id="pages" lay-filter="pages"></table>
  14. </div>
  15. <script type="text/html" id="toolbarDemo">
  16. <div class="layui-btn-container">
  17. <span class="layui-btn layui-btn-sm" lay-event="add" data-title="添加单页面">+ 添加单页面</span>
  18. </div>
  19. </script>
  20. <script type="text/html" id="status">
  21. <i class="layui-icon {{# if(d.status == 1){ }}layui-icon-ok green{{# } else { }}layui-icon-close red{{# } }}"></i>
  22. </script>
  23. <script type="text/html" id="barDemo">
  24. <div class="layui-btn-group"><a class="layui-btn layui-btn-normal layui-btn-xs" href="/home/pages/detail/id/{{d.id}}.html" target="_blank">查看</a><a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a><a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a></div>
  25. </script>
  26. {/block}
  27. <!-- /主体 -->
  28. <!-- 脚本 -->
  29. {block name="script"}
  30. <script>
  31. const moduleInit = ['tool'];
  32. function gouguInit() {
  33. var table = layui.table,tool = layui.tool, form = layui.form;
  34. layui.pageTable = table.render({
  35. elem: '#pages',
  36. title: '单页面列表',
  37. toolbar: '#toolbarDemo',
  38. url: '/admin/pages/datalist',
  39. page: true,
  40. limit: 20,
  41. cellMinWidth: 80,
  42. cols: [
  43. [
  44. {
  45. fixed: 'left',
  46. field: 'id',
  47. title: '编号',
  48. align: 'center',
  49. width: 80
  50. },{
  51. field: 'title',
  52. title: '页面名称',
  53. },{
  54. field: 'read',
  55. title: '阅读量',
  56. align: 'center',
  57. width: 100
  58. },{
  59. field: 'name',
  60. title: 'URL文件名',
  61. align: 'center',
  62. width: 100
  63. },{
  64. field: 'template',
  65. title: '前端模板',
  66. align: 'center',
  67. width: 100
  68. },{
  69. field: 'admin_name',
  70. title: '创建人',
  71. align: 'center',
  72. width: 100
  73. },{
  74. field: 'create_time',
  75. title: '创建时间',
  76. align: 'center',
  77. width: 150
  78. },
  79. {
  80. field: 'status',
  81. title: '上下架',
  82. toolbar: '#status',
  83. align: 'center',
  84. width: 80
  85. },
  86. {
  87. fixed: 'right',
  88. field: 'right',
  89. title: '操作',
  90. toolbar: '#barDemo',
  91. width: 136,
  92. align: 'center'
  93. }
  94. ]
  95. ]
  96. });
  97. //监听表头工具栏事件
  98. table.on('toolbar(pages)', function(obj){
  99. if (obj.event === 'add') {
  100. tool.side("/admin/pages/add");
  101. return false;
  102. }
  103. });
  104. //监听表格行工具事件
  105. table.on('tool(pages)', function(obj) {
  106. var data = obj.data;
  107. if (obj.event === 'read') {
  108. tool.side('/admin/pages/read?id='+obj.data.id);
  109. }
  110. else if (obj.event === 'edit') {
  111. tool.side('/admin/pages/edit?id='+obj.data.id);
  112. }
  113. else if (obj.event === 'del') {
  114. layer.confirm('确定要删除该记录吗?', {
  115. icon: 3,
  116. title: '提示'
  117. }, function(index) {
  118. let callback = function (e) {
  119. layer.msg(e.msg);
  120. if (e.code == 0) {
  121. obj.del();
  122. }
  123. }
  124. tool.delete("/admin/pages/del", { id: data.id }, callback);
  125. layer.close(index);
  126. });
  127. }
  128. return false;
  129. });
  130. //监听搜索提交
  131. form.on('submit(searchform)', function(data) {
  132. layui.pageTable.reload({
  133. where: {
  134. keywords: data.field.keywords
  135. },
  136. page: {
  137. curr: 1
  138. }
  139. });
  140. return false;
  141. });
  142. }
  143. </script>
  144. {/block}
  145. <!-- /脚本 -->