list.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <div class="layui-layout layui-layout-admin" style="padding-left: 20px;">
  2. <div class="layui-row" style="margin-top: 20px;">
  3. <div class="layui-col-xs6">
  4. <a class="layui-btn" data-type="tabAdd" id="add_source" href="javascript:;">新增</a>
  5. </div>
  6. <div class="layui-col-xs6 search_text">
  7. <form class="layui-form" action="" onsubmit="javascript:return false;">
  8. <div class="demoTable">
  9. <div class="layui-inline" style="width: 40%">
  10. <input class="layui-input" name="sourceName" id="sourceName" autocomplete="off" placeholder="资源名称" >
  11. </div>
  12. <button class="layui-btn" data-type="reload">查询</button>
  13. </div>
  14. </form>
  15. </div>
  16. </div>
  17. <table class="layui-hide" id="table_list" lay-filter="table_filter">
  18. </table>
  19. <script type="text/html" id="bar">
  20. <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  21. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
  22. </script>
  23. </div>
  24. <script>
  25. layui.use(['table','form','element'], function(){
  26. var table = layui.table;
  27. var form = layui.form;
  28. var element = layui.element;
  29. //方法级渲染
  30. table.render({
  31. elem: '#table_list'
  32. ,url: '/apisource/table'
  33. ,cols: [[
  34. // {checkbox: true, fixed: true},
  35. {field:'id', title: 'ID', align:'center',sort: true, width:150}
  36. ,{field:'source_name',title: '资源名称'}
  37. ,{field:'group_name',title: '所属分组'}
  38. ,{field:'create_time', title: '创建时间'}
  39. ,{field:'update_time', title: '修改时间'}
  40. ,{fixed: 'right', width:160, align:'center', toolbar: '#bar'}
  41. ]]
  42. ,id: 'listReload'
  43. ,page: true
  44. ,height: "full-130"
  45. });
  46. var $ = layui.$, active = {
  47. reload: function(){
  48. table.reload('listReload', {
  49. where: {
  50. sourceName: $('#sourceName').val(),
  51. }
  52. });
  53. }
  54. };
  55. $("#add_source").on("click",function() {
  56. layer.open({
  57. type: 2,
  58. shade: 0.3,
  59. id:1,
  60. title:"新增资源",
  61. content: '/apisource/add',
  62. area:['500px','300px'],
  63. cancel:function(){
  64. window.location.reload();
  65. layer.close(index);
  66. }
  67. });
  68. })
  69. //监听工具条
  70. table.on('tool(table_filter)', function(obj){
  71. var data = obj.data;
  72. if(obj.event === 'detail'){
  73. //layer.msg('ID:'+ data.id + ' 的查看操作');
  74. } else if(obj.event === 'del'){
  75. layer.confirm('真的删除【'+data.source_name+'】资源么', function(index){
  76. var jsData = {'id':data.id}
  77. $.post('{{urlfor "ApiSourceController.AjaxDel"}}', jsData, function (out) {
  78. if (out.status == 0) {
  79. layer.alert('删除成功了', {icon: 1},function(index){
  80. layer.close(index);
  81. window.location.reload();
  82. });
  83. } else {
  84. layer.msg(out.message)
  85. }
  86. }, "json");
  87. obj.del();
  88. layer.close(index);
  89. });
  90. } else if(obj.event === 'edit'){
  91. layer.open({
  92. type: 2,
  93. shade: 0.3,
  94. id:1,
  95. title:"编辑-"+data.source_name,
  96. content: '/apisource/edit?id='+data.id,
  97. area:['500px','300px'],
  98. });
  99. }
  100. });
  101. $('.demoTable .layui-btn').on('click', function(){
  102. var type = $(this).data('type');
  103. active[type] ? active[type].call(this) : '';
  104. });
  105. });
  106. </script>