Browse Source

Merge pull request 'fix:集中告警列表字段时间处理' (#114) from dev-xjf into master

Reviewed-on: http://120.26.116.243:3000/root/alert-front/pulls/114
master
xiaojinfei 1 week ago
parent
commit
1731b6104a
  1. 7
      src/utils/dateUtil.ts
  2. 26
      src/views/warn/alarm/alarm.data.ts
  3. 48
      src/views/warn/alarm/index.vue

7
src/utils/dateUtil.ts

@ -114,14 +114,15 @@ export function getDate(ms) {
const hour = Math.floor(ms / (60 * 60 * 1000) - day * 24) const hour = Math.floor(ms / (60 * 60 * 1000) - day * 24)
const minute = Math.floor(ms / (60 * 1000) - day * 24 * 60 - hour * 60) const minute = Math.floor(ms / (60 * 1000) - day * 24 * 60 - hour * 60)
const second = Math.floor(ms / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - minute * 60) const second = Math.floor(ms / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - minute * 60)
console.log(day, hour, minute, second)
if (day > 0) if (day > 0)
return `${day}${hour}小时${minute}分钟` return `${day}${hour}小时${minute}分钟${second}`
if (hour > 0) if (hour > 0)
return `${hour}小时${minute}分钟` return `${hour}小时${minute}分钟${second}`
if (minute > 0) if (minute > 0)
return `${minute}分钟` return `${minute}分钟${second}`
if (second > 0) if (second > 0)
return `${second}` return `${second}`

26
src/views/warn/alarm/alarm.data.ts

@ -2,9 +2,13 @@ import type { BasicColumn, FormSchema } from '@/components/Table'
import {optionListApi, subSystemListApi} from "@/api/alert/model/select"; import {optionListApi, subSystemListApi} from "@/api/alert/model/select";
import {h, ref} from "vue"; import {h, ref} from "vue";
import {systemSelectParams} from "@/api/alert/model/model/optionsModel"; import {systemSelectParams} from "@/api/alert/model/model/optionsModel";
import {FileItem, UploadResultStatus} from "@/components/Upload/src/typing"; import {formatToDateTime, getDate} from "@/utils/dateUtil";
import {Progress} from "ant-design-vue";
import moment from "moment/moment"; function toTimestamp(time: string): number {
if (!time) return 0
// 兼容:2026-01-04T09:30:15 / 2026-01-04 09:30:15
return new Date(time.replace('T', ' ')).getTime()
}
const optionList = await optionListApi() const optionList = await optionListApi()
const systemOptions = ref<any>([]) const systemOptions = ref<any>([])
@ -117,7 +121,7 @@ export const columns: BasicColumn[] = [
{ {
title: '报警名称', title: '报警名称',
dataIndex: 'alarmName', dataIndex: 'alarmName',
width: 180, width: 200,
fixed: 'left', fixed: 'left',
// 将 JSX 改为 h 函数调用 // 将 JSX 改为 h 函数调用
customRender: ({ record }) => { customRender: ({ record }) => {
@ -172,13 +176,15 @@ export const columns: BasicColumn[] = [
}, },
{ {
title: '预警时间', title: '预警时间',
dataIndex: 'createTime', dataIndex: 'insertTime',
width: 200, width: 200,
// 将 JSX 改为 h 函数调用 // 将 JSX 改为 h 函数调用
customRender: ({ record }) => { customRender: ({ record }) => {
return h('div', [ return h('div', [
h('div', record.createTime), h('div', record.insertTime),
h('div', '--'), // h('div', '--'),
h('div', formatToDateTime(record.currentTime))
]); ]);
}, },
@ -187,8 +193,10 @@ export const columns: BasicColumn[] = [
title: '持续时长', title: '持续时长',
dataIndex: 'timeDiffStr', dataIndex: 'timeDiffStr',
width: 90, width: 90,
ellipsis: false, // ⭐ 关键 customRender: ({ record }) => {
const diffMs = record.currentTime - toTimestamp(record.insertTime)
return getDate(diffMs)
},
}, },
{ {
title: '告警级别', title: '告警级别',

48
src/views/warn/alarm/index.vue

@ -1,6 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import { Switch } from 'ant-design-vue' import { Switch } from 'ant-design-vue'
import {nextTick, onMounted, ref} from 'vue' import {nextTick, onUnmounted, onMounted, ref} from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import { columns } from './alarm.data' import { columns } from './alarm.data'
@ -15,6 +15,7 @@ import { useMessage } from '@/hooks/web/useMessage'
import { IconEnum } from '@/enums/appEnum' import { IconEnum } from '@/enums/appEnum'
import { useModal } from '@/components/Modal' import { useModal } from '@/components/Modal'
import {router} from "@/router"; import {router} from "@/router";
import {getExaNow} from "@/api/alert/exa";
defineOptions({ name: 'Warn' }) defineOptions({ name: 'Warn' })
@ -25,12 +26,13 @@ const { t } = useI18n()
const [registerUpdateModal, { openModal: openUpdateModal }] = useModal() const [registerUpdateModal, { openModal: openUpdateModal }] = useModal()
const [registerTrendModal, { openModal: openTrendModal }] = useModal() const [registerTrendModal, { openModal: openTrendModal }] = useModal()
const searchSchema = ref<FormSchema[]>(getSearchFormSchema(false)) // const searchSchema = ref<FormSchema[]>(getSearchFormSchema(false)) //
const [registerTable, { getForm,reload, getDataSource }] = useTable({ const [registerTable, { getForm,reload, getDataSource,setTableData,updateTableDataRecord }] = useTable({
title: '集中告警列表', title: '集中告警列表',
api: getWarnPageReal, api: getWarnPageReal,
rowKey: 'warnId', rowKey: 'warnId',
immediate: true, immediate: true,
columns, columns,
//, //,
useSearchForm: true, useSearchForm: true,
formConfig: { formConfig: {
@ -73,14 +75,44 @@ async function handleTrend(record: Recordable) {
openTrendModal(true, { record }) openTrendModal(true, { record })
} }
onMounted(async () => {
// await nextTick();
// //algorithmId
// updateSchema([
// { field: 'algorithmId', show: false },
// ]);
let timer: number | null = null
onMounted(() => {
timer = window.setInterval(async() => {
const list = getDataSource()
const now = Date.now()
// data
for (const row of list) {
//
const pointCode = row.pointId
//
const pointValue = await getExaNow(pointCode);
const outpointCode = row.outputPoint;
const outpointValue = await getExaNow(outpointCode);
//
updateTableDataRecord(row.mpId, Object.assign(row, { pointValue: pointValue, outpointValue: outpointValue }))
}
//
setTableData(
list.map(item => ({
...item,
currentTime: now,
}))
)
}, 1000)
}) })
onUnmounted(() => {
if (timer) clearInterval(timer)
})
</script> </script>
<template> <template>

Loading…
Cancel
Save