From aa7d302f05517751a4c9eef0935fa6183a1960a2 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Wed, 9 Nov 2022 15:10:12 +0800 Subject: [PATCH] refactor: refactoring the logic for get the setup state of the system (halo-dev/console#686) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind improvement /milestone 2.0 #### What this PR does / why we need it: 重构获取系统初始化状态的方式,之前会在每个路由切换前获取,在一定程度上会导致路由切换时卡顿。此 PR 改为仅在首次加载页面的时候调用接口获取,并保留状态由 pinia 管理。 #### Special notes for your reviewer: 测试方式: 1. 需要使用未初始化的 Halo。 2. 测试在未初始化前是否会自动切换到初始化页面。 3. 测试初始化之后是否还会跳转到初始化页面。 #### Does this PR introduce a user-facing change? ```release-note None ``` --- src/main.ts | 4 ++++ src/router/guards/check-states.ts | 2 -- src/views/system/Setup.vue | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index cba0e87c0..7fa378e0a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -18,6 +18,7 @@ import { hasPermission } from "@/utils/permission"; import { useRoleStore } from "@/stores/role"; import type { RouteRecordRaw } from "vue-router"; import { useThemeStore } from "./stores/theme"; +import { useSystemStatesStore } from "./stores/system-states"; const app = createApp(App); @@ -240,6 +241,9 @@ async function initApp() { } catch (e) { console.error("Failed to load plugins", e); } + + const systemStateStore = useSystemStatesStore(); + await systemStateStore.fetchSystemStates(); } catch (e) { console.error(e); } finally { diff --git a/src/router/guards/check-states.ts b/src/router/guards/check-states.ts index 10b7a3eb6..4f4ba3baa 100644 --- a/src/router/guards/check-states.ts +++ b/src/router/guards/check-states.ts @@ -10,8 +10,6 @@ export function setupCheckStatesGuard(router: Router) { const systemStateStore = useSystemStatesStore(); - await systemStateStore.fetchSystemStates(); - if (!systemStateStore.states.isSetup) { next({ name: "Setup" }); return; diff --git a/src/views/system/Setup.vue b/src/views/system/Setup.vue index 752fba1a9..4a18aef8b 100644 --- a/src/views/system/Setup.vue +++ b/src/views/system/Setup.vue @@ -92,6 +92,9 @@ const handleSubmit = async () => { }, }); + const systemStateStore = useSystemStatesStore(); + await systemStateStore.fetchSystemStates(); + router.push({ name: "Dashboard" }); } catch (error) { console.error("Failed to setup", error);