diff --git a/src/views/warn/alarm/alarm.data.ts b/src/views/warn/alarm/alarm.data.ts index 8b2cae7..5d5fc3d 100644 --- a/src/views/warn/alarm/alarm.data.ts +++ b/src/views/warn/alarm/alarm.data.ts @@ -4,6 +4,13 @@ import {h, ref} from "vue"; import {systemSelectParams} from "@/api/alert/model/model/optionsModel"; import {formatToDateTime, getDate} from "@/utils/dateUtil"; + +export const currentTime = ref(Date.now()) + +setInterval(() => { + currentTime.value = Date.now() +}, 1000) + function toTimestamp(time: string): number { if (!time) return 0 // 兼容:2026-01-04T09:30:15 / 2026-01-04 09:30:15 @@ -183,8 +190,7 @@ export const columns: BasicColumn[] = [ return h('div', [ h('div', record.insertTime), // h('div', '--'), - h('div', formatToDateTime(record.currentTime)) - + h('div', formatToDateTime(currentTime.value)) ]); }, @@ -192,9 +198,10 @@ export const columns: BasicColumn[] = [ { title: '持续时长', dataIndex: 'timeDiffStr', - width: 85, + width: 100, customRender: ({ record }) => { - const diffMs = record.currentTime - toTimestamp(record.insertTime) + if (!record.insertTime) return '-' + const diffMs = currentTime.value - toTimestamp(record.insertTime) return getDate(diffMs) }, }, diff --git a/src/views/warn/alarm/index.vue b/src/views/warn/alarm/index.vue index f97eaa3..5cbb907 100644 --- a/src/views/warn/alarm/index.vue +++ b/src/views/warn/alarm/index.vue @@ -80,7 +80,10 @@ async function handleTrend(record: Recordable) { let timer: number | null = null onMounted(() => { + console.log("定时器开始") + timer = window.setInterval(async() => { + const list = getDataSource() const now = Date.now() @@ -93,26 +96,16 @@ onMounted(() => { const outpointCode = row.outputPoint; const outpointValue = await getExaNow(outpointCode); // 更新当前行 - updateTableDataRecord(row.mpId, Object.assign(row, { pointValue: pointValue, outpointValue: outpointValue })) + updateTableDataRecord(row.mpId, Object.assign(row, { pointValue: pointValue, outpointValue: outpointValue})) } - - // 只更新字段,不请求接口 - setTableData( - list.map(item => ({ - ...item, - currentTime: now, - })) - ) }, 1000) }) onUnmounted(() => { + console.log("定时器销毁",timer) if (timer) clearInterval(timer) }) - - -