colly_wyx
2018-05-29 d479d9fbcb37f8b861031c94a83d0e37761210c5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
 
    <link rel="stylesheet" href="/themes/AdminLTE/plugins/datatables/dataTables.bootstrap.css">
 
    <section class="content-header">
      <h1>
        文章管理
      </h1>
      <ol class="breadcrumb">
        <li><a href="/admin/index/index"><i class="fa fa-dashboard"></i> 平台首页</a></li>
        <li><a href="/article/manager/list">文章管理</a></li>
        <li class="active">文章列表</li>
      </ol>
    </section>
 
     <!-- Main content -->
    <section class="content">
      <div class="row">
        <div class="col-xs-12">
          <div class="box">
            <div class="box-header">
              <h3 class="box-title">文章列表</h3>
            </div>
            
            <!-- /.box-header -->
            <div class="box-body">
              <table id="table_list" class="table table-bordered table-hover">
                <thead>
                  <tr>
                    <th>文章名称</th>
                    <th>文章分类</th>
                    <th>是否发布</th>
                    <th>创建时间</th>
                    <th>操作</th>
                  </tr>
                </thead>
              </table>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </section>
 
<script>
  $(function () {
 
    var config = {
      "dom": 'l<"#toolbar">frtip',
      /*
       * 默认为false
       * 当表格在处理的时候(比如排序操作)是否显示“处理中...”
       * 当表格的数据中的数据过多以至于对其中的记录进行排序时会消耗足以被察觉的时间的时候,该选项会有些用处
       */
         "processing":true,
      /*
        * 默认为true
        * 是否允许终端用户从一个选择列表中选择分页的页数,页数为10,25,50和100,需要分页组件bPaginate的支持
        */
        "lengthChange":false,
        "serverSide":true,
        "autoWidth": true,
        "language":{
          "lengthMenu": "每页显示 _MENU_ 条",
          "emptyTable": "没有任何数据记录",
          "processing": "正在载入数据...",
          "search": "搜索 _INPUT_",
          "info": "显示 _START_ 至 _END_ 项结果,共 _TOTAL_ 项",
          "zeroRecords": "暂时没有任何数据记录",
          "sInfoEmpty": "",
          "paginate": {
            "first": "首页",
            "previous": "上一页",
            "next": "下一页",
            "last": "尾页"
          },
        },
        "ajax":{
          "url": "/article/manager/list",
          "type":"POST",
        },
        "columns":[
          {
            "data":"name",
            "orderable":false
          },
          {
            "data":"category",
            "orderable":false
          },
          {
            "data":"is_publish",
            "orderable":false
          },
          {
            "data":"create_time",
            "orderable":false
          },
          {
            "data":null,
            "orderable":false
          },
        ],
        "columnDefs": [
          {
            "targets":1,
            "searchable":false,
            "render":function(data, type, row, meta){
              if(data == 0) {
                return "未选择分类";
              }
              else if(data == 1){
                return "平台通知";
              }
              else if(data == 2){
                return "行业资讯";
              }
              else if(data == 3){
                return "防辐射知识";
              }
              else if(data == 4){
                return "母婴知识";
              }
              else{
                return '';
              }
            }
          },
          {
            "targets":2,
            "searchable":false,
            "render":function(data, type, row, meta){
              if(data == 0) {
                return "否";
              }
              else{
                return "是";
              }
            }
          },
          {
            "targets":4,
            "searchable":false,
            "render":function(data, type, row, meta){
              return '<a class="btn btn-primary" href="/<?php echo $route['module']?>/<?php echo $route['controller']?>/edit/id/'+row['_id']+'">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn btn-danger del" data-id="'+row['_id']+'" data-target="/<?php echo $route['module']?>/<?php echo $route['controller']?>/del">删除</a>'
            }
          }
        ],
        "initComplete": function(){
          $("#toolbar").css("width", "100px").css("display", "inline").css("margin-left", "10px");
          $("#toolbar").append('<a id="build"  class="btn btn-success" data-toggle="modal" data-target="" href="/<?php echo $route['module']?>/<?php echo $route['controller']?>/add"> <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>添加 <a> ');
          $(".del").bind('click', function(){
            if(confirm('您确定要删除这条信息?')){
              $.ajax({
                type: "POST",
                url: $(this).data('target'),
                data:  {id:$(this).data('id')},
                success:function(response){
                  var dataObj=jQuery.parseJSON(response);
                  if(dataObj.code == 200)
                  {
                    $.scojs_message('删除成功', $.scojs_message.TYPE_OK);
                    setTimeout(function(){window.location.href = "/<?php echo $route['module']?>/<?php echo $route['controller']?>/<?php echo $route['action']?>";}, 600);
                  }else
                  {
                    $.scojs_message(dataObj.content, $.scojs_message.TYPE_ERROR);
                  }
                },
                error: function (request, status, error) {
                  $.scojs_message(request.responseText, $.scojs_message.TYPE_ERROR);
                }
              });
            }
            else{
              return false;
            }
          });
        }
 
    }
    $("#table_list").DataTable(config);
 
    
  });
</script>