crawler.hbs 3.19 KB
<div class="pageheader">
    <div class="media">
        <div class="pageicon pull-left">
            <i class="fa fa-th-list"></i>
        </div>
        <div class="media-body">
            <ul class="breadcrumb">
                <li><a href=""><i class="glyphicon glyphicon-home"></i></a></li>
                <li><a href="">防爬虫设置</a></li>
                <li>{{main_name}}{{listName}}</li>
            </ul>
            <h4>{{main_name}}{{listName}}设置</h4>
        </div>
    </div>
    <!-- media -->
</div>
<!-- pageheader -->

<div class="contentpanel page-servers">
    <div class="panel panel-primary-head">
        <!-- panel-heading -->
        <div class="input-group" style="margin: 20px 20px 20px 0">
            <input id="val" type="text" class="form-control" placeholder="请输入..." style="width: 500px;">
            <span class="input-group-btn" style="float: left;">
                <button class="btn btn-default" type="button" id="add_black">添加至{{listName}}</button>
            </span>
        </div>
        <table id="table-servers" class="table table-striped table-bordered responsive" style="border: 1px solid #ddd;">
            <thead class="">
            <tr>
                <th>{{main_name}}</th>
                <th>操作</th>
            </tr>
            </thead>

            <tbody>
            {{#each list}}
                <tr>
                    <td>{{name}}</td>
                    <td>
                        <button class="btn btn-danger btn-xs server-del">删除</button>
                    </td>
                </tr>
            {{/each}}
            </tbody>
        </table>
    </div>
    <!-- panel -->
</div>


<script>
    var isBlack = '{{listName}}' === '黑名单';
    var path = location.pathname.match(/\/crawler_(white|black)\/(.*)/)[2];

    $('#add_black').on('click', function() {
        var val = $('#val').val();
        if (!val)return;
        var dataId = $($("tbody").find("tr")[$("tbody").find("tr").length - 1]).find('[data-id]').attr('data-id');
        $('tbody').append('<tr><td>' + val + '</td><td><button class="btn btn-danger btn-xs server-del">删除</button></td></tr>');
        $('#val').val('');


        var vallists = [];
        $('tr td:first-child').each(function() {
            vallists.push($(this).html());
        });
        vallists = JSON.stringify(vallists);

        if (isBlack) {
            $.get('/crawler_black/change_' + path + '?path=/crawler/' + path + '_blacklists&val=' + vallists);
        } else {
            $.get('/crawler_white/change_' + path + '?path=/crawler/' + path + '_whitelists&val=' + vallists);

        }
    });

    $('tbody').on('click', '.server-del', function() {
        $(this).parent().parent().remove();

        var vallists = [];
        $('tr td:first-child').each(function() {
            vallists.push($(this).html());
        });
        vallists = (vallists.length ? JSON.stringify(vallists) : '');

        if (isBlack) {
            $.get('/crawler_black/change_' + path + '?path=/crawler/' + path + '_blacklists&val=' + vallists);
        } else {
            $.get('/crawler_white/change_' + path + '?path=/crawler/' + path + '_whitelists&val=' + vallists);
        }
    });

</script>