feat: 增加角色管理与奖池配置迁移,优化管理端权限与样式
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
import { create } from "zustand";
|
||||
|
||||
import { getAdminMe } from "@/api/admin-auth";
|
||||
import { setAdminBearerToken } from "@/lib/admin-auth";
|
||||
import { readProfile, writeProfile } from "@/stores/admin-profile";
|
||||
import { readToken, writeToken } from "@/stores/admin-token";
|
||||
@@ -19,6 +20,7 @@ export type AdminSessionState = {
|
||||
clearSession: () => void;
|
||||
/** 从 localStorage 恢复 Token 与管理员摘要(仅客户端) */
|
||||
rehydrate: () => void;
|
||||
refreshAdminProfile: () => Promise<void>;
|
||||
/** @deprecated 使用 {@link clearSession} */
|
||||
clearBearerToken: () => void;
|
||||
};
|
||||
@@ -61,12 +63,28 @@ export const useAdminSessionStore = create<AdminSessionState>((set, get) => ({
|
||||
if (token) {
|
||||
setAdminBearerToken(token);
|
||||
set({ bearerToken: token, adminProfile: profile });
|
||||
void get().refreshAdminProfile();
|
||||
} else {
|
||||
setAdminBearerToken(null);
|
||||
set({ bearerToken: null, adminProfile: null });
|
||||
}
|
||||
},
|
||||
|
||||
refreshAdminProfile: async () => {
|
||||
const token = get().bearerToken ?? readToken();
|
||||
if (!token) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await getAdminMe();
|
||||
writeProfile(result.admin);
|
||||
set({ adminProfile: result.admin });
|
||||
} catch {
|
||||
// 兼容旧缓存失败时不打断页面,留给后续登录态处理。
|
||||
}
|
||||
},
|
||||
|
||||
clearBearerToken: () => {
|
||||
get().clearSession();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user