1. 程式人生 > >一隻正在努力進化的程式猿

一隻正在努力進化的程式猿

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>COM站群</title>
    {% load staticfiles %}
    <link rel="stylesheet" href="{% static "layui/css/layui.css" %}">
</head>
<body class="layui-layout-body">
    <div class="layui-layout layui-layout-admin">
        {% include 'public/header.html' %}
        {% include 'public/left.html' %}
        <div class="layui-body">
            <table id="demo" lay-filter="demo"></table>
        </div>
    </div>
</body>
<script src="{% static "js/jquery.js" %}"></script>
<script src="{% static "layui/layui.all.js" %}"></script>
<script src="{% static 'js/crc32.js' %}"></script>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit">編輯基本資訊</a>
</script>
<script>
    layui.use('table', function(){
        var table = layui.table;
        //第一個例項
        table.render({
            elem: '#demo',
            method: 'post',
            height: 590,
            url: '/url_list',
            page: true,
            cols: [[ //表頭
                {type:'checkbox', fixed: 'left'},
                {field: 'index_url', title: 'URL',sort: true, fixed: 'left'},
                {fixed: 'right', title:"操作", width:200, align:'center', toolbar: '#barDemo'}
            ]]
        });
        //監聽工具條
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                layer.msg('ID:'+ data.id + ' 的檢視操作');
            } else if(obj.event === 'del'){
                layer.confirm('真的刪除行麼', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.alert('編輯行:<br>'+ JSON.stringify(data))
            }
        });
    });
</script>
</html>
def url_list(request):
    page = request.POST['page']
    limit = request.POST['limit']
    start = (int(page) - 1) * int(limit)
    end = int(page) * int(limit)
    urls = Urls.objects.filter(index_url__startswith="www.")
    count = len(urls)
    urls = Urls.objects.filter(index_url__startswith="www.")[start:end].values()
    urls = list(urls)
    data = {"code": 0, "msg": "", "count": count, "data": urls}
    return JsonResponse(data, safe=False)