From bffb6c6166006a82bafd8fe8c874c103abe07a38 Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Wed, 24 Sep 2025 01:39:35 +0800 Subject: [PATCH] fix chartjs --- src/main.ts | 27 +++++++++++++++++++++++++++ src/routes.ts | 5 ----- src/shared/composables/chart.ts | 32 -------------------------------- 3 files changed, 27 insertions(+), 37 deletions(-) delete mode 100644 src/shared/composables/chart.ts diff --git a/src/main.ts b/src/main.ts index 4a142d2..8f4a7bd 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,6 +2,20 @@ import { addAPIProvider } from "@iconify/vue" import { createPinia } from "pinia" import { createRouter, createWebHistory } from "vue-router" +import { + ArcElement, + BarElement, + CategoryScale, + Chart as ChartJS, + Colors, + Legend, + LinearScale, + Title, + Tooltip, + LineElement, + PointElement, +} from "chart.js" + import { STORAGE_KEY } from "utils/constants" import storage from "utils/storage" @@ -28,6 +42,19 @@ router.beforeEach((to, from, next) => { } }) +ChartJS.register( + CategoryScale, + LinearScale, + BarElement, + ArcElement, + LineElement, + PointElement, + Colors, + Title, + Tooltip, + Legend, +) + const pinia = createPinia() const app = createApp(App) app.use(router) diff --git a/src/routes.ts b/src/routes.ts index 8501862..9f996ad 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -1,5 +1,4 @@ import { RouteRecordRaw } from "vue-router" -import { loadChart } from "./shared/composables/chart" export const ojs: RouteRecordRaw = { path: "/", @@ -11,7 +10,6 @@ export const ojs: RouteRecordRaw = { component: () => import("oj/problem/detail.vue"), props: true, name: "problem", - beforeEnter: loadChart, }, { path: "submission", @@ -63,12 +61,10 @@ export const ojs: RouteRecordRaw = { props: true, name: "contest problem", meta: { requiresAuth: true }, - beforeEnter: loadChart, }, { path: "rank", component: () => import("oj/rank/list.vue"), - beforeEnter: loadChart, }, { path: "announcement", @@ -99,7 +95,6 @@ export const ojs: RouteRecordRaw = { path: "ai-analysis", component: () => import("oj/ai/analysis.vue"), meta: { requiresAuth: true }, - beforeEnter: loadChart, }, ], } diff --git a/src/shared/composables/chart.ts b/src/shared/composables/chart.ts deleted file mode 100644 index 6b74df6..0000000 --- a/src/shared/composables/chart.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { - ArcElement, - BarElement, - CategoryScale, - Chart as ChartJS, - Colors, - Legend, - LinearScale, - Title, - Tooltip, - LineElement, - PointElement, -} from "chart.js" - -const [isLoaded] = useToggle() - -export function loadChart() { - if (isLoaded.value) return - ChartJS.register( - CategoryScale, - LinearScale, - BarElement, - ArcElement, - LineElement, - PointElement, - Colors, - Title, - Tooltip, - Legend, - ) - isLoaded.value = true -}