HttpTrace.vue
4.16 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<template>
<a-card :bordered="false" class="card-area">
<div>
<div class="alert">
<a-alert type="success" :show-icon="true">
<div slot="message">
共追踪到 {{dataSource.length}} 条近期HTTP请求记录
<a style="margin-left: 24px" @click="search">点击刷新</a>
</div>
</a-alert>
</div>
<!-- 表格区域 -->
<a-table :columns="columns"
:dataSource="dataSource"
:pagination="pagination"
:loading="loading"
:scroll="{ x: 900 }"
@change="handleTableChange">
</a-table>
</div>
</a-card>
</template>
<script>
import moment from 'moment'
moment.locale('zh-cn')
import {getAction} from '@/api/manage'
export default {
data () {
return {
advanced: false,
dataSource: [],
pagination: {
defaultPageSize: 10,
defaultCurrent: 1,
pageSizeOptions: ['10', '20', '30', '40', '100'],
showQuickJumper: true,
showSizeChanger: true,
showTotal: (total, range) => `显示 ${range[0]} ~ ${range[1]} 条记录,共 ${total} 条记录`
},
loading: false
}
},
computed: {
columns () {
return [{
title: '请求时间',
dataIndex: 'timestamp',
customRender: (text, row, index) => {
return moment(text).format('YYYY-MM-DD HH:mm:ss')
}
}, {
title: '请求方法',
dataIndex: 'request.method',
customRender: (text, row, index) => {
switch (text) {
case 'GET':
return <a-tag color="#87d068">{text}</a-tag>
case 'POST':
return <a-tag color="#2db7f5">{text}</a-tag>
case 'PUT':
return <a-tag color="#ffba5a">{text}</a-tag>
case 'DELETE':
return <a-tag color="#f50">{text}</a-tag>
default:
return text
}
},
filters: [
{ text: 'GET', value: 'GET' },
{ text: 'POST', value: 'POST' },
{ text: 'PUT', value: 'PUT' },
{ text: 'DELETE', value: 'DELETE' }
],
filterMultiple: true,
onFilter: (value, record) => record.request.method.includes(value)
}, {
title: '请求URL',
dataIndex: 'request.uri',
customRender: (text, row, index) => {
return text.split('?')[0]
}
}, {
title: '响应状态',
dataIndex: 'response.status',
customRender: (text, row, index) => {
if (text < 200) {
return <a-tag color="pink">{text}</a-tag>
} else if (text < 201) {
return <a-tag color="green">{text}</a-tag>
} else if (text < 399) {
return <a-tag color="cyan">{text}</a-tag>
} else if (text < 403) {
return <a-tag color="orange">{text}</a-tag>
} else if (text < 501) {
return <a-tag color="red">{text}</a-tag>
} else {
return text
}
}
}, {
title: '请求耗时',
dataIndex: 'timeTaken',
customRender: (text, row, index) => {
if (text < 500) {
return <a-tag color="green">{text} ms</a-tag>
} else if (text < 1000) {
return <a-tag color="cyan">{text} ms</a-tag>
} else if (text < 1500) {
return <a-tag color="orange">{text} ms</a-tag>
} else {
return <a-tag color="red">{text} ms</a-tag>
}
}
}]
}
},
mounted () {
this.fetch()
},
methods: {
search () {
this.fetch()
},
handleTableChange (pagination, filters, sorter) {
this.fetch()
},
fetch () {
this.loading = true
getAction('actuator/httptrace').then((data) => {
this.loading = false
let filterData = []
for (let d of data.traces) {
if (d.request.method !== 'OPTIONS' && d.request.uri.indexOf('httptrace') === -1) {
filterData.push(d)
}
}
this.dataSource = filterData
})
}
}
}
</script>
<style lang="less" scoped>
.alert {
margin-bottom: .5rem;
}
</style>