| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <template>
- <div class="absolute top-10px right-15px">
- <n-button class="bg-#389bff94" size="small" @click="historyAlarm">历史告警</n-button>
- </div>
- <n-modal
- v-model:show="showModal"
- class="custom-card"
- preset="card"
- title="告警记录"
- size="huge"
- :style="{
- marginTop: '10%',
- width: '50%'
- }"
- :bordered="false"
- >
- <n-data-table :columns="columns" :data="data" max-height="500px" bordered />
- <div class="flex justify-end mt-2">
- <n-pagination
- v-model:page="pagination.page"
- :page-sizes="pagination.pageSizes"
- :page-count="pagination.pageSize"
- :on-update:page="pagination.onChange"
- :on-update:page-size="pagination.onUpdatePageSize"
- show-quick-jumper
- show-size-picker
- />
- </div>
- </n-modal>
- </template>
- <script setup>
- import { NButton, NModal, NDataTable, NPagination, useModal } from 'naive-ui'
- import { Events } from '@/utils/enum'
- import dayjs from 'dayjs'
- import { h } from 'vue'
- const modal = useModal()
- const { API_ALARM_HISTORY_GET } = useRequest()
- const showModal = ref(false)
- function createColumns({ handleSubmit }) {
- return [
- {
- title: '事件名称',
- key: 'eventTypeId',
- render(row) {
- return h('span', Events[row.eventTypeId])
- }
- },
- {
- title: '事件时间',
- key: 'haveTime',
- render(row) {
- return dayjs(parseInt(`${row.haveTime}`.padEnd(13, '0'))).format('YYYY-MM-DD HH:mm:ss')
- }
- },
- {
- title: '核验结果',
- key: 'handled',
- render(row) {
- const t = { 0: '未处理', 1: '已处理', 2: '误报' }
- return h('span', t[row.handled])
- }
- },
- {
- title: '可信度',
- key: 'score'
- },
- {
- title: '操作',
- key: 'actions',
- render(row) {
- return h(
- NButton,
- {
- strong: true,
- tertiary: true,
- size: 'small',
- onClick: () => handleSubmit(row)
- },
- { default: () => '查看' }
- )
- }
- }
- ]
- }
- function historyAlarm() {
- showModal.value = true
- }
- const data = ref([])
- const columns = createColumns({
- handleSubmit(row) {
- modal.create({
- title: '事件详情',
- preset: 'card',
- style: {
- marginTop: '10%'
- },
- content: () =>
- h('div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } }, [
- h('span', {}, `事件名称:${Events[row.eventTypeId] ? Events[row.eventTypeId] : ''}`),
- h(
- 'span',
- {},
- `事件时间:${dayjs(parseInt(`${row.haveTime}`.padEnd(13, '0'))).format('YYYY-MM-DD HH:mm:ss')}`
- ),
- h('span', { style: { 'white-space': 'pre-wrap' } }, `事件描述:${row.handledDetail}`)
- ])
- })
- }
- })
- const pagination = reactive({
- page: 1,
- pageSize: 10,
- showSizePicker: true,
- pageSizes: [10, 50, 100],
- onChange: (page) => {
- pagination.page = page
- init()
- },
- onUpdatePageSize: (pageSize) => {
- pagination.pageSize = pageSize
- pagination.page = 1
- console.log(123)
- init()
- }
- })
- const init = async () => {
- const res = await API_ALARM_HISTORY_GET({
- page: pagination.page,
- page_size: pagination.pageSize
- })
- data.value = res?.items || []
- pagination.total = res?.total
- pagination.page = res?.page
- pagination.pageSize = res?.pageSize
- console.log(res)
- }
- onMounted(() => {
- init()
- })
- </script>
|