page_cache.hbs 4.49 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="/servers">缓存管理</a></li>
            </ul>
            <h4>清理缓存</h4>
        </div>
    </div>
    <!-- media -->
</div>

<div class="contentpanel">
    <div class="row cache-panel">
        <div class="panel panel-default">
            <div class="panel-body">
                <div class="col-sm-6">
                    <div class="operations mb20">
                        
                    </div>
                    <div class="query">
                        <textarea name="" id="uri" cols="30" rows="20" class="form-control" placeholder="支持多条换行输入">http://m.yohobuy.com</textarea>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="panel">
                        <div class="panel-heading">
                            <h4 class="panel-title">日志</h4>
                        </div><!-- panel-heading -->
                        <div class="panel-body yoho-log-dark">
                            <div class="results-list ">

                            </div><!-- results-list -->
                        </div><!-- panel-body -->
                    </div><!-- panel -->
                </div>
            </div>
            <div class="panel-footer">
                <select id="stores" class="form-control input-sm selcet-auto pull-left mr20">
                    {{#each storeList}}
                    <option value="{{tableName}}">{{name}}</option>
                    {{/each}}
                </select>
                <button class="btn btn-warning btn-clear pull-left">清除</button>
                <div class="result pull-left ml20"></div>
                <button class="btn btn-danger btn-all-clear pull-right">全网刷新</button>
            </div>
        </div>
    </div>
</div>

<script>
    var posing = false;
    $(document).on('ready pjax:success', function() {
        $('.btn-success').click(function() {
            if (posing) {
                return;
            }
            posing = true;
            $('.page-count>span').text('查询中..');
            $('.btn-search').addClass('disabled');
            var tableName = $('#stores').val();
            var uri = $('#uri').val();
            if (uri && tableName) {
                $.post('/page_cache/search', {
                    query_uri: uri,
                    table_name: tableName
                }, function (res) {
                    posing = false;
                    $('.btn-search').removeClass('disabled');
                    if (res.code === 200) {
                        $('.page-count>span').text(res.data);
                    } else {
                        $('.page-count>span').text('查询失败');
                    }
                    
                })
            }
        });
        $('.btn-clear').click(function() {
            var tableName = $('#stores').val();
            var uri = $('#uri').val();
            if (uri && tableName) {
                $logs.empty();
                $.post('/page_cache/clear', {
                    query_uri: uri,
                    table_name: tableName
                }, function(res) {
                });  
            }
        })
        $('.btn-all-clear').click(function() {
            var tableName = $('#stores').val();
            if (tableName) {
                $logs.empty();
                $.post('/page_cache/clear/all', {
                    table_name: tableName
                }, function(res) {
                });  
            }
        })
        function layoutResize() {
            $('.yoho-log-dark').height($('body').height() - 450);
        }

        $(window).resize(function() {
            layoutResize();
        });

        layoutResize();
        var $logs = $('.yoho-log-dark .results-list');
        var $dark = $('.yoho-log-dark');
        function appendLog(message) {
            var html = '<p><span class="message">- ' + message + '</span></p>';
            $logs.append(html);
            $dark.scrollTop($logs[0].scrollHeight);
        }

        var ws = io();
        ws.on('connect', function() {
            ws.on('/page_cache/log', function(data) {
                appendLog(data.message)
            });
        });

    });
</script>