|
@@ -1,5 +1,5 @@
|
|
|
<script setup lang="ts">
|
|
|
-import { computed, ref, watch } from 'vue';
|
|
|
+import { computed, onUnmounted, ref, watch } from 'vue';
|
|
|
import { useRouter } from 'vue-router';
|
|
|
import { Modal } from 'ant-design-vue';
|
|
|
|
|
@@ -8,7 +8,7 @@ import { useRequest } from '@/hooks/request';
|
|
|
import { useViewVisible } from '@/hooks/view-visible';
|
|
|
import { t } from '@/i18n';
|
|
|
import { getGroupModuleDevData, updateGroupModuleDevData } from '@/api';
|
|
|
-import { waitTime } from '@/utils';
|
|
|
+import { isNotEmptyVal } from '@/utils';
|
|
|
import { DevParamChillerUnit, DevParamCoolingPump, DevParamCoolingTower } from '@/constants/device-params';
|
|
|
|
|
|
import { DeviceType } from '../device-work-status/device-card';
|
|
@@ -28,6 +28,7 @@ defineEmits<{
|
|
|
const { visible, showView, hideView } = useViewVisible();
|
|
|
const { isLoading, handleRequest } = useRequest();
|
|
|
const deviceRealTimeData = ref<Record<string, number | string | undefined>>({});
|
|
|
+let deviceRTDTimer: number | undefined;
|
|
|
|
|
|
const deviceType = computed(() => {
|
|
|
return props.info?.deviceQueryVo.deviceType;
|
|
@@ -78,10 +79,18 @@ watch(visible, () => {
|
|
|
getDeviceData();
|
|
|
} else {
|
|
|
deviceRealTimeData.value = {};
|
|
|
+ clearTimeout(deviceRTDTimer);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+onUnmounted(() => {
|
|
|
+ deviceRealTimeData.value = {};
|
|
|
+ clearTimeout(deviceRTDTimer);
|
|
|
+});
|
|
|
+
|
|
|
const getDeviceData = () => {
|
|
|
+ clearTimeout(deviceRTDTimer);
|
|
|
+
|
|
|
handleRequest(async () => {
|
|
|
if (!props.info?.deviceQueryVo) {
|
|
|
return;
|
|
@@ -94,6 +103,8 @@ const getDeviceData = () => {
|
|
|
deviceRealTimeData.value[item.dataCode] = item.value;
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+ deviceRTDTimer = window.setTimeout(getDeviceData, 3000);
|
|
|
};
|
|
|
|
|
|
const updateDeviceData = (paramCode: string, value?: string | number | null) => {
|
|
@@ -104,16 +115,8 @@ const updateDeviceData = (paramCode: string, value?: string | number | null) =>
|
|
|
|
|
|
const { id } = props.info.deviceQueryVo;
|
|
|
|
|
|
- try {
|
|
|
- if (value !== undefined && value !== null) {
|
|
|
- await updateGroupModuleDevData(id, paramCode, value);
|
|
|
- }
|
|
|
- // eslint-disable-next-line no-useless-catch
|
|
|
- } catch (err) {
|
|
|
- throw err;
|
|
|
- } finally {
|
|
|
- await waitTime();
|
|
|
- getDeviceData();
|
|
|
+ if (isNotEmptyVal(value)) {
|
|
|
+ await updateGroupModuleDevData(id, paramCode, value);
|
|
|
}
|
|
|
});
|
|
|
};
|