From 7e7424b2662e5b27dcc1c0d37f43e909e0b15ee1 Mon Sep 17 00:00:00 2001 From: songshankun <songshankun@foxmail.com> Date: 星期四, 02 十一月 2023 16:47:38 +0800 Subject: [PATCH] feat: 轮询plc/设备/调整集群状态组件/title组件加图标 --- src/stores/devices.ts | 44 ++++++++++++++++++++++++++++---------------- 1 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/stores/devices.ts b/src/stores/devices.ts index a961994..4c74113 100644 --- a/src/stores/devices.ts +++ b/src/stores/devices.ts @@ -1,23 +1,35 @@ -import { ref, computed } from 'vue' +import { computed, onUnmounted } from 'vue' import { defineStore } from 'pinia' -import type { Devices } from '@/api/device' import { getDeviceList } from '@/api' +import { useRequest } from 'vue-hooks-plus' +import type { Devices } from '@/api/device' -export const useDevicesStore = defineStore('counter', () => { - const devices = ref<Devices>() - const deviceIDList = computed(() => devices?.value?.deviceIDList ?? []) +export const useDevicesStore = defineStore('device', () => { + const deviceInfo = computed(() => { + return deviceRes?.value?.data as Devices + }) - function getDevicesInfo() { - getDeviceList().then( - (res) => { - devices.value = res?.data - }, - (err) => { - console.error(err) - devices.value = undefined - } - ) + /** + * 濡傛灉浠诲姟鐘舵�佹槸杩涜涓�, 鍒欒疆璇� plc 鍙栬繘搴� + */ + const { + data: deviceRes, + run: startDevicePolling, + cancel: cancelDevicePolling + } = useRequest(getDeviceList, { + manual: true, + pollingInterval: 6000, + pollingWhenHidden: false + }) + + function startPollingDevice() { + cancelDevicePolling() + startDevicePolling() } - return { devices, deviceIDList, getDevicesInfo } + onUnmounted(() => { + cancelDevicePolling() + }) + + return { deviceInfo, startPollingDevice } }) -- Gitblit v1.8.0