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

@@ -1,5 +1,4 @@
<script lang="ts" setup>
import { useUserStore } from "@/stores/user";
import { ucApiClient } from "@halo-dev/api-client";
import {
Dialog,
@@ -14,6 +13,7 @@ import {
VPageHeader,
VTabbar,
} from "@halo-dev/components";
import { stores } from "@halo-dev/console-shared";
import { useQuery, useQueryClient } from "@tanstack/vue-query";
import { useRouteQuery } from "@vueuse/router";
import { chunk } from "lodash-es";
@@ -25,7 +25,7 @@ import NotificationListItem from "./components/NotificationListItem.vue";
const queryClient = useQueryClient();
const { t } = useI18n();
const { currentUser } = useUserStore();
const { currentUser } = stores.currentUser();
const activeTab = useRouteQuery("tab", "unread");
@@ -39,7 +39,7 @@ const {
queryFn: async () => {
const { data } =
await ucApiClient.notification.notification.listUserNotifications({
username: currentUser?.metadata.name as string,
username: currentUser?.user.metadata.name as string,
fieldSelector: [`spec.unread=${activeTab.value === "unread"}`],
});
@@ -85,7 +85,7 @@ function handleDeleteNotifications() {
await Promise.all(
chunk.map((notification) =>
ucApiClient.notification.notification.deleteSpecifiedNotification({
username: currentUser.metadata.name,
username: currentUser.user.metadata.name,
name: notification.metadata.name,
})
)
@@ -121,7 +121,7 @@ function handleMarkAllAsRead() {
);
await ucApiClient.notification.notification.markNotificationsAsRead({
username: currentUser.metadata.name,
username: currentUser.user.metadata.name,
markSpecifiedRequest: {
names,
},