From 57401c195126623defd074297a5c50f3861a5c70 Mon Sep 17 00:00:00 2001 From: G Date: Tue, 26 Dec 2023 00:26:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20:sparkles:=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97,?= =?UTF-8?q?=E4=BF=AE=E6=94=B9meta=E5=8F=82=E6=95=B0,=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E5=9B=BE=E6=A0=87=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/admin/src/assets/icons/ic_user.svg | 4 ++ apps/admin/src/layout/menu/index.tsx | 8 +-- apps/admin/src/router/guard/guardRoute.tsx | 2 +- apps/admin/src/router/guard/index.tsx | 6 +-- apps/admin/src/router/routes/user.tsx | 38 +++++++++++++++ apps/admin/src/router/types.ts | 54 +++++++++++---------- apps/admin/src/views/user/addUser/index.tsx | 16 ++++++ apps/admin/src/views/user/index.tsx | 23 +++++++++ apps/admin/src/views/user/list/index.tsx | 20 ++++++++ 9 files changed, 137 insertions(+), 34 deletions(-) create mode 100644 apps/admin/src/assets/icons/ic_user.svg create mode 100644 apps/admin/src/router/routes/user.tsx create mode 100644 apps/admin/src/views/user/addUser/index.tsx create mode 100644 apps/admin/src/views/user/index.tsx create mode 100644 apps/admin/src/views/user/list/index.tsx diff --git a/apps/admin/src/assets/icons/ic_user.svg b/apps/admin/src/assets/icons/ic_user.svg new file mode 100644 index 00000000..db5eb370 --- /dev/null +++ b/apps/admin/src/assets/icons/ic_user.svg @@ -0,0 +1,4 @@ + + + + diff --git a/apps/admin/src/layout/menu/index.tsx b/apps/admin/src/layout/menu/index.tsx index ba39f907..0f4f7b76 100644 --- a/apps/admin/src/layout/menu/index.tsx +++ b/apps/admin/src/layout/menu/index.tsx @@ -44,11 +44,11 @@ const LayoutMenu = (props: any) => { setOpenKeys(getOpenKeys(pathname)); }, [pathname]); - const addIcon = (icon?: string) => { + const addIcon = (icon?: string, iconSize?: number) => { if (!icon) return null; return ( - + ); }; @@ -56,9 +56,9 @@ const LayoutMenu = (props: any) => { 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; }; diff --git a/apps/admin/src/router/guard/guardRoute.tsx b/apps/admin/src/router/guard/guardRoute.tsx index 3b19fdd7..07007d79 100644 --- a/apps/admin/src/router/guard/guardRoute.tsx +++ b/apps/admin/src/router/guard/guardRoute.tsx @@ -20,5 +20,5 @@ export const GuardRoute = ({ children }: { children: ReactNode }) => { return ; } - return children; + return <>{children}; }; diff --git a/apps/admin/src/router/guard/index.tsx b/apps/admin/src/router/guard/index.tsx index de991e4b..6833e514 100644 --- a/apps/admin/src/router/guard/index.tsx +++ b/apps/admin/src/router/guard/index.tsx @@ -3,7 +3,7 @@ import { BasicLayout } from '@/layout'; import { GuardRoute } from './guardRoute'; export const LayoutGuard = () => ( - - - + + + ); diff --git a/apps/admin/src/router/routes/user.tsx b/apps/admin/src/router/routes/user.tsx new file mode 100644 index 00000000..33493b89 --- /dev/null +++ b/apps/admin/src/router/routes/user.tsx @@ -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: , + 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; diff --git a/apps/admin/src/router/types.ts b/apps/admin/src/router/types.ts index 9c3df2ad..da4b5d61 100644 --- a/apps/admin/src/router/types.ts +++ b/apps/admin/src/router/types.ts @@ -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; } diff --git a/apps/admin/src/views/user/addUser/index.tsx b/apps/admin/src/views/user/addUser/index.tsx new file mode 100644 index 00000000..e5ba70b5 --- /dev/null +++ b/apps/admin/src/views/user/addUser/index.tsx @@ -0,0 +1,16 @@ +import type { FC } from 'react'; + +interface PAddUser { + onAdd?: (user: any) => void; +} + +const AddUser: FC = ({ onAdd = () => {} }) => { + console.log(onAdd); + + return ( +
+
添加用户
+
+ ); +}; +export default AddUser; diff --git a/apps/admin/src/views/user/index.tsx b/apps/admin/src/views/user/index.tsx new file mode 100644 index 00000000..8a4a4a5e --- /dev/null +++ b/apps/admin/src/views/user/index.tsx @@ -0,0 +1,23 @@ +import type { FC } from 'react'; + +interface PUser { + id: number; + name: string; + email: string; + avatar: string; +} + +const User: FC = ({ id, name, email, avatar }) => { + console.log(id, name, email, avatar); + + return ( +
+
{id}
+
{name}
+
{email}
+
{avatar}
+
+ ); +}; + +export default User; diff --git a/apps/admin/src/views/user/list/index.tsx b/apps/admin/src/views/user/list/index.tsx new file mode 100644 index 00000000..1c76fc4b --- /dev/null +++ b/apps/admin/src/views/user/list/index.tsx @@ -0,0 +1,20 @@ +import type { FC } from 'react'; + +interface PUSerList { + data?: { + id: number; + name: string; + email: string; + avatar: string; + }; +} + +const UserList: FC = ({ data = { id: 0, name: '', email: '', avatar: '' } }) => ( +
+
{data.id}
+
{data.name}
+
{data.email}
+
{data.avatar}
+
+); +export default UserList;