Refactor user and global info stores to shared package (#7858)

#### What type of PR is this?

/area ui
/kind feature
/milestone 2.22.x

#### What this PR does / why we need it:

This PR moves the `currentUser` and `globalInfo` stores to the `@halo-dev/console-shared` package, making them easily accessible for plugins.

In addition, it’s now possible for plugins to define their own global stores using Pinia.

#### Does this PR introduce a user-facing change?

```release-note
- 在 `@halo-dev/console-shared` 包中提供 `stores` 对象,包含 currentUser 和 globalInfo。
- 支持在插件的 UI 中使用 Pinia 定义全局 Store
```
This commit is contained in:
Ryan Wang
2025-10-23 18:32:14 +08:00
committed by GitHub
parent cc4ba4a361
commit e53bfd4edb
43 changed files with 188 additions and 211 deletions

View File

@@ -11,16 +11,14 @@ import "@/setup/setupStyles";
// core modules
import { setupApiClient } from "@/setup/setupApiClient";
import { setupVueQuery } from "@/setup/setupVueQuery";
import { useGlobalInfoStore } from "@/stores/global-info";
import { useRoleStore } from "@/stores/role";
import { useUserStore } from "@/stores/user";
import { getCookie } from "@/utils/cookie";
import {
setupCoreModules,
setupPluginModules,
} from "@console/setup/setupModules";
import { useThemeStore } from "@console/stores/theme";
import { utils } from "@halo-dev/console-shared";
import { stores, utils } from "@halo-dev/console-shared";
import "core-js/es/object/has-own";
const app = createApp(App);
@@ -73,17 +71,17 @@ async function initApp() {
try {
setupCoreModules(app);
const userStore = useUserStore();
await userStore.fetchCurrentUser();
const currentUserStore = stores.currentUser();
await currentUserStore.fetchCurrentUser();
// set locale
i18n.global.locale.value = getCookie("language") || getBrowserLanguage();
utils.date.setLocale(i18n.global.locale.value);
const globalInfoStore = useGlobalInfoStore();
const globalInfoStore = stores.globalInfo();
await globalInfoStore.fetchGlobalInfo();
if (userStore.isAnonymous) {
if (currentUserStore.isAnonymous) {
return;
}