Skip to content

Commit

Permalink
feat: ✨ 添加用户管理模块,修改meta参数,支持自定义图标大小
Browse files Browse the repository at this point in the history
  • Loading branch information
G committed Dec 25, 2023
1 parent d86ca8b commit 57401c1
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 34 deletions.
4 changes: 4 additions & 0 deletions apps/admin/src/assets/icons/ic_user.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions apps/admin/src/layout/menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ const LayoutMenu = (props: any) => {
setOpenKeys(getOpenKeys(pathname));
}, [pathname]);

const addIcon = (icon?: string) => {
const addIcon = (icon?: string, iconSize?: number) => {
if (!icon) return null;
return (
<span className='anticon'>
<SvgIcon name={icon} size={16} />
<SvgIcon name={icon} size={iconSize || 16} />
</span>
);
};

const getMenuItem = (data: AppMenu[], list: MenuItem[] = []) => {
data.forEach((item: AppMenu) => {
if (!item?.children?.length) {
return list.push(getItem(item.name, item.path, addIcon(item.icon)));
return list.push(getItem(item.name, item.path, addIcon(item.icon, item.iconSize)));
}
list.push(getItem(item.name, item.path, addIcon(item.icon), getMenuItem(item.children)));
list.push(getItem(item.name, item.path, addIcon(item.icon, item.iconSize), getMenuItem(item.children)));
});
return list;
};
Expand Down
2 changes: 1 addition & 1 deletion apps/admin/src/router/guard/guardRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export const GuardRoute = ({ children }: { children: ReactNode }) => {
return <Navigate to={`/login?redirect=${pathname}`} replace />;
}

return children;
return <>{children}</>;
};
6 changes: 3 additions & 3 deletions apps/admin/src/router/guard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BasicLayout } from '@/layout';
import { GuardRoute } from './guardRoute';

export const LayoutGuard = () => (
<GuardRoute>
<BasicLayout />
</GuardRoute>
<GuardRoute>
<BasicLayout />
</GuardRoute>
);
38 changes: 38 additions & 0 deletions apps/admin/src/router/routes/user.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { lazy } from 'react';

import { LazyLoad } from '@/components/LazyLoad';

import { LayoutGuard } from '../guard';

import type { RouteObject } from '../types';

// user module page
const UserRoute: RouteObject = {
path: '/user',
element: <LayoutGuard />,
meta: {
title: '用户管理',
icon: 'ic_user',
orderNo: 2,
iconSize: 20,
},
children: [
{
path: 'user-list',
element: LazyLoad(lazy(() => import('@/views/user/list'))),
meta: {
title: '用户列表',
key: 'userList',
},
},
{
path: 'add-user',
element: LazyLoad(lazy(() => import('@/views/user/addUser'))),
meta: {
title: '添加用户',
key: 'addUser',
},
},
],
};
export default UserRoute;
54 changes: 28 additions & 26 deletions apps/admin/src/router/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,38 @@ import type { ReactNode } from 'react';
import type { LoaderFunction } from 'react-router-dom';

export interface MetaProps {
title: string
key?: string
icon?: string
affix?: boolean
keepAlive?: boolean
orderNo?: number
hideMenu?: boolean
hideChildrenInMenu?: boolean
title: string;
key?: string;
icon?: string;
iconSize?: number;
affix?: boolean;
keepAlive?: boolean;
orderNo?: number;
hideMenu?: boolean;
hideChildrenInMenu?: boolean;
}

export interface RouteObject {
id?: string
loader?: LoaderFunction
element?: ReactNode
path?: string
fullPath?: string
children?: RouteObject[]
index?: false
meta?: MetaProps
id?: string;
loader?: LoaderFunction;
element?: ReactNode;
path?: string;
fullPath?: string;
children?: RouteObject[];
index?: false;
meta?: MetaProps;
}

export interface AppMenu {
name: string
path: string
children?: AppMenu[]
disabled?: boolean
icon?: string
affix?: boolean
orderNo?: number
hideMenu?: boolean
hideChildrenInMenu?: boolean
hideBreadcrumb?: boolean
name: string;
path: string;
children?: AppMenu[];
disabled?: boolean;
icon?: string;
iconSize?: number;
affix?: boolean;
orderNo?: number;
hideMenu?: boolean;
hideChildrenInMenu?: boolean;
hideBreadcrumb?: boolean;
}
16 changes: 16 additions & 0 deletions apps/admin/src/views/user/addUser/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { FC } from 'react';

interface PAddUser {
onAdd?: (user: any) => void;
}

const AddUser: FC<PAddUser> = ({ onAdd = () => {} }) => {
console.log(onAdd);

return (
<div>
<div>添加用户</div>
</div>
);
};
export default AddUser;
23 changes: 23 additions & 0 deletions apps/admin/src/views/user/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { FC } from 'react';

interface PUser {
id: number;
name: string;
email: string;
avatar: string;
}

const User: FC<PUser> = ({ id, name, email, avatar }) => {
console.log(id, name, email, avatar);

return (
<div>
<div>{id}</div>
<div>{name}</div>
<div>{email}</div>
<div>{avatar}</div>
</div>
);
};

export default User;
20 changes: 20 additions & 0 deletions apps/admin/src/views/user/list/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { FC } from 'react';

interface PUSerList {
data?: {
id: number;
name: string;
email: string;
avatar: string;
};
}

const UserList: FC<PUSerList> = ({ data = { id: 0, name: '', email: '', avatar: '' } }) => (
<div>
<div>{data.id}</div>
<div>{data.name}</div>
<div>{data.email}</div>
<div>{data.avatar}</div>
</div>
);
export default UserList;

0 comments on commit 57401c1

Please sign in to comment.