layui_jxs.html 4.6 KB
Newer Older
H
hjdhnx 已提交
1 2 3 4 5 6 7 8 9 10
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>解析管理</title>
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <link rel="stylesheet" href="/static/plugin/layui/css/layui.css">
  <link rel="stylesheet" href="/static/plugin/layui/ext/soulTable/soulTable.css" media="all"/>
</head>
<body>
H
hjdhnx 已提交
11
<table id="myTable" lay-filter="myTable"></table>
H
hjdhnx 已提交
12
<script type="text/html" id="toolbar">
H
hjdhnx 已提交
13
  <div class="layui-btn-container">
H
hjdhnx 已提交
14
<!--    <button class="layui-btn layui-btn-sm" lay-event="clearFilter">清除所有筛选条件</button>-->
H
hjdhnx 已提交
15 16
<!--    <button class="layui-btn layui-btn-sm" lay-event="getData">获取当前页数据</button>-->
    <button class="layui-btn layui-btn-sm" lay-event="saveData">保存拖拽排序结果</button>
H
hjdhnx 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
  </div>
</script>
<script type="text/html" id="bar">
  <a class="layui-btn layui-btn-xs" lay-event="set_top"></a>
  <a class="layui-btn layui-btn-xs" lay-event="set_bottom"></a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"></a>
</script>
<script src="/static/plugin/layui/layui.js"></script>
<script>
  // 自定义模块
  layui.config({
    base: '/static/plugin/layui/ext/',   // 模块目录
    version: 'v1.6.4'
  }).extend({
    soulTable: 'soulTable/soulTable',
    tableChild: 'soulTable/tableChild',
    tableMerge: 'soulTable/tableMerge',
    tableFilter: 'soulTable/tableFilter',
    excel: 'soulTable/excel',
  });

  layui.use(['form', 'table','soulTable'], function () {
    var table = layui.table, soulTable = layui.soulTable;
H
hjdhnx 已提交
40
    var $ = layui.$;
H
hjdhnx 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    soulTable.config({
          rowDrag: true
    });
    // 后台分页
    table.render({
      elem: '#myTable'
      ,id: 'myTable'
      ,url: '/layui/api/jx_list'
      ,height: 1000
      ,toolbar: '#toolbar'
      ,page: true
      ,limit:100
    ,limits:[20,40,60,80,100,150,200,300,500]
      ,cols: [[
        {type: 'checkbox', fixed: 'left'},
H
hjdhnx 已提交
56
        {field: 'id', title: '编号', width: 80, sort: true},
H
hjdhnx 已提交
57
        {field: 'name', title: '名称', width: 200, sort: true, filter: true},
H
hjdhnx 已提交
58 59 60 61
        {field: 'state', title: '状态', width: 60},
        {field: 'order', title: '顺序', width: 80,sort: true},
        {field: 'url', title: '接口', minWidth: 200, sort: true},
        {field: 'type', title: '类型', width: 80 , filter: true},
H
hjdhnx 已提交
62 63 64 65 66 67 68 69 70 71
        // {field: 'header', title: '请求头', width: 112,  filter: {split:','}, sort:true},
        {field: 'header', title: '请求头', width: 200, sort:true},
        {field: 'ext', title: '扩展信息', minWidth: 200, sort:true},
        {title: '操作', width: 156, fixed: 'right', templet: '#bar'}
      ]]
      ,done: function () {
        soulTable.render(this)
      }
    });

H
hjdhnx 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93

    function saveData(data){
      if(!Array.isArray(data) || data.length < 1){
      return layer.msg('待保存的数据有误');
      }
      let params = {"data":JSON.stringify(data)};
      // console.log(params);
      $.post("/admin/parse/save_data",params,function(res,status){
           console.log(res);
           if(res.code === 200){
             table.reload('myTable', {
                // page: {
                //     curr: 3 //重新从第 1 页开始
                // }
            });
           }else{
               console.log('修改失败了...');
               return false
           }
       });
    }

H
hjdhnx 已提交
94 95 96
    // 工具栏事件
    table.on('toolbar(myTable)', function(obj){
      var id = obj.config.id;
H
hjdhnx 已提交
97
      // console.log(id);
H
hjdhnx 已提交
98 99 100 101 102 103
      if (obj.event === 'clearFilter') {
        // 清除所有筛选条件并重载表格
        // 参数: tableId
        soulTable.clearFilter('myTable')
      }else if(obj.event === 'getData'){
        var getData = table.getData(id);
H
hjdhnx 已提交
104
        // console.log(getData);
H
hjdhnx 已提交
105
        layer.alert(layui.util.escape(JSON.stringify(getData)));
H
hjdhnx 已提交
106 107 108 109 110 111 112
      }else if(obj.event === 'saveData'){
        layer.confirm('确定保存当前的排序结果?保存后将刷新数据库和当前页面', function(index){
          var getData = table.getData(id);
          // console.log(getData);
          saveData(getData);
          layer.close(index);
        });
H
hjdhnx 已提交
113 114 115 116
      }
    });

    //触发单元格工具事件
H
hjdhnx 已提交
117
    table.on('tool(myTable)', function(obj) { // 双击 toolDouble
H
hjdhnx 已提交
118 119
      console.log(obj);
      if(obj.event === 'del'){
H
hjdhnx 已提交
120 121 122 123 124
        layer.msg('未开发功能:删除...')
      }else if(obj.event === 'set_top'){
        layer.msg('未开发功能:置顶...')
      }else if(obj.event === 'set_bottom'){
        layer.msg('未开发功能:置底...')
H
hjdhnx 已提交
125 126 127 128 129 130 131 132 133
      }
    });
  // }, null, 'define');
  });


</script>
</body>
</html>