e9d1f0ecc99c5c7bb8cff434596cd2c0dd9d7180.svn-base 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <a-skeleton active :loading="loading" :paragraph="{rows: 17}">
  3. <a-card :bordered="false" class="card-area">
  4. <a-alert type="info" :showIcon="true">
  5. <div slot="message">
  6. 共追踪到 {{ dataSource.length }} 条近期HTTP请求记录
  7. <a-divider type="vertical"/>
  8. <a @click="handleClickUpdate">立即刷新</a>
  9. </div>
  10. </a-alert>
  11. <!-- 表格区域 -->
  12. <a-table
  13. :columns="columns"
  14. :dataSource="dataSource"
  15. :pagination="pagination"
  16. :loading="tableLoading"
  17. :scroll="{ x: 900 }"
  18. style="margin-top: 20px;"
  19. @change="handleTableChange">
  20. <template slot="timeTaken" slot-scope="text">
  21. <a-tag v-if="text < 500" color="green">{{ text }} ms</a-tag>
  22. <a-tag v-else-if="text < 1000" color="cyan">{{ text }} ms</a-tag>
  23. <a-tag v-else-if="text < 1500" color="orange">{{ text }} ms</a-tag>
  24. <a-tag v-else color="red">{{ text }} ms</a-tag>
  25. </template>
  26. <template slot="responseStatus" slot-scope="text">
  27. <a-tag v-if="text < 200" color="pink">{{ text }} </a-tag>
  28. <a-tag v-else-if="text < 201" color="green">{{ text }} </a-tag>
  29. <a-tag v-else-if="text < 399" color="cyan">{{ text }} </a-tag>
  30. <a-tag v-else-if="text < 403" color="orange">{{ text }} </a-tag>
  31. <a-tag v-else-if="text < 501" color="red">{{ text }} </a-tag>
  32. <span v-else>{{ text }}</span>
  33. </template>
  34. <template slot="requestMethod" slot-scope="text">
  35. <a-tag v-if="text === 'GET'" color="#87d068">{{ text }}</a-tag>
  36. <a-tag v-else-if="text === 'POST'" color="#2db7f5">{{ text }}</a-tag>
  37. <a-tag v-else-if="text === 'PUT'" color="#ffba5a">{{ text }}</a-tag>
  38. <a-tag v-else-if="text === 'DELETE'" color="#f50">{{ text }}</a-tag>
  39. <span v-else>{{ text }} ms</span>
  40. </template>
  41. </a-table>
  42. </a-card>
  43. </a-skeleton>
  44. </template>
  45. <script>
  46. import moment from 'moment'
  47. import { getAction } from '@/api/manage'
  48. moment.locale('zh-cn')
  49. export default {
  50. data() {
  51. return {
  52. advanced: false,
  53. dataSource: [],
  54. pagination: {
  55. defaultPageSize: 10,
  56. defaultCurrent: 1,
  57. pageSizeOptions: ['10', '20', '30', '40', '100'],
  58. showQuickJumper: true,
  59. showSizeChanger: true,
  60. showTotal: (total, range) => `显示 ${range[0]} ~ ${range[1]} 条记录,共 ${total} 条记录`
  61. },
  62. loading: true,
  63. tableLoading: true
  64. }
  65. },
  66. computed: {
  67. columns() {
  68. return [{
  69. title: '请求时间',
  70. dataIndex: 'timestamp',
  71. customRender(text) {
  72. return moment(text).format('YYYY-MM-DD HH:mm:ss')
  73. }
  74. }, {
  75. title: '请求方法',
  76. dataIndex: 'request.method',
  77. scopedSlots: { customRender: 'requestMethod' },
  78. filters: [
  79. { text: 'GET', value: 'GET' },
  80. { text: 'POST', value: 'POST' },
  81. { text: 'PUT', value: 'PUT' },
  82. { text: 'DELETE', value: 'DELETE' }
  83. ],
  84. filterMultiple: true,
  85. onFilter: (value, record) => record.request.method.includes(value)
  86. }, {
  87. title: '请求URL',
  88. dataIndex: 'request.uri',
  89. customRender(text) {
  90. return text.split('?')[0]
  91. }
  92. }, {
  93. title: '响应状态',
  94. dataIndex: 'response.status',
  95. scopedSlots: { customRender: 'responseStatus' }
  96. }, {
  97. title: '请求耗时',
  98. dataIndex: 'timeTaken',
  99. scopedSlots: { customRender: 'timeTaken' }
  100. }]
  101. }
  102. },
  103. mounted() {
  104. this.fetch()
  105. },
  106. methods: {
  107. handleClickUpdate() {
  108. this.fetch()
  109. },
  110. handleTableChange() {
  111. this.fetch()
  112. },
  113. fetch() {
  114. this.tableLoading = true
  115. getAction('actuator/httptrace').then((data) => {
  116. let filterData = []
  117. for (let d of data.traces) {
  118. if (d.request.method !== 'OPTIONS' && d.request.uri.indexOf('httptrace') === -1) {
  119. filterData.push(d)
  120. }
  121. }
  122. this.dataSource = filterData
  123. }).catch((e) => {
  124. console.error(e)
  125. this.$message.error('获取HTTP信息失败')
  126. }).finally(() => {
  127. this.loading = false
  128. this.tableLoading = false
  129. })
  130. }
  131. }
  132. }
  133. </script>
  134. <style></style>