yangfeng
2023-12-12 1519870c0e18171ced014a840e86a459dc6b00f1
src/stores/plc.ts
@@ -5,6 +5,7 @@
import { useRequest } from 'vue-hooks-plus'
import { useTasksStore } from '@/stores/tasks'
import type { PLCResponse } from '@/api/plc'
import { PLC_POLLING_DURATION } from '@/common/constants'
// 全局 watcher ref 防止多次调用 usePLCStore 时重复注册侦听器
const unwatch = ref()
@@ -26,12 +27,12 @@
  } = useRequest(
    () =>
      getProductProgress({
        channel: taskStore.activeTask?.Channel,
        procedureId: taskStore.activeTask?.Procedure.ID
        channel: taskStore.activeChannel ?? 0,
        procedureId: taskStore.activeTask?.Procedure.ID ?? undefined
      } as ProductProgressParams),
    {
      manual: true,
      pollingInterval: 6000,
      pollingInterval: PLC_POLLING_DURATION,
      pollingWhenHidden: false
    }
  )
@@ -41,7 +42,7 @@
     * 如果切换到其他通道的任务,则重新轮询plc
     */
    unwatch.value = watch(
      () => taskStore.activeTask?.Channel,
      () => taskStore.activeChannel,
      () => {
        cancelPLCPolling()
        startPLCPolling()