367 lines
12 KiB
Vue
367 lines
12 KiB
Vue
<template>
|
|
<div class="app-container">
|
|
<div class="head-container">
|
|
<div v-if="crud.props.searchToggle">
|
|
<el-form
|
|
:inline="true"
|
|
class="demo-form-inline"
|
|
label-position="right"
|
|
label-width="90px"
|
|
label-suffix=":"
|
|
>
|
|
<el-form-item label="关键字">
|
|
<el-input
|
|
v-model="query.keyword"
|
|
clearable
|
|
size="mini"
|
|
placeholder="请输入关键字查询"
|
|
class="filter-item"
|
|
style="width: 200px;"
|
|
@keyup.enter.native="crud.toQuery"
|
|
/>
|
|
</el-form-item>
|
|
<el-form-item label="接口走向">
|
|
<el-select
|
|
v-model="query.direction"
|
|
clearable
|
|
size="mini"
|
|
placeholder="请选择"
|
|
class="filter-item"
|
|
@change="crud.toQuery"
|
|
>
|
|
<el-option label="出站" :value="0" />
|
|
<el-option label="入站" :value="1" />
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item label="系统标识">
|
|
<el-select
|
|
v-model="query.systemFlag"
|
|
clearable
|
|
size="mini"
|
|
placeholder="请选择"
|
|
class="filter-item"
|
|
@change="handleSystemFlagChange"
|
|
>
|
|
<el-option label="mes" value="mes" />
|
|
<el-option label="sap" value="sap" />
|
|
<el-option label="crm" value="crm" />
|
|
<el-option label="mdm" value="mdm" />
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item label="业务类型" class="biz-code-item">
|
|
<el-select
|
|
v-model="query.bizCode"
|
|
clearable
|
|
filterable
|
|
size="mini"
|
|
placeholder="请选择"
|
|
class="filter-item"
|
|
@change="crud.toQuery"
|
|
>
|
|
<el-option
|
|
v-for="item in bizCodeList"
|
|
:key="item.bizCode"
|
|
:label="item.bizDesc"
|
|
:value="item.bizCode"
|
|
/>
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item label="状态">
|
|
<el-select
|
|
v-model="query.status"
|
|
clearable
|
|
size="mini"
|
|
placeholder="请选择"
|
|
class="filter-item"
|
|
@change="crud.toQuery"
|
|
>
|
|
<el-option label="SUCCESS" value="SUCCESS" />
|
|
<el-option label="FAIL" value="FAIL" />
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item label="请求时间">
|
|
<el-date-picker
|
|
v-model="query.createTime"
|
|
type="daterange"
|
|
value-format="yyyy-MM-dd HH:mm:ss"
|
|
start-placeholder="开始日期"
|
|
end-placeholder="结束日期"
|
|
:default-time="['00:00:00', '23:59:59']"
|
|
@change="crud.toQuery"
|
|
/>
|
|
</el-form-item>
|
|
<rrOperation />
|
|
</el-form>
|
|
</div>
|
|
<crudOperation>
|
|
<el-button
|
|
slot="right"
|
|
class="filter-item"
|
|
type="primary"
|
|
icon="el-icon-folder-checked"
|
|
:loading="archiveLoading"
|
|
@click="handleArchive"
|
|
>
|
|
日志归档
|
|
</el-button>
|
|
</crudOperation>
|
|
</div>
|
|
<!--表格渲染-->
|
|
<el-table
|
|
ref="table"
|
|
v-loading="crud.loading"
|
|
:data="crud.data"
|
|
style="width: 100%;"
|
|
:row-style="{height: '50px'}"
|
|
:cell-style="{fontSize: '14px'}"
|
|
@selection-change="crud.selectionChangeHandler"
|
|
>
|
|
<el-table-column prop="direction" label="接口走向" width="100">
|
|
<template slot-scope="scope">
|
|
<el-tag v-if="scope.row.direction === 0" type="success"><i class="el-icon-upload2"></i>出站</el-tag>
|
|
<el-tag v-else-if="scope.row.direction === 1" type="primary"><i class="el-icon-download"></i>入站</el-tag>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column prop="systemFlag" label="系统标识" width="100" />
|
|
<el-table-column prop="bizCode" label="业务类型" width="260" />
|
|
<el-table-column prop="bizDesc" label="业务描述" show-overflow-tooltip width="500" />
|
|
<el-table-column prop="status" label="状态" width="100">
|
|
<template slot-scope="scope">
|
|
<el-tag v-if="scope.row.status === 'SUCCESS'" type="success">请求成功</el-tag>
|
|
<el-tag v-else-if="scope.row.status === 'FAIL'" type="danger">请求失败</el-tag>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column prop="costTime" label="耗时(ms)" width="100" align="center">
|
|
<template slot-scope="scope">
|
|
<el-tag v-if="scope.row.costTime <= 300" type="success">{{ scope.row.costTime }}ms</el-tag>
|
|
<el-tag v-else-if="scope.row.costTime <= 1000" type="warning">{{ scope.row.costTime }}ms</el-tag>
|
|
<el-tag v-else type="danger">{{ scope.row.costTime }}ms</el-tag>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column prop="createTime" label="请求时间" width="180">
|
|
<template slot-scope="scope">
|
|
<span>{{ parseTime(scope.row.createTime) }}</span>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column prop="requestParams" label="请求参数" show-overflow-tooltip min-width="200" />
|
|
<el-table-column prop="responseBody" label="响应结果" show-overflow-tooltip min-width="200" />
|
|
<el-table-column label="详情" width="100" fixed="right">
|
|
<template slot-scope="scope">
|
|
<el-button size="mini" type="primary" plain @click="showDetail(scope.row)">查看详情</el-button>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
<!--分页组件-->
|
|
<pagination />
|
|
|
|
<!-- 详情抽屉 -->
|
|
<el-drawer
|
|
:visible.sync="drawerVisible"
|
|
title="接口日志详情"
|
|
direction="rtl"
|
|
size="60%"
|
|
:before-close="handleCloseDrawer"
|
|
>
|
|
<div class="drawer-content">
|
|
<el-descriptions :column="2" border size="small">
|
|
<el-descriptions-item label="日志ID">{{ currentRow.logId }}</el-descriptions-item>
|
|
<el-descriptions-item label="链路追踪ID">{{ currentRow.traceId }}</el-descriptions-item>
|
|
<el-descriptions-item label="接口走向">
|
|
<el-tag v-if="currentRow.direction === 0" type="success" size="small"><i class="el-icon-upload2"></i>出站</el-tag>
|
|
<el-tag v-else-if="currentRow.direction === 1" type="primary" size="small"><i class="el-icon-download"></i>入站</el-tag>
|
|
</el-descriptions-item>
|
|
<el-descriptions-item label="系统标识">{{ currentRow.systemFlag }}</el-descriptions-item>
|
|
<el-descriptions-item label="业务类型">{{ currentRow.bizCode }}</el-descriptions-item>
|
|
<el-descriptions-item label="业务描述">{{ currentRow.bizDesc }}</el-descriptions-item>
|
|
<el-descriptions-item label="接口地址" :span="2">{{ currentRow.apiUrl }}</el-descriptions-item>
|
|
<el-descriptions-item label="请求方法">{{ currentRow.requestMethod }}</el-descriptions-item>
|
|
<el-descriptions-item label="请求IP">{{ currentRow.requestIp }}</el-descriptions-item>
|
|
<el-descriptions-item label="状态">
|
|
<el-tag v-if="currentRow.status === 'SUCCESS'" type="success" size="small">SUCCESS</el-tag>
|
|
<el-tag v-else-if="currentRow.status === 'FAIL'" type="danger" size="small">FAIL</el-tag>
|
|
</el-descriptions-item>
|
|
<el-descriptions-item label="响应状态码">{{ currentRow.responseStatus }}</el-descriptions-item>
|
|
<el-descriptions-item label="耗时">{{ currentRow.costTime }}ms</el-descriptions-item>
|
|
<el-descriptions-item label="请求时间">{{ parseTime(currentRow.createTime) }}</el-descriptions-item>
|
|
<el-descriptions-item label="错误信息" :span="2" v-if="currentRow.errorMsg">
|
|
<span style="color: #f56c6c;">{{ currentRow.errorMsg }}</span>
|
|
</el-descriptions-item>
|
|
</el-descriptions>
|
|
|
|
<el-divider content-position="left">请求头</el-divider>
|
|
<pre class="json-content">{{ formatJson(currentRow.requestHeaders) }}</pre>
|
|
|
|
<el-divider content-position="left">请求参数</el-divider>
|
|
<pre class="json-content">{{ formatJson(currentRow.requestParams) }}</pre>
|
|
|
|
<el-divider content-position="left">响应结果</el-divider>
|
|
<pre class="json-content">{{ formatJson(currentRow.responseBody) }}</pre>
|
|
</div>
|
|
</el-drawer>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import CRUD, { presenter, header } from '@crud/crud'
|
|
import rrOperation from '@crud/RR.operation'
|
|
import crudOperation from '@crud/CRUD.operation'
|
|
import pagination from '@crud/Pagination'
|
|
import apiLog from '@/api/monitor/sysapilog'
|
|
|
|
export default {
|
|
name: 'SysApiLog',
|
|
components: { rrOperation, crudOperation, pagination },
|
|
cruds() {
|
|
return CRUD({
|
|
title: '接口日志',
|
|
url: 'api/sysApiLog',
|
|
query: {
|
|
createTime: [new Date(), new Date()]
|
|
}
|
|
})
|
|
},
|
|
mixins: [presenter(), header()],
|
|
data() {
|
|
return {
|
|
drawerVisible: false,
|
|
currentRow: {},
|
|
bizCodeList: [],
|
|
archiveLoading: false
|
|
}
|
|
},
|
|
created() {
|
|
this.crud.optShow = {
|
|
add: false,
|
|
edit: false,
|
|
del: false,
|
|
download: false
|
|
}
|
|
},
|
|
methods: {
|
|
handleSystemFlagChange() {
|
|
this.query.bizCode = undefined
|
|
this.bizCodeList = []
|
|
if (this.query.systemFlag) {
|
|
apiLog.getBizCodeList(this.query.systemFlag, this.query.direction).then(res => {
|
|
this.bizCodeList = res
|
|
})
|
|
}
|
|
this.crud.toQuery()
|
|
},
|
|
showDetail(row) {
|
|
this.currentRow = row
|
|
this.drawerVisible = true
|
|
},
|
|
handleCloseDrawer() {
|
|
this.drawerVisible = false
|
|
this.currentRow = {}
|
|
},
|
|
formatJson(json) {
|
|
if (!json) return ''
|
|
try {
|
|
return JSON.stringify(JSON.parse(json), null, 2)
|
|
} catch (e) {
|
|
return json
|
|
}
|
|
},
|
|
handleArchive() {
|
|
this.$confirm('确认将历史接口日志数据进行归档备份吗?此操作可能需要较长时间。', '提示', {
|
|
confirmButtonText: '确定',
|
|
cancelButtonText: '取消',
|
|
type: 'warning'
|
|
}).then(() => {
|
|
this.archiveLoading = true
|
|
apiLog.archiveLogs().then(() => {
|
|
this.archiveLoading = false
|
|
this.$notify({
|
|
title: '归档成功',
|
|
message: '历史日志数据已成功归档备份',
|
|
type: 'success',
|
|
duration: 3000
|
|
})
|
|
this.crud.toQuery()
|
|
}).catch(err => {
|
|
this.archiveLoading = false
|
|
this.$notify({
|
|
title: '归档失败',
|
|
message: err.message || '归档操作失败,请稍后重试',
|
|
type: 'error',
|
|
duration: 3000
|
|
})
|
|
})
|
|
}).catch(() => {
|
|
})
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
|
|
.demo-table-expand label {
|
|
width: 90px;
|
|
color: #99a9bf;
|
|
}
|
|
|
|
.demo-table-expand .el-form-item {
|
|
margin-right: 0;
|
|
margin-bottom: 0;
|
|
width: 100%;
|
|
}
|
|
|
|
.demo-table-expand .el-form-item__content {
|
|
font-size: 12px;
|
|
}
|
|
|
|
.drawer-content {
|
|
padding: 0 20px 20px;
|
|
}
|
|
|
|
.json-content {
|
|
background-color: #f5f7fa;
|
|
padding: 15px;
|
|
border-radius: 4px;
|
|
max-height: 400px;
|
|
overflow: auto;
|
|
font-size: 12px;
|
|
line-height: 1.5;
|
|
margin: 10px 0;
|
|
}
|
|
|
|
::v-deep .el-drawer__header {
|
|
margin-bottom: 10px;
|
|
padding: 15px 20px;
|
|
border-bottom: 1px solid #e8e8e8;
|
|
}
|
|
|
|
::v-deep .el-drawer__body {
|
|
padding: 0;
|
|
}
|
|
.biz-code-item {
|
|
min-width: 350px;
|
|
}
|
|
|
|
.biz-code-item .el-select {
|
|
width: 100%;
|
|
}
|
|
::v-deep .el-drawer__body {
|
|
padding: 0;
|
|
}
|
|
.biz-code-item {
|
|
min-width: 350px;
|
|
}
|
|
|
|
.biz-code-item .el-select {
|
|
width: 100%;
|
|
}
|
|
|
|
</style>
|
|
<style>
|
|
.el-tooltip__popper {
|
|
max-width: 800px !important;
|
|
word-wrap: break-word !important;
|
|
word-break: break-all !important;
|
|
white-space: normal !important;
|
|
}
|
|
</style>
|