import { computed } from 'vue'
|
import { defineStore } from 'pinia'
|
import { getDeviceList } from '@/api'
|
import { useRequest } from 'vue-hooks-plus'
|
import type { Devices } from '@/api/device'
|
import { DEVICE_INFO_POLLING_DURATION } from '@/common/constants'
|
|
export const useDevicesStore = defineStore('device', () => {
|
const deviceInfo = computed(() => {
|
if (deviceInfo?.value) {
|
deviceRes.value.data.currentDeviceID = 'wwwwwwww222222'
|
}
|
return deviceRes?.value?.data as Devices
|
})
|
|
/**
|
* 如果任务状态是进行中, 则轮询 plc 取进度
|
*/
|
const {
|
data: deviceRes,
|
run: startDevicePolling,
|
cancel: cancelDevicePolling
|
} = useRequest(getDeviceList, {
|
manual: true,
|
pollingInterval: DEVICE_INFO_POLLING_DURATION,
|
pollingWhenHidden: false
|
})
|
|
function startPollingDevice() {
|
cancelDevicePolling()
|
startDevicePolling()
|
}
|
|
return { deviceInfo, startPollingDevice }
|
})
|