<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
        <title>爬虫管理系统-小说精品屋</title>
        <link rel="stylesheet" href="/css/base.css?v=1"/>
        <link rel="stylesheet" href="/css/user.css"/>
    </head>
</head>
<body class="">

<div th:replace="crawl/header :: header">
</div>

<div class="main box_center cf">
    <div class="userBox cf">
        <div class="my_l">

            <ul class="log_list">
                <li><a class="link_1 on" href="/">爬虫源管理</a></li>
                <li><a class="link_1" href="/crawl/crawlSingleTask_list.html">单本采集管理</a></li>
                <li><a class="link_1" href="/crawl/crawlSource_test.html" target="_blank">规则测试</a></li>
                <!-- <li><a class="link_1 " href="/user/userinfo.html">批量小说爬取</a></li>
                 <li><a class="link_4 " href="/user/favorites.html">单本小说爬取</a></li>-->
            </ul>

        </div>
        <div class="my_r">
            <div class="my_bookshelf">
                <div class="title cf">
                    <h2 class="fl">爬虫源列表</h2>
                    <div class="fr"><a href="/crawl/crawlSource_add.html" class="btn_red">增加爬虫源</a>
                    </div>
                </div>

                <div id="divData" class="updateTable">
                    <table cellpadding="0" cellspacing="0">
                        <thead>
                        <tr>
                            <th class="style">
                                序号
                            </th>
                            <th class="chapter">
                                爬虫源
                            </th>
                            <th class="name">
                                创建时间
                            </th>
                            <th class="name">
                                更新时间
                            </th>
                            <th class="goread">
                                状态
                            </th>
                            <th class="goread">
                                操作
                            </th>
                        </tr>
                        </thead>
                        <tbody id="crawlSourceList">


                        </tbody>
                    </table>
                    <div class="pageBox cf" id="shellPage">
                    </div>
                </div>
                <!--<div id="divData" class="updateTable">
                    <table cellpadding="0" cellspacing="0">
                        <thead>
                        <tr>

                            <th class="name">
                                爬虫源（已开启的爬虫源）
                            </th>
                            <th class="chapter">
                                成功爬取数量（websocket实现）
                            </th>
                            <th class="time">
                            目标爬取数量
                            </th>
                            <th class="goread">
                                状态（正在运行，已停止）（一次只能运行一个爬虫源）
                            </th>
                            <th class="goread">
                                操作（启动，停止）
                            </th>
                        </tr>
                        </thead>
                        <tbody id="bookShelfList">



                        </tbody>
                    </table>
                    <div class="pageBox cf" id="shellPage">
                    </div>
                </div>-->
            </div>
        </div>
    </div>
</div>


</body>
<script src="/javascript/jquery-1.8.0.min.js" type="text/javascript"></script>
<script src="/layui/layui.all.js" type="text/javascript"></script>
<script src="/javascript/header.js" type="text/javascript"></script>
<script src="/javascript/user.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
    search(1, 10);

    var pageCrawlSourceList = null;

    function search(curr, limit) {

        $.ajax({
            type: "get",
            url: "/crawl/listCrawlByPage",
            data: {'curr': curr, 'limit': limit},
            dataType: "json",
            success: function (data) {
                if (data.code == 200) {
                    var crawlSourceList = data.data.list;
                    pageCrawlSourceList = data.data.list;
                    if (crawlSourceList.length > 0) {
                        var crawlSourceListHtml = "";
                        for (var i = 0; i < crawlSourceList.length; i++) {
                            var crawlSource = crawlSourceList[i];
                            crawlSourceListHtml += (" <tr class=\"book_list\" vals=\"291\">\n" +
                                "                            <td class=\"style bookclass\">\n" +
                                "                                [" + (i + 1) + "]\n" +
                                "                            </td>\n" +
                                "                            <td class=\"chapter\">\n" +
                                "                                " + crawlSource.sourceName + "</td>\n" +
                                "                            <td class=\"name\" valsc=\"291|2037554|1\">"
                                + crawlSource.createTime + "</td>\n" +
                                "                            <td class=\"name\">\n" +
                                "                                " + crawlSource.updateTime + "\n" +
                                "                            </td>\n" +
                                "                            <td class=\"goread\" id='sourceStatus" + crawlSource.id + "'>" + (crawlSource.sourceStatus == 0 ? '停止运行' : '正在运行') +
                                "                            </td>\n" +

                                " <td class=\"goread\" id='opt" + crawlSource.id + "'><a href='javascript:openOrStopCrawl(" + crawlSource.id + "," + crawlSource.sourceStatus + ")'>" + (crawlSource.sourceStatus == 0 ? '开启' : '关闭') + "  </a>" +
                                "<a href='javascript:updateCrawlSource(" + crawlSource.id + ")'>修改  </a>" +
                                "</td>                     </tr>");
                        }
                        $("#crawlSourceList").html(crawlSourceListHtml);

                        layui.use('laypage', function () {
                            var laypage = layui.laypage;

                            //执行一个laypage实例
                            laypage.render({
                                elem: 'shellPage' //注意，这里的 test1 是 ID，不用加 # 号
                                , count: data.data.total //数据总数，从服务端得到,
                                , curr: data.data.pageNum
                                , limit: data.data.pageSize
                                , jump: function (obj, first) {


                                    //obj包含了当前分页的所有参数，比如：
                                    console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                                    console.log(obj.limit); //得到每页显示的条数


                                    //首次不执行
                                    if (!first) {
                                        search(obj.curr, obj.limit);
                                    } else {

                                    }
                                }
                            });
                        });

                    }


                } else if (data.code == 1001) {
                    //未登录
                    location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);

                } else {
                    layer.alert(data.msg);
                }

            },
            error: function () {
                layer.alert('网络异常');
            }
        })

    }

    function updateCrawlSource(crawlSourceId) {

        localStorage.setItem("crawlSourceId", crawlSourceId);
        window.location.href = "/crawl/crawlSource_update.html";

    }

    function openOrStopCrawl(sourceId, status) {

        $.ajax({
            type: "POST",
            url: "/crawl/openOrCloseCrawl",
            data: {'sourceId': sourceId, 'sourceStatus': status == 0 ? 1 : 0},
            dataType: "json",
            success: function (data) {
                if (data.code == 200) {

                    if (status == 0) {
                        //开启
                        $("#sourceStatus" + sourceId).html("正在运行");
                        $("#opt" + sourceId).html("<a href='javascript:openOrStopCrawl(" + sourceId + "," + 1 + ")'>关闭</a>");
                    } else {
                        //关闭
                        $("#sourceStatus" + sourceId).html("停止运行");
                        $("#opt" + sourceId).html("<a href='javascript:openOrStopCrawl(" + sourceId + "," + 0 + ")'>开启</a>");
                    }


                } else if (data.code == 1001) {
                    //未登录
                    location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);

                } else {
                    layer.alert(data.msg);
                }

            },
            error: function () {
                layer.alert('网络异常');
            }
        })


    }
</script>
</html>
