2026-09-04 10:22:37 +08:00

28 lines
813 B
TypeScript

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<HealthData | null>(null);
const checkingHealth = ref(false);
const healthError = ref<string | null>(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 };
});