datalist.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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">
  7. <select name="cate_id">
  8. <option value="">请选择文章分类</option>
  9. {volist name=":set_recursion(get_article_cate())" id="v"}
  10. <option value="{$v.id}">{$v.title}</option>
  11. {/volist}
  12. </select>
  13. </div>
  14. <div class="layui-input-inline" style="width:300px;">
  15. <input type="text" name="keywords" placeholder="请输入关键字" class="layui-input" autocomplete="off" />
  16. </div>
  17. <div class="layui-input-inline">
  18. <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="searchform">提交搜索</button>
  19. </div>
  20. </form>
  21. <table class="layui-hide" id="article" lay-filter="article"></table>
  22. </div>
  23. <script type="text/html" id="status">
  24. <i class="layui-icon {{# if(d.status == 1){ }}layui-icon-ok{{# } else { }}layui-icon-close{{# } }}"></i>
  25. </script>
  26. <script type="text/html" id="is_home">
  27. <i class="layui-icon {{# if(d.is_home == 1){ }}layui-icon-ok{{# } else { }}layui-icon-close{{# } }}"></i>
  28. </script>
  29. <script type="text/html" id="toolbarDemo">
  30. <div class="layui-btn-container">
  31. <span class="layui-btn layui-btn-sm" lay-event="add" data-title="添加文章表">+ 添加文章表</span>
  32. </div>
  33. </script>
  34. <script type="text/html" id="barDemo">
  35. <div class="layui-btn-group"><a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="read">查看</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>
  36. </script>
  37. {/block}
  38. <!-- /主体 -->
  39. <!-- 脚本 -->
  40. {block name="script"}
  41. <script>
  42. const moduleInit = ['tool'];
  43. function gouguInit() {
  44. var table = layui.table,tool = layui.tool, form = layui.form;
  45. layui.pageTable = table.render({
  46. elem: '#article',
  47. title: '文章表列表',
  48. toolbar: '#toolbarDemo',
  49. url: '/admin/article/datalist',
  50. page: true,
  51. limit: 20,
  52. cellMinWidth: 80,
  53. cols: [
  54. [
  55. {
  56. fixed: 'left',
  57. field: 'id',
  58. title: '编号',
  59. align: 'center',
  60. width: 80
  61. },{
  62. field: 'cate_title',
  63. title: '文章分类',
  64. align: 'center',
  65. width: 120
  66. },{
  67. field: 'title',
  68. title: '文章标题',
  69. },{
  70. field: 'read',
  71. title: '阅读量',
  72. align: 'center',
  73. width: 90
  74. },{
  75. field: 'type_str',
  76. title: '文章属性',
  77. align: 'center',
  78. width: 90
  79. },{
  80. field: 'is_home',
  81. title: '是否首页显示',
  82. toolbar: '#is_home',
  83. align: 'center',
  84. width: 100
  85. },{
  86. field: 'sort',
  87. title: '排序',
  88. align: 'center',
  89. width: 80
  90. },{
  91. field: 'status',
  92. title: '状态',
  93. toolbar: '#status',
  94. align: 'center',
  95. width: 80
  96. },{
  97. field: 'admin_name',
  98. title: '创建人',
  99. align: 'center',
  100. width: 100
  101. },{
  102. field: 'create_time',
  103. title: '创建时间',
  104. align: 'center',
  105. width: 160
  106. },{
  107. fixed: 'right',
  108. field: 'right',
  109. title: '操作',
  110. toolbar: '#barDemo',
  111. width: 136,
  112. align: 'center'
  113. }
  114. ]
  115. ]
  116. });
  117. //监听表头工具栏事件
  118. table.on('toolbar(article)', function(obj){
  119. if (obj.event === 'add') {
  120. tool.side("/admin/article/add");
  121. return false;
  122. }
  123. });
  124. //监听表格行工具事件
  125. table.on('tool(article)', function(obj) {
  126. var data = obj.data;
  127. if (obj.event === 'read') {
  128. tool.side('/admin/article/read?id='+obj.data.id);
  129. }
  130. else if (obj.event === 'edit') {
  131. tool.side('/admin/article/edit?id='+obj.data.id);
  132. }
  133. else if (obj.event === 'del') {
  134. layer.confirm('确定要删除该记录吗?', {
  135. icon: 3,
  136. title: '提示'
  137. }, function(index) {
  138. let callback = function (e) {
  139. layer.msg(e.msg);
  140. if (e.code == 0) {
  141. obj.del();
  142. }
  143. }
  144. tool.delete("/admin/article/del", { id: data.id }, callback);
  145. layer.close(index);
  146. });
  147. }
  148. return false;
  149. });
  150. //监听搜索提交
  151. form.on('submit(searchform)', function(data) {
  152. layui.pageTable.reload({
  153. where: {
  154. keywords: data.field.keywords,
  155. cate_id: data.field.cate_id
  156. },
  157. page: {
  158. curr: 1
  159. }
  160. });
  161. return false;
  162. });
  163. }
  164. </script>
  165. {/block}
  166. <!-- /脚本 -->