index.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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="webform">提交搜索</button>
  11. </div>
  12. </form>
  13. <table class="layui-hide" id="keywords" lay-filter="keywords"></table>
  14. </div>
  15. <script type="text/html" id="status">
  16. <i class="layui-icon {{# if(d.status == 1){ }}layui-icon-ok{{# } else { }}layui-icon-close{{# } }}"></i>
  17. </script>
  18. <script type="text/html" id="toolbarDemo">
  19. <div class="layui-btn-container">
  20. <button class="layui-btn layui-btn-sm" lay-event="add">+ 添加关键字</button>
  21. </div>
  22. </script>
  23. {/block}
  24. <!-- /主体 -->
  25. <!-- 脚本 -->
  26. {block name="script"}
  27. <script>
  28. const moduleInit = ['tool'];
  29. function gouguInit() {
  30. var table = layui.table,tool = layui.tool, form = layui.form;
  31. layui.pageTable = table.render({
  32. elem: '#keywords',
  33. title: '关键字列表',
  34. toolbar: '#toolbarDemo',
  35. url: '/admin/keywords/index',
  36. page: true, //开启分页
  37. limit: 20,
  38. cols: [
  39. [{
  40. field: 'id',
  41. width: 80,
  42. title: 'ID编号',
  43. align: 'center'
  44. }, {
  45. field: 'sort',
  46. width: 80,
  47. title: '排序',
  48. align: 'center',
  49. edit: "text"
  50. }, {
  51. field: 'title',
  52. title: '关键字名称',
  53. edit: "text"
  54. }, {
  55. field: 'status',
  56. width: 80,
  57. title: '状态',
  58. templet: '#status',
  59. align: 'center'
  60. }, {
  61. width: 100,
  62. title: '操作',
  63. align: 'center',
  64. templet: function (d) {
  65. var html = '<div class="layui-btn-group"><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></div>';
  66. return html;
  67. }
  68. }]
  69. ]
  70. });
  71. //监听搜索提交
  72. form.on('submit(webform)', function (data) {
  73. if (data.field.keywords) {
  74. layui.pageTable.reload({
  75. where: {
  76. keywords: data.field.keywords
  77. },
  78. page: {
  79. curr: 1
  80. }
  81. });
  82. } else {
  83. location.reload();
  84. }
  85. return false;
  86. });
  87. //表头工具栏事件
  88. table.on('toolbar(keywords)', function(obj){
  89. if (obj.event === 'add') {
  90. tool.side("/admin/keywords/add");
  91. return;
  92. }
  93. });
  94. //监听行工具事件
  95. table.on('tool(keywords)', function (obj) {
  96. var data = obj.data;
  97. if (obj.event === 'edit') {
  98. tool.side('/admin/keywords/add?id='+obj.data.id);
  99. return;
  100. }
  101. if (obj.event === 'del') {
  102. layer.confirm('确定要删除吗?', {
  103. icon: 3,
  104. title: '提示'
  105. }, function (index) {
  106. let callback = function (e) {
  107. layer.msg(e.msg);
  108. if (e.code == 0) {
  109. obj.del();
  110. }
  111. }
  112. tool.delete("/admin/keywords/delete", { id: data.id }, callback);
  113. layer.close(index);
  114. });
  115. }
  116. });
  117. }
  118. </script>
  119. {/block}
  120. <!-- /脚本 -->