refactor: refactoring the logic for get the setup state of the system (#686)

#### 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
```
pull/687/head
Ryan Wang 2022-11-09 15:10:12 +08:00 committed by GitHub
parent fdf964b18d
commit e0ca6186ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 2 deletions

View File

@ -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 {

View File

@ -10,8 +10,6 @@ export function setupCheckStatesGuard(router: Router) {
const systemStateStore = useSystemStatesStore();
await systemStateStore.fetchSystemStates();
if (!systemStateStore.states.isSetup) {
next({ name: "Setup" });
return;

View File

@ -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);