forked from kidgrow-microservices-platform

zhaoxiaohao
2020-04-27 b5d80f607c87f04a70d09a16f456612dab69aff9
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
<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">慢查询日志</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>慢查询日志</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
            搜索:
            <select id="slowQueryLog-search-key">
                <option value="_all">全文搜索</option>
                <option value="query_str">查询语句</option>
            </select>&emsp;
            <input id="slowQueryLog-search-value" class="layui-input search-input" style="width: 300px" type="text" placeholder="输入关键字"/>&emsp;
            <button id="slowQueryLog-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
        </div>
 
        <table class="layui-table" id="slowQueryLog-table" lay-filter="slowQueryLog-table"></table>
    </div>
</div>
<script>
    layui.use(['form', 'table', 'util', 'config', 'admin'], function () {
        let table = layui.table;
        let config = layui.config;
        let util = layui.util;
 
        // 渲染表格
        table.render({
            elem: '#slowQueryLog-table',
            url: config.base_server + 'api-log/slowQueryLog',
            method: 'GET',
            headers:{'Authorization': 'Bearer ' + config.getToken().access_token},
            page: true,
            cols: [[
                {type: 'numbers'},
                {
                    field: 'timestamp', width: 200, sort: true, templet: function (d) {
                        return util.toDateString(d.timestamp, 'yyyy-MM-dd HH:mm:ss');
                    }, title: '日志时间'
                },
                {field: 'query_str', sort: true, title: '查询语句', width: 410},
                {field: 'query_time', sort: true, title: '查询时间(ms)', width: 120},
                {field: 'lock_time', sort: true, title: '锁等待时间(ms)', width: 140},
                {field: 'rows_sent', sort: true, title: '返回行数', width: 110},
                {field: 'rows_examined', sort: true, title: '优化器扫描行数', width: 140}
            ]]
        });
 
        // 搜索按钮点击事件
        $('#slowQueryLog-btn-search').click(function () {
            let key = $('#slowQueryLog-search-key').val();
            let value = $('#slowQueryLog-search-value').val();
            if (key != '_all' && value) {
                value = key + ':' + value;
            }
            table.reload('slowQueryLog-table', {where: {queryStr: value}});
        });
    });
</script>