| | |
| | | export const usePLCStore = defineStore('plc', () => { |
| | | const taskStore = useTasksStore() |
| | | |
| | | const plcInfo = computed(() => { |
| | | return plcRes?.value?.data as PLCResponse |
| | | }) |
| | | const plcInfo = ref() |
| | | |
| | | /** |
| | | * 如果任务状态是进行中, 则轮询 plc 取进度 |
| | | */ |
| | | const { |
| | | data: plcRes, |
| | | run: startPLCPolling, |
| | | cancel: cancelPLCPolling |
| | | } = useRequest( |
| | | () => |
| | | getProductProgress({ |
| | | channel: taskStore.activeChannel ?? 0, |
| | | procedureId: taskStore.activeTask?.Procedure.ID ?? undefined |
| | | } as ProductProgressParams), |
| | | { |
| | | manual: true, |
| | | pollingInterval: PLC_POLLING_DURATION, |
| | | pollingWhenHidden: false |
| | | } |
| | | ) |
| | | // const { |
| | | // data: plcRes, |
| | | // run: startPLCPolling, |
| | | // cancel: cancelPLCPolling |
| | | // } = useRequest( |
| | | // () => |
| | | // getProductProgress({ |
| | | // channel: taskStore.activeChannel ?? 0, |
| | | // procedureId: taskStore.activeTask?.Procedure.ID ?? undefined |
| | | // } as ProductProgressParams), |
| | | // { |
| | | // manual: true, |
| | | // pollingInterval: PLC_POLLING_DURATION, |
| | | // pollingWhenHidden: false |
| | | // } |
| | | // ) |
| | | |
| | | if (!unwatch.value) { |
| | | /** |
| | |
| | | unwatch.value = watch( |
| | | () => taskStore.activeChannel, |
| | | () => { |
| | | cancelPLCPolling() |
| | | startPLCPolling() |
| | | // cancelPLCPolling() |
| | | // startPLCPolling() |
| | | } |
| | | ) |
| | | } |
| | | |
| | | function startPollingPLC() { |
| | | cancelPLCPolling() |
| | | startPLCPolling() |
| | | // cancelPLCPolling() |
| | | // startPLCPolling() |
| | | } |
| | | |
| | | onUnmounted(() => { |
| | | cancelPLCPolling() |
| | | // cancelPLCPolling() |
| | | }) |
| | | |
| | | return { plcInfo, startPollingPLC } |