feat: 添加活动告警自动刷新功能并优化代码结构
This commit is contained in:
@@ -217,6 +217,7 @@ onMounted(() => {
|
|||||||
let serverTimeInterval: any = null;
|
let serverTimeInterval: any = null;
|
||||||
let serverTime = 0;
|
let serverTime = 0;
|
||||||
let serverTimeZone = getTimezoneOffset();
|
let serverTimeZone = getTimezoneOffset();
|
||||||
|
let activeAlarmRefresh = 0;
|
||||||
|
|
||||||
// 获取服务器时间
|
// 获取服务器时间
|
||||||
function fnGetServerTime() {
|
function fnGetServerTime() {
|
||||||
@@ -230,6 +231,7 @@ function fnGetServerTime() {
|
|||||||
const serverTimeDom = document.getElementById('serverTimeDom');
|
const serverTimeDom = document.getElementById('serverTimeDom');
|
||||||
serverTimeInterval = setInterval(() => {
|
serverTimeInterval = setInterval(() => {
|
||||||
serverTime += 1000;
|
serverTime += 1000;
|
||||||
|
activeAlarmRefresh += 1;
|
||||||
if (serverTimeDom) {
|
if (serverTimeDom) {
|
||||||
serverTimeDom.innerText = parseDateUTCToStr(
|
serverTimeDom.innerText = parseDateUTCToStr(
|
||||||
serverTime,
|
serverTime,
|
||||||
@@ -239,6 +241,10 @@ function fnGetServerTime() {
|
|||||||
clearInterval(serverTimeInterval);
|
clearInterval(serverTimeInterval);
|
||||||
serverTimeInterval = null;
|
serverTimeInterval = null;
|
||||||
}
|
}
|
||||||
|
if (activeAlarmRefresh === 5) {
|
||||||
|
useAlarmStore().fnGetActiveAlarmInfo();
|
||||||
|
activeAlarmRefresh = 0;
|
||||||
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { reactive, ref, onMounted, toRaw } from 'vue';
|
import { reactive, ref, onMounted, toRaw, onBeforeUnmount } from 'vue';
|
||||||
import { PageContainer } from 'antdv-pro-layout';
|
import { PageContainer } from 'antdv-pro-layout';
|
||||||
import { ProModal } from 'antdv-pro-modal';
|
import { ProModal } from 'antdv-pro-modal';
|
||||||
import { message, Modal } from 'ant-design-vue/es';
|
import { message, Modal } from 'ant-design-vue/es';
|
||||||
@@ -560,22 +560,24 @@ function fnCancelConfirm() {
|
|||||||
*/
|
*/
|
||||||
function fnSync() {
|
function fnSync() {
|
||||||
const hide = message.loading(t('common.loading'), 0);
|
const hide = message.loading(t('common.loading'), 0);
|
||||||
listSync().then(res => {
|
listSync()
|
||||||
if (res.code === RESULT_CODE_SUCCESS) {
|
.then(res => {
|
||||||
message.success({
|
if (res.code === RESULT_CODE_SUCCESS) {
|
||||||
content: t('views.faultManage.activeAlarm.sysncSuss'),
|
message.success({
|
||||||
duration: 2,
|
content: t('views.faultManage.activeAlarm.sysncSuss'),
|
||||||
});
|
duration: 2,
|
||||||
fnGetList();
|
});
|
||||||
} else {
|
fnGetList();
|
||||||
message.error({
|
} else {
|
||||||
content: `${res.msg}`,
|
message.error({
|
||||||
duration: 2,
|
content: `${res.msg}`,
|
||||||
});
|
duration: 2,
|
||||||
}
|
});
|
||||||
}).finally(()=>{
|
}
|
||||||
hide();
|
})
|
||||||
});
|
.finally(() => {
|
||||||
|
hide();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -821,6 +823,24 @@ function fnGetList(pageNum?: number) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let interval: any = null;
|
||||||
|
/**自动刷新 */
|
||||||
|
function AutoRefresh() {
|
||||||
|
interval = setInterval(() => {
|
||||||
|
listAct(toRaw(queryParams)).then((res: any) => {
|
||||||
|
if (res.code === RESULT_CODE_SUCCESS) {
|
||||||
|
const { total, rows } = res.data;
|
||||||
|
tablePagination.total = total;
|
||||||
|
tableState.data = rows;
|
||||||
|
} else {
|
||||||
|
tablePagination.total = 0;
|
||||||
|
tableState.data = [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 5_000);
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// 初始字典数据
|
// 初始字典数据
|
||||||
Promise.allSettled([
|
Promise.allSettled([
|
||||||
@@ -844,7 +864,12 @@ onMounted(() => {
|
|||||||
});
|
});
|
||||||
// 获取列表
|
// 获取列表
|
||||||
fnGetList();
|
fnGetList();
|
||||||
|
// 自动刷新
|
||||||
|
AutoRefresh();
|
||||||
});
|
});
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
clearInterval(interval);
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -957,7 +982,11 @@ onMounted(() => {
|
|||||||
{{ t('views.faultManage.activeAlarm.updateConfirm') }}
|
{{ t('views.faultManage.activeAlarm.updateConfirm') }}
|
||||||
</a-button>
|
</a-button>
|
||||||
|
|
||||||
<a-button type="primary" @click.prevent="fnSync()" v-perms:has="['faultManage:active-alarm:async']">
|
<a-button
|
||||||
|
type="primary"
|
||||||
|
@click.prevent="fnSync()"
|
||||||
|
v-perms:has="['faultManage:active-alarm:async']"
|
||||||
|
>
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<ReloadOutlined />
|
<ReloadOutlined />
|
||||||
</template>
|
</template>
|
||||||
@@ -982,7 +1011,11 @@ onMounted(() => {
|
|||||||
{{ t('views.faultManage.activeAlarm.clear') }}
|
{{ t('views.faultManage.activeAlarm.clear') }}
|
||||||
</a-button>
|
</a-button>
|
||||||
|
|
||||||
<a-button type="dashed" @click.prevent="fnExportList()" v-perms:has="['faultManage:active-alarm:export']">
|
<a-button
|
||||||
|
type="dashed"
|
||||||
|
@click.prevent="fnExportList()"
|
||||||
|
v-perms:has="['faultManage:active-alarm:export']"
|
||||||
|
>
|
||||||
<template #icon><ExportOutlined /></template>
|
<template #icon><ExportOutlined /></template>
|
||||||
{{ t('common.export') }}
|
{{ t('common.export') }}
|
||||||
</a-button>
|
</a-button>
|
||||||
|
|||||||
Reference in New Issue
Block a user