import { createApp } from "vue"; import { createPinia } from "pinia"; import { listen } from "@tauri-apps/api/event"; import PrimeVue from "primevue/config"; import { AiclientPreset } from "./theme/aiclient-preset.js"; import Button from "primevue/button"; import InputText from "primevue/inputtext"; import Password from "primevue/password"; import Message from "primevue/message"; import Card from "primevue/card"; import Select from "primevue/select"; import Textarea from "primevue/textarea"; import InputNumber from "primevue/inputnumber"; import Slider from "primevue/slider"; import Checkbox from "primevue/checkbox"; import RadioButton from "primevue/radiobutton"; import SelectButton from "primevue/selectbutton"; import Tabs from "primevue/tabs"; import TabList from "primevue/tablist"; import Tab from "primevue/tab"; import TabPanels from "primevue/tabpanels"; import TabPanel from "primevue/tabpanel"; import DatePicker from "primevue/datepicker"; import Dialog from "primevue/dialog"; import DataTable from "primevue/datatable"; import Column from "primevue/column"; import Tag from "primevue/tag"; import DashboardCard from "./components/dashboard/DashboardCard.vue"; import App from "./App.vue"; import router from "./router"; import { useAuthStore } from "./stores/auth.js"; import "primeicons/primeicons.css"; import "./styles/main.css"; const app = createApp(App); const pinia = createPinia(); app.use(pinia); app.use(router); app.use(PrimeVue, { theme: { preset: AiclientPreset, options: { darkModeSelector: ".dark", cssLayer: false, }, }, }); app.component("Button", Button); app.component("InputText", InputText); app.component("Password", Password); app.component("Message", Message); app.component("Card", Card); app.component("Select", Select); app.component("Textarea", Textarea); app.component("InputNumber", InputNumber); app.component("Slider", Slider); app.component("Checkbox", Checkbox); app.component("RadioButton", RadioButton); app.component("SelectButton", SelectButton); app.component("Tabs", Tabs); app.component("TabList", TabList); app.component("Tab", Tab); app.component("TabPanels", TabPanels); app.component("TabPanel", TabPanel); app.component("DashboardCard", DashboardCard); app.component("DatePicker", DatePicker); app.component("Dialog", Dialog); app.component("DataTable", DataTable); app.component("Column", Column); app.component("Tag", Tag); const authStore = useAuthStore(pinia); authStore.hydrateRustSession(); function setupHeartbeatLogoutListener() { if (typeof window === "undefined" || !("__TAURI_INTERNALS__" in window)) { return; } listen("auth-heartbeat-failed", async (event) => { const message = typeof event.payload === "string" ? event.payload : event.payload?.message ?? "会话已失效"; console.warn("[heartbeat] failed:", message); if (!authStore.isAuthenticated) { return; } authStore.redirectToCardActivate(router); }); } function setupVipWatch() { authStore.$subscribe(() => { if (!authStore.needsVipActivation) return; if (router.currentRoute.value.name === "card-activate") return; authStore.redirectToCardActivate(router); }); } setupHeartbeatLogoutListener(); setupVipWatch(); app.mount("#app");