import { defineStore } from "pinia"; import { computed, ref } from "vue"; import { getHealth } from "@/services/health.service"; import type { HealthData } from "@/types/api"; export const useAppStore = defineStore("app", () => { const health = ref(null); const checkingHealth = ref(false); const healthError = ref(null); const isOnline = computed(() => health.value?.status === "ok"); async function refreshHealth() { checkingHealth.value = true; healthError.value = null; try { health.value = await getHealth(); } catch { health.value = null; healthError.value = "后端服务不可用"; } finally { checkingHealth.value = false; } } return { health, checkingHealth, healthError, isOnline, refreshHealth }; });