| | |
| | | import { ref, computed } from 'vue' |
| | | import { computed } 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' |
| | | import { DEVICE_INFO_POLLING_DURATION } from '@/common/constants' |
| | | |
| | | 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 |
| | | } |
| | | ) |
| | | // 当前设备在缺少工艺参数的时候是否允许下发生产 |
| | | const currentDeviceAllowNoParams = computed(() => { |
| | | const currentDeviceInfo = deviceInfo.value.deviceList?.find((ele) => { |
| | | return ele.deviceID === deviceInfo.value.currentDeviceID |
| | | }) |
| | | return !currentDeviceInfo?.needSetProcessParams |
| | | }) |
| | | |
| | | /** |
| | | * 如果任务状态是进行中, 则轮询 plc 取进度 |
| | | */ |
| | | const { |
| | | data: deviceRes, |
| | | run: startDevicePolling, |
| | | cancel: cancelDevicePolling |
| | | } = useRequest( |
| | | getDeviceList |
| | | // { |
| | | // manual: true, |
| | | // pollingInterval: DEVICE_INFO_POLLING_DURATION, |
| | | // pollingWhenHidden: false |
| | | // } |
| | | ) |
| | | |
| | | function startPollingDevice() { |
| | | cancelDevicePolling() |
| | | startDevicePolling() |
| | | } |
| | | |
| | | return { devices, deviceIDList, getDevicesInfo } |
| | | return { deviceInfo, startPollingDevice, currentDeviceAllowNoParams } |
| | | }) |