feat: 优化导航链接的点击处理和类型定义

This commit is contained in:
2026-02-26 01:49:36 +08:00
parent 60a7328889
commit 9e8c658159
2 changed files with 28 additions and 23 deletions

View File

@@ -34,13 +34,15 @@ export type LayoutStore = {
};
setLoginPageConfig: (config: Partial<LayoutStore['loginPageConfig']>) => void;
links: HeaderLink[];
setLinks: (links: HeaderLink[]) => void;
};
type HeaderLink = {
title: string;
title?: string;
href: string;
description?: string;
icon?: React.ReactNode;
key?: string;
isRoot?: boolean;
};
export const useLayoutStore = create<LayoutStore>((set, get) => ({
@@ -78,19 +80,12 @@ export const useLayoutStore = create<LayoutStore>((set, get) => ({
const token = await queryLogin.getToken();
if (token) {
set({ me: {} })
let me: UserInfo | undefined = undefined;
const _user = await queryLogin.checkLocalUser() as UserInfo;
if (_user) {
me = _user;
}
if (!me) {
const res = await queryLogin.getMe();
me = res.code === 200 ? res.data : undefined;
}
if (me) {
set({ me: me });
set({ isAdmin: me.orgs?.includes?.('admin') || false });
const me = await queryLogin.getMe();
// const user = await queryLogin.checkLocalUser() as UserInfo;
const user = me.code === 200 ? me.data : undefined;
if (user) {
set({ me: user });
set({ isAdmin: user.orgs?.includes?.('admin') || false });
} else {
set({ me: undefined, isAdmin: false });
}
@@ -107,4 +102,5 @@ export const useLayoutStore = create<LayoutStore>((set, get) => ({
loginPageConfig: { ...state.loginPageConfig, ...config },
})),
links: [{ title: '', href: '/', key: 'home' }],
setLinks: (links) => set({ links }),
}));