ad_index.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. {extend name='table'}
  2. {block name="button"}
  3. {if auth("ad_add")}
  4. <!--<button data-modal='{:url("ad_add")}' class='layui-btn layui-btn-sm layui-btn-primary'>添加</button>-->
  5. <button data-open='{:url("ad_add")}' class='layui-btn layui-btn-sm layui-btn-primary'>添加</button>
  6. {/if}
  7. <!--{if auth("ad_del")}-->
  8. <button data-action='{:url("ad_del")}' data-table-id="NewsTable" data-rule="id#{id}" data-confirm="确定要批量删除分类吗?" class='layui-btn layui-btn-sm layui-btn-primary'>批量删除</button>
  9. <!--{/if}-->
  10. {/block}
  11. {block name="content"}
  12. <div class="layui-tab layui-tab-card">
  13. <ul class="layui-tab-title">
  14. <li>分类管理</li>
  15. </ul>
  16. <div class="layui-tab-content">
  17. <table id="NewsTable" data-url="{:sysuri()}" data-target-search="form.form-search"></table>
  18. </div>
  19. </div>
  20. {/block}
  21. {block name='script'}
  22. <script>
  23. $(function () {
  24. // 初始化表格组件
  25. $('#NewsTable').layTable({
  26. even: true, height: 'full',
  27. sort: {field: 'sort desc', type: 'desc'},
  28. where: {type: '{$type|default="index"}'},
  29. cols: [[
  30. {checkbox: true, fixed: true},
  31. {field: 'sort', title: '排序权重', align: 'center', width: 100, sort: true, templet: '#SortInputTpl'},
  32. {field: 'id', title: 'ID', align: "center", width: 80},
  33. {
  34. field: 'images', title: '封面', align: 'center', templet: function (d) {
  35. if (!d.images) return '';
  36. return layui.laytpl(`<div data-tips-image data-tips-hover class="headimg headimg-xs headimg-no margin-0" data-lazy-src="${d.images}"></div>`).render(d);
  37. }
  38. },
  39. {field: 'title', title: '标题', align: 'left', minWidth: 140},
  40. {field: 'source', title: '来源', align: 'left', minWidth: 140},
  41. {field: 'status', title: '状态', align: 'center', minWidth: 110, templet: '#StatusSwitchTpl'},
  42. {toolbar: '#toolbar', title: '操作面板', align: 'center', minWidth: 80, fixed: 'right'},
  43. ]]
  44. });
  45. // 数据状态切换操作
  46. layui.form.on('switch(StatusSwitch)', function (obj) {
  47. var data = {id: obj.value, status: obj.elem.checked > 0 ? 1 : 0};
  48. $.form.load("{:url('ad_state')}", data, 'post', function (ret) {
  49. if (ret.code < 1) $.msg.error(ret.info, 3, function () {
  50. $('#NewsTable').trigger('reload');
  51. }); else {
  52. $('#NewsTable').trigger('reload');
  53. }
  54. return false;
  55. }, false);
  56. });
  57. });
  58. </script>
  59. <!-- 列表排序权重模板 -->
  60. <script type="text/html" id="SortInputTpl">
  61. <input type="number" min="0" data-blur-number="0" data-action-blur="{:sysuri()}" data-value="id#{{d.id}};action#sort;sort#{value}" data-loading="false" value="{{d.sort}}" class="layui-input text-center">
  62. </script>
  63. <!-- 数据状态切换模板 -->
  64. <script type="text/html" id="StatusSwitchTpl">
  65. <!--{if auth("ad_state")}-->
  66. <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="已激活|已禁用" lay-filter="StatusSwitch" {{-d.status>0?'checked':''}}>
  67. <!--{else}-->
  68. {{-d.status ? '<b class="color-green">已启用</b>' : '<b class="color-red">已禁用</b>'}}
  69. <!--{/if}-->
  70. </script>
  71. <!-- 数据操作工具条模板 -->
  72. <script type="text/html" id="toolbar">
  73. <!--{if auth("ad_edit")}-->
  74. <a class="layui-btn layui-btn-primary layui-btn-sm" data-modal='{:url("ad_edit")}?id={{d.id}}'>编 辑</a>
  75. <!--{/if}-->
  76. <!--{if auth("ad_del")}-->
  77. <a class="layui-btn layui-btn-danger layui-btn-sm" data-action="{:url('ad_del')}" data-value="id#{{d.id}}" data-confirm="确定要删除分类吗?">删 除</a>
  78. <!--{/if}-->
  79. </script>
  80. {/block}