historyAlarm.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div class="absolute top-10px right-15px">
  3. <n-button class="bg-#389bff94" size="small" @click="historyAlarm">历史告警</n-button>
  4. </div>
  5. <n-modal
  6. v-model:show="showModal"
  7. class="custom-card"
  8. preset="card"
  9. title="告警记录"
  10. size="huge"
  11. :style="{
  12. marginTop: '10%',
  13. width: '50%'
  14. }"
  15. :bordered="false"
  16. >
  17. <n-data-table :columns="columns" :data="data" max-height="500px" bordered />
  18. <div class="flex justify-end mt-2">
  19. <n-pagination
  20. v-model:page="pagination.page"
  21. :page-sizes="pagination.pageSizes"
  22. :page-count="pagination.pageSize"
  23. :on-update:page="pagination.onChange"
  24. :on-update:page-size="pagination.onUpdatePageSize"
  25. show-quick-jumper
  26. show-size-picker
  27. />
  28. </div>
  29. </n-modal>
  30. </template>
  31. <script setup>
  32. import { NButton, NModal, NDataTable, NPagination, useModal } from 'naive-ui'
  33. import { Events } from '@/utils/enum'
  34. import dayjs from 'dayjs'
  35. import { h } from 'vue'
  36. const modal = useModal()
  37. const { API_ALARM_HISTORY_GET } = useRequest()
  38. const showModal = ref(false)
  39. function createColumns({ handleSubmit }) {
  40. return [
  41. {
  42. title: '事件名称',
  43. key: 'eventTypeId',
  44. render(row) {
  45. return h('span', Events[row.eventTypeId])
  46. }
  47. },
  48. {
  49. title: '事件时间',
  50. key: 'haveTime',
  51. render(row) {
  52. return dayjs(parseInt(`${row.haveTime}`.padEnd(13, '0'))).format('YYYY-MM-DD HH:mm:ss')
  53. }
  54. },
  55. {
  56. title: '核验结果',
  57. key: 'handled',
  58. render(row) {
  59. const t = { 0: '未处理', 1: '已处理', 2: '误报' }
  60. return h('span', t[row.handled])
  61. }
  62. },
  63. {
  64. title: '可信度',
  65. key: 'score'
  66. },
  67. {
  68. title: '操作',
  69. key: 'actions',
  70. render(row) {
  71. return h(
  72. NButton,
  73. {
  74. strong: true,
  75. tertiary: true,
  76. size: 'small',
  77. onClick: () => handleSubmit(row)
  78. },
  79. { default: () => '查看' }
  80. )
  81. }
  82. }
  83. ]
  84. }
  85. function historyAlarm() {
  86. showModal.value = true
  87. }
  88. const data = ref([])
  89. const columns = createColumns({
  90. handleSubmit(row) {
  91. modal.create({
  92. title: '事件详情',
  93. preset: 'card',
  94. style: {
  95. marginTop: '10%'
  96. },
  97. content: () =>
  98. h('div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } }, [
  99. h('span', {}, `事件名称:${Events[row.eventTypeId] ? Events[row.eventTypeId] : ''}`),
  100. h(
  101. 'span',
  102. {},
  103. `事件时间:${dayjs(parseInt(`${row.haveTime}`.padEnd(13, '0'))).format('YYYY-MM-DD HH:mm:ss')}`
  104. ),
  105. h('span', { style: { 'white-space': 'pre-wrap' } }, `事件描述:${row.handledDetail}`)
  106. ])
  107. })
  108. }
  109. })
  110. const pagination = reactive({
  111. page: 1,
  112. pageSize: 10,
  113. showSizePicker: true,
  114. pageSizes: [10, 50, 100],
  115. onChange: (page) => {
  116. pagination.page = page
  117. init()
  118. },
  119. onUpdatePageSize: (pageSize) => {
  120. pagination.pageSize = pageSize
  121. pagination.page = 1
  122. console.log(123)
  123. init()
  124. }
  125. })
  126. const init = async () => {
  127. const res = await API_ALARM_HISTORY_GET({
  128. page: pagination.page,
  129. page_size: pagination.pageSize
  130. })
  131. data.value = res?.items || []
  132. pagination.total = res?.total
  133. pagination.page = res?.page
  134. pagination.pageSize = res?.pageSize
  135. console.log(res)
  136. }
  137. onMounted(() => {
  138. init()
  139. })
  140. </script>