index.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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="ID/名称" class="layui-input" />
  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="link" lay-filter="link"></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. <script type="text/html" id="barDemo">
  24. <div class="layui-btn-group"><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: '#link',
  36. title: '友情链接列表',
  37. toolbar: '#toolbarDemo',
  38. url: '/admin/links/index', //数据接口
  39. page: false, //开启分页
  40. cols: [
  41. [
  42. {
  43. field: 'id',
  44. title: 'ID号',
  45. align: 'center',
  46. width: 80
  47. }, {
  48. field: 'name',
  49. title: '网站名称',
  50. width: 240
  51. }, {
  52. field: 'src',
  53. title: '网站链接'
  54. }, {
  55. field: 'sort',
  56. title: '排序',
  57. width: 80,
  58. align: 'center'
  59. }, {
  60. field: 'right',
  61. title: '操作',
  62. toolbar: '#barDemo',
  63. width: 100,
  64. align: 'center'
  65. }
  66. ]
  67. ]
  68. });
  69. //表头工具栏事件
  70. table.on('toolbar(link)', function (obj) {
  71. if (obj.event === 'add') {
  72. tool.side("/admin/links/add");
  73. return;
  74. }
  75. });
  76. //监听行工具事件
  77. table.on('tool(link)', function (obj) {
  78. var data = obj.data;
  79. if (obj.event === 'edit') {
  80. tool.side('/admin/links/add?id=' + obj.data.id);
  81. return;
  82. }
  83. if (obj.event === 'del') {
  84. layer.confirm('确定要删除该数据吗?', {
  85. icon: 3,
  86. title: '提示'
  87. }, function (index) {
  88. let callback = function (e) {
  89. layer.msg(e.msg);
  90. if (e.code == 0) {
  91. obj.del();
  92. }
  93. }
  94. tool.delete("/admin/links/delete", { id: data.id }, callback);
  95. layer.close(index);
  96. });
  97. }
  98. });
  99. //监听搜索提交
  100. form.on('submit(webform)', function (data) {
  101. layui.pageTable.reload({
  102. where: {
  103. keywords: data.field.keywords
  104. },
  105. page: {
  106. curr: 1
  107. }
  108. });
  109. return false;
  110. });
  111. }
  112. </script>
  113. {/block}
  114. <!-- /脚本 -->