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

@@ -51,18 +51,27 @@ export const BaseHeader = (props: { main?: React.ComponentType | null }) => {
return (
<>
<div className="flex gap-2 text-lg w-full h-12 items-center justify-between bg-gray-200">
<div className='px-2'>
<div className='px-2 flex items-center gap-1'>
{
store.links.map(link => (
<Link
key={link.key || link.title}
to={link.href}
className="px-3 py-1.5 text-sm text-gray-600 hover:text-gray-900 hover:bg-gray-100 rounded-lg transition-colors"
<div key={link.key || link.title}
className="cursor-pointer flex items-center justify-center gap-1 p-2 text-sm text-gray-600 hover:text-gray-900 hover:bg-gray-100 rounded-lg transition-colors"
onClick={() => {
if (!link.href) return;
if (link.href.startsWith('http') || link.isRoot) {
window.open(link.href, '_blank');
return;
}
navigate({
to: link.href
})
}}
>
{link.key === 'home' && <Home className="w-4 h-4 mr-1" />}
{link.icon && <span className="mr-1">{link.icon}</span>}
{link.title}
</Link>
{link.key === 'home' && <Home className="w-4 h-4" />}
{link.icon && <>{link.icon}</>}
{!link.icon && link.title}
</div>
))
}
</div>

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 }),
}));