自动化立体仓库 - WMS系统
pang.jiabao
2025-11-12 99458a90a21032ed17dd7ecf48ddb42051577438
API接口日志导出excel列错乱修复
2个文件已修改
44 ■■■■■ 已修改文件
src/main/webapp/static/js/apiLog/apiLog.js 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/apiLog/apiLog.html 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/apiLog/apiLog.js
@@ -30,7 +30,7 @@
            // ,{field: 'timestamp', align: 'center',title: '时间戳'}
            // ,{field: 'clientIp', align: 'center',title: 'URL',hide: true}
            ,{field: 'request', align: 'center',title: '请求内容'}
            ,{field: 'response', align: 'center',title: '操作内容'}
            ,{field: 'response', align: 'center',title: '响应内容'}
            // ,{field: 'err', align: 'center',title: '异常内容'}
            ,{field: 'result$', align: 'center',title: '结果', templet: '#resTpl', width: 80}
            // ,{field: 'status$', align: 'center',title: '状态'}
@@ -122,7 +122,38 @@
                        success: function (res) {
                            layer.closeAll();
                            if (res.code === 200) {
                                table.exportFile(titles,res.data,'xls');
                                var rows = res.data.map(function(arr) {
                                    return {
                                        namespace: arr[0],
                                        url: arr[1],
                                        request: arr[2],
                                        response: arr[3],
                                        result$: arr[4],
                                        createTime$: arr[5]
                                    };
                                });
                                // 格式化 JSON 字段(只处理 request 和 response)
                                var fixedData = rows.map(function(item){
                                    var newItem = {};
                                    fields.forEach(function(f){
                                        var val = item[f];
                                        if (f === 'request' || f === 'response') {
                                            if (val) {
                                                // 尝试格式化 JSON 并转义特殊符号
                                                try {
                                                    val = JSON.stringify(JSON.parse(val));
                                                } catch (e) {
                                                    // 非标准JSON就不格式化
                                                }
                                                val = val.replace(/"/g, '“');   // 替换双引号为全角引号,防止 Excel 混乱
                                                val = val.replace(/\n/g, '');    // 去掉换行
                                            }
                                        }
                                        newItem[f] = val == null ? '' : String(val);
                                    });
                                    return newItem;
                                });
                                table.exportFile(titles,fixedData,'xls');
                            } else if (res.code === 403) {
                                top.location.href = baseUrl+"/";
                            } else {
src/main/webapp/views/apiLog/apiLog.html
@@ -10,6 +10,11 @@
    <link rel="stylesheet" href="../../static/css/admin.css?v=318" media="all">
    <link rel="stylesheet" href="../../static/css/cool.css" media="all">
</head>
<style>
    div .layui-table-tool .layui-table-tool-self .layui-inline[title='导出']{
        display: none;
    }
</style>
<body>
<div class="layui-fluid">
@@ -45,10 +50,10 @@
</div>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
    <div class="layui-btn-container" style="display: flex; justify-content: flex-start; align-items: center; height: 100%;">
<!--        <button class="layui-btn layui-btn-sm" id="btn-add" lay-event="addData">新增</button>-->
<!--        <button class="layui-btn layui-btn-sm layui-btn-danger" id="btn-delete" lay-event="deleteData">删除</button>-->
<!--        <button class="layui-btn layui-btn-primary layui-btn-sm" id="btn-export" lay-event="exportData" style="float: right">导出</button>-->
        <button class="layui-btn layui-btn-primary layui-btn-sm" id="btn-export" lay-event="exportData" style="float: right">导出</button>
    </div>
</script>