forked from kidgrow-microservices-platform

zhaoxiaohao
2021-03-01 7ea2a2cfe922c9b2d5c09c737d10a7f1ab5b50d1
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
<style>
    pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; }
    .string { color: green; }
    .number { color: darkorange; }
    .boolean { color: blue; }
    .null { color: magenta; }
    .key { color: red; }
</style>
 
<!-- index弹窗 -->
<form id="index-form" lay-filter="index-form" class="layui-form model-form" style="height:500px; overflow:auto !important;">
    <div class="layui-form-item layui-form-text" style="width: 430px; height:460px; margin-top: -20px">
        <pre class="layui-code" id="data"></pre>
    </div>
</form>
 
<script>
    layui.use(['layer', 'admin'], function () {
        let layer = layui.layer;
        let admin = layui.admin;
        // 回显user数据
        let indexName = admin.getTempData('indexName');
        if (indexName) {
            admin.req('api-search/admin/index', {'indexName':indexName}, function (data) {
                layer.closeAll('loading');
                if (0 == data.code) {
                    $('#data').html(syntaxHighlight(data.datas));
                } else {
                    layer.msg('获取索引信息失败', {icon: 2, time: 2000});
                }
            }, 'GET');
        }
    });
 
    function syntaxHighlight(json) {
        if (typeof json != 'string') {
            json = JSON.stringify(json, undefined, 2);
        }
        json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
        return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function(match) {
            var cls = 'number';
            if (/^"/.test(match)) {
                if (/:$/.test(match)) {
                    cls = 'key';
                } else {
                    cls = 'string';
                }
            } else if (/true|false/.test(match)) {
                cls = 'boolean';
            } else if (/null/.test(match)) {
                cls = 'null';
            }
            return '<span class="' + cls + '">' + match + '</span>';
        });
    }
</script>