|
|
@@ -49,8 +49,8 @@
|
|
|
}
|
|
|
"
|
|
|
>
|
|
|
- <DownOutlined v-if="expandedRowKeys.includes(record.id)" />
|
|
|
- <RightOutlined v-else />
|
|
|
+ <DownCircleTwoTone v-if="expandedRowKeys.includes(record.id)" />
|
|
|
+ <RightCircleTwoTone v-else />
|
|
|
</a-button>
|
|
|
</template>
|
|
|
|
|
|
@@ -94,7 +94,7 @@ import { AesEncryption } from '/@/utils/cipher';
|
|
|
import { loginCipher } from '/@/settings/encryptionSetting';
|
|
|
import { message, TreeProps } from 'ant-design-vue';
|
|
|
import { getDeviceTypeList, getDeviceListByType, getDevMonitorListById } from './device.api';
|
|
|
-import { DownOutlined, RightOutlined } from '@ant-design/icons-vue';
|
|
|
+import { RightCircleTwoTone, DownCircleTwoTone } from '@ant-design/icons-vue';
|
|
|
import { alignElement } from 'dom-align';
|
|
|
import { active } from 'sortablejs';
|
|
|
|
|
|
@@ -113,7 +113,6 @@ const isRefresh = ref(true);
|
|
|
const treeNodeTitle = ref(''); // 选中的树形标题
|
|
|
const deviceList = ref<any[]>([]); // 设备列表
|
|
|
const monitorList = ref<any[]>([]); // 监测数据列表
|
|
|
-let timer: null | NodeJS.Timeout = undefined;
|
|
|
// 当前展开的行key数组
|
|
|
const expandedRowKeys = ref([]);
|
|
|
|
|
|
@@ -207,23 +206,6 @@ const onSelect: TreeProps['onSelect'] = (keys, e) => {
|
|
|
if (deviceType.value != e.node.type) deviceType.value = e.node.type;
|
|
|
}
|
|
|
getDeviceList(deviceType.value);
|
|
|
- // clearTimeout(timer);
|
|
|
- // timer = undefined;
|
|
|
- // if (startMonitorTimer) {
|
|
|
- // clearTimeout(startMonitorTimer);
|
|
|
- // }
|
|
|
- // dataSource.value = [];
|
|
|
- // // monitorTable.value.resetPagination();
|
|
|
- // if (!startMonitorTimer) {
|
|
|
- // startMonitorTimer = setTimeout(() => {
|
|
|
- // expandedKeys.value = keys;
|
|
|
- // selectedKeys.value = keys;
|
|
|
- // treeNodeTitle.value = e.node.title;
|
|
|
- // if (e.node.children?.length < 1 && timer) {
|
|
|
- // // getMonitor(true);
|
|
|
- // }
|
|
|
- // }, 1000);
|
|
|
- // }
|
|
|
};
|
|
|
|
|
|
async function findTreeDataValue(obj) {
|
|
|
@@ -278,12 +260,6 @@ async function findTreeDataValue(obj) {
|
|
|
expandedKeys.value = [defaultData.key as string];
|
|
|
treeNodeTitle.value = defaultData.title;
|
|
|
}
|
|
|
-
|
|
|
- // if (timer === undefined) {
|
|
|
- // timer = null;
|
|
|
- // await getDataSource();
|
|
|
- // getMonitor(true);
|
|
|
- // }
|
|
|
}
|
|
|
// 获取树形菜单数据
|
|
|
async function getDeviceType(sysType?) {
|
|
|
@@ -326,6 +302,10 @@ async function getDeviceType(sysType?) {
|
|
|
// 根据选择设备获取设备列表
|
|
|
async function getDeviceList(deviceTypeVal?) {
|
|
|
if (!deviceTypeVal) return;
|
|
|
+ if (timer) {
|
|
|
+ clearInterval(timer);
|
|
|
+ timer = undefined;
|
|
|
+ }
|
|
|
const params: any = {
|
|
|
devKind: deviceTypeVal,
|
|
|
};
|
|
|
@@ -406,6 +386,10 @@ const toggleExpand = (deviceId) => {
|
|
|
if (index > -1) {
|
|
|
// 如果已经展开,则关闭
|
|
|
expandedRowKeys.value.splice(index, 1);
|
|
|
+ if (timer) {
|
|
|
+ clearInterval(timer);
|
|
|
+ timer = undefined;
|
|
|
+ }
|
|
|
} else {
|
|
|
// 如果未展开,则打开
|
|
|
expandedRowKeys.value.push(deviceId);
|
|
|
@@ -413,24 +397,36 @@ const toggleExpand = (deviceId) => {
|
|
|
}
|
|
|
};
|
|
|
// 加载监测数据
|
|
|
-const loadMonitoringData = async (deviceId) => {
|
|
|
- const device = deviceList.value.find((d) => d.id === deviceId);
|
|
|
-
|
|
|
- loadingMap[deviceId] = true;
|
|
|
- try {
|
|
|
- const result = await getDevMonitorListById({ devId: deviceId.toString() });
|
|
|
- monitorList.value = Object.values(result.readData);
|
|
|
- } catch (error) {
|
|
|
- console.error(`加载设备 ${deviceId} 数据失败:`, error);
|
|
|
- } finally {
|
|
|
- loadingMap[deviceId] = false;
|
|
|
+let timer: null | NodeJS.Timeout = null;
|
|
|
+async function loadMonitoringData(deviceId: string) {
|
|
|
+ // 先清除之前的定时器
|
|
|
+ if (timer) {
|
|
|
+ clearInterval(timer);
|
|
|
+ timer = null;
|
|
|
}
|
|
|
-};
|
|
|
+ // 定时器会在1秒后开始,所以先手动加载一次
|
|
|
+ refreshData(deviceId);
|
|
|
+ // 设置新的定时器
|
|
|
+ timer = setInterval(() => {
|
|
|
+ refreshData(deviceId);
|
|
|
+ }, 1000);
|
|
|
+}
|
|
|
+async function refreshData(deviceId: string) {
|
|
|
+ // 这里实现具体的请求逻辑
|
|
|
+ const device = deviceList.value.find((d) => d.id === deviceId);
|
|
|
+ const result = await getDevMonitorListById({ devId: deviceId.toString() });
|
|
|
+ monitorList.value = Object.values(result.readData);
|
|
|
+}
|
|
|
|
|
|
onMounted(async () => {
|
|
|
await getDeviceType();
|
|
|
});
|
|
|
-onUnmounted(() => {});
|
|
|
+onUnmounted(() => {
|
|
|
+ if (timer) {
|
|
|
+ clearInterval(timer);
|
|
|
+ timer = undefined;
|
|
|
+ }
|
|
|
+});
|
|
|
// 监听分页变化
|
|
|
watch(
|
|
|
() => [paginationState.value.current, paginationState.value.pageSize],
|