<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('接口调用日志列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <input type="hidden" id="platformInterfacetype" name="platformInterfacetype" th:value="${shareType}">
                        <li>
                            <label>登录名：</label>
                            <input type="text" name="loginName"/>
                        </li>
                        <li>
                            <label>调用部门：</label>
                            <input type="text" name="deptName" onclick="selectDeptTree()" id="treeName" placeholder="请选择接口调用部门"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:log:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    let viewFlag = [[${@permission.hasPermi('system:log:view')}]];
    let prefix = ctx + "system/log";
    let platform_interfacetype_datas = [[${@dict.getType('platform_interfacetype')}]];
    let shareType_datas = [[${@dict.getType('share_type')}]];
    let intId = [[${intId}]];
    let shareType = [[${shareType}]];

    $(function () {
        var options = {
            url: prefix + "/list?id="+intId,
            detailUrl: prefix + "/detail/{id}",
            exportUrl: prefix + "/export",
            modalName: "接口调用日志",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'status',
                    title: '状态',
                    visible: false
                },
                {
                    field: 'remark',
                    title: '注释',
                    visible: false
                },
                {
                    field: 'loginUser',
                    title: '登录人',
                    visible: false
                },
                {
                    field: 'deptId',
                    title: '调用部门ID',
                    visible: false
                },
                {
                    field: 'deptName',
                    title: '调用部门'
                },
                {
                    field: 'loginName',
                    title: '登录名'
                },
                {
                    field: 'createTime',
                    title: '调用时间'
                },
                {
                    field: 'interfaceinfoId',
                    title: '调用接口id',
                    visible: false
                },
                {
                    field: 'interfaceinfoName',
                    title: '调用接口名'
                },
                {
                    field: 'operationStatus',
                    title: '调用结果',
                    sortable: true,
                    formatter: function (value,row,index) {
                        return value == 1 ? '<span class="badge badge-primary">成功</span>' : '<span class="badge badge-danger">失败</span>';
                    }
                },
                {
                    field: 'ipaddress',
                    title: 'ip地址'
                },
                {
                    field: 'os',
                    title: '操作系统',
                    cellStyle:formatTableUnit,
                    formatter: paramsMatter

                },
                {
                    field: 'platformInterfacetype',
                    title: '接口类型',
                    visible: false,
                    formatter: function (value, item, index) {
                        return $.table.selectDictLabel(shareType_datas, item.platformInterfacetype);
                    }
                },
                {
                    field: 'browser',
                    title: '访问浏览器',
                    visible: false
                },
                {
                    field: 'param',
                    title: '参数条件',
                    visible: false
                },
                {
                    field: 'results',
                    title: '返回结果',
                    visible: false
                },
                {
                    field: 'operationQuantity',
                    title: '操作数量',
                    visible: false
                },
                {
                    field: 'operationStatus',
                    title: '操作状态',
                    visible: false
                },
                {
                    field: 'exceptionLog',
                    title: '异常记录',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-search"></i>详情</a> ');
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });

    //表格超出宽度鼠标悬停显示td内容
    function paramsMatter(value,row,index) {
        let span=document.createElement("span");
        span.setAttribute("title",value);
        span.innerHTML = value;
        return span.outerHTML;
    }
    //td宽度以及内容超过宽度隐藏
    function formatTableUnit(value, row, index) {
        return {
            css: {
                "white-space": "nowrap",
                "text-overflow": "ellipsis",
                "overflow": "hidden",
                "max-width":"150px"
            }
        }
    }


    /**选择部门树**/
    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero){
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }
</script>
</body>
</html>
