msgTrack.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <a-card >
  3. <div class="subtitle" > 消息跟踪可记录设备在运行过程中的各类操作信息,状态和结果。当数据上报、响应命令等业务场景中出现故障时,消息跟踪功能可帮助您快速进行故障定位和原因分析</div>
  4. <div class="subtitle" >为避免占用读写计算、存储资源,同时保证数据有效,平台限制最长可跟踪3天的数据,且单个用户下,仅支持同时启动10个设备的消息跟踪。</div>
  5. <AlertTsx style="margin-top: 20px;" >
  6. <template #valueSlot>
  7. <div v-if="state.dataSource.length && state.trackStart" >
  8. 结束时间: {{state.formatStartTime}}
  9. </div>
  10. <div v-else-if="state.trackStart" >
  11. 开始追踪:当前暂无消息记录
  12. </div>
  13. <div v-else >
  14. 尚未追踪
  15. </div>
  16. </template>
  17. <template #operaSlot>
  18. <a-space>
  19. <a-button type="link" @click="clearDataSource">清除数据</a-button>
  20. </a-space>
  21. </template>
  22. </AlertTsx>
  23. <a-row style="margin: 20px 0px;" justify="space-between" >
  24. <a-col>
  25. <a-space>
  26. </a-space>
  27. </a-col>
  28. <a-col>
  29. <a-space>
  30. <a-button type="primary" @click="addEventTrace" >新增事件跟踪</a-button>
  31. </a-space>
  32. </a-col>
  33. </a-row>
  34. <a-table
  35. :columns="columns"
  36. :loading="state.loading"
  37. :dataSource="state.dataSource"
  38. :pagination="false"
  39. style="height: 400px;overflow: hidden;overflow-y: auto;"
  40. >
  41. <template #bodyCell="{column, record}">
  42. <template v-if="column.key === 'eventType'" >
  43. {{EventController.eventTypeMap.get(record.eventType)?.name}}
  44. </template>
  45. <template v-if="column.key === 'eventPayload'" >
  46. <a-tooltip placement="topLeft" >
  47. <template #title> {{record.eventPayload}}</template>
  48. {{record.eventPayload}}
  49. </a-tooltip>
  50. </template>
  51. <template v-else-if="column.key === 'eventTs'" >
  52. {{ dayjs(record.eventTs).format('YYYY-MM-DD hh:mm:ss') }}
  53. </template>
  54. </template>
  55. </a-table>
  56. </a-card>
  57. </template>
  58. <script lang="ts" setup >
  59. import { AlertTsx } from '@/components/MicroComponents/index'
  60. import { EventController } from '@/controller'
  61. import { onMounted, reactive } from 'vue'
  62. import { useRoute } from 'vue-router'
  63. import dayjs from 'dayjs'
  64. import { useScheduler } from '@/hooks'
  65. const route = useRoute()
  66. const deviceId = route.query.id as string
  67. const columns = [
  68. {
  69. title: '业务名称',
  70. dataIndex: 'eventName',
  71. width: 100
  72. },
  73. {
  74. title: '业务类型',
  75. dataIndex: 'eventType',
  76. key: 'eventType',
  77. width: 100
  78. },
  79. {
  80. title: '业务详情',
  81. dataIndex: 'eventPayload',
  82. key: 'eventPayload',
  83. width: 100,
  84. ellipsis: true
  85. },
  86. {
  87. title: '记录时间',
  88. dataIndex: 'eventTs',
  89. key: 'eventTs',
  90. width: 100
  91. }
  92. ]
  93. const eventTypeList = Array.from(EventController.eventTypeMap, ([key, value]) => ({ ...value, value: value.key }))
  94. const state = reactive({
  95. loading: false,
  96. dataSource: [],
  97. total: 0,
  98. trackStart: false,
  99. // startTime: new Date().getTime() - 2000,
  100. startTime: 0,
  101. lastId: '',
  102. formatStartTime: ''
  103. })
  104. const clearDataSource = () => {
  105. state.dataSource = []
  106. }
  107. const addEventTrace = async () => {
  108. await EventController.addTrace({ deviceId: deviceId })
  109. state.trackStart = true
  110. stop()
  111. getEventTraceList()
  112. }
  113. const getEventList = async () => {
  114. const { data } = await EventController.list({ deviceId: deviceId, startTime: state.startTime, lastId: state.lastId })
  115. console.log('getEventList:', data)
  116. state.dataSource = state.dataSource.concat(data)
  117. state.total = 0
  118. }
  119. const { start, stop } = useScheduler(getEventList, 2000)
  120. const getEventTraceList = async () => {
  121. const data = await EventController.listTrace({ deviceId: deviceId }) as unknown as Number
  122. state.formatStartTime = data ? dayjs(data).format('YYYY-MM-DD hh:mm:ss') : ''
  123. start()
  124. }
  125. onMounted(() => {
  126. getEventTraceList()
  127. })
  128. </script>
  129. <style lang="less" scoped >
  130. @import '~@/styles/theme.less';
  131. .subtitle {
  132. color: @sublabel-color;
  133. font-size: 14px;
  134. }
  135. </style>