chore: update frontend/src/stores/userStore.ts
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* 用户状态管理 - UserStore
|
||||||
|
* 功能:集中管理当前用户 userId,替代硬编码的 USER_ID = 6
|
||||||
|
* 持久化:使用 zustand persist 中间件存储到 localStorage,刷新页面不丢失
|
||||||
|
* 后续:接入真实认证系统时,只需替换 userId 的获取方式
|
||||||
|
*/
|
||||||
|
import { create } from 'zustand';
|
||||||
|
import { persist } from 'zustand/middleware';
|
||||||
|
|
||||||
|
interface UserState {
|
||||||
|
userId: number;
|
||||||
|
setUserId: (id: number) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useUserStore = create<UserState>()(
|
||||||
|
persist(
|
||||||
|
(set) => ({
|
||||||
|
userId: 6, // MVP 阶段默认用户 ID,后续由登录态覆盖
|
||||||
|
setUserId: (id) => set({ userId: id }),
|
||||||
|
}),
|
||||||
|
{ name: 'user-storage' }
|
||||||
|
)
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user