import { onMounted, onUnmounted, ref } from "vue";

export function useTimeInterval(callback, delay = 300000) {
  const intervalId = ref(null);

  onMounted(() => {
    // 设置定时器，每5分钟（300000毫秒）执行一次回调函数
    callback();
    intervalId.value = setInterval(callback, delay);
  });

  onUnmounted(() => {
    // 组件卸载时清除定时器
    if (intervalId.value) {
      clearInterval(intervalId.value);
    }
  });
}
