From cdf35df09e527c000570c0d70bd39a17ed135997 Mon Sep 17 00:00:00 2001 From: Yanko <747575620@qq.com> Date: Thu, 17 Oct 2024 14:59:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8F=9C=E5=8D=95=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/config/routes.ts | 14 ++--- frontend/src/app.tsx | 58 +++++++++++++------ frontend/src/components/HeaderRight/index.tsx | 2 + frontend/src/pages/system/module/index.tsx | 42 ++++++++------ frontend/src/requestErrorConfig.ts | 13 +++-- 5 files changed, 84 insertions(+), 45 deletions(-) diff --git a/frontend/config/routes.ts b/frontend/config/routes.ts index f05dee2..89801ec 100644 --- a/frontend/config/routes.ts +++ b/frontend/config/routes.ts @@ -1,6 +1,6 @@ export default [ { path: '/user', layout: false, routes: [{ path: '/user/login', component: './user/login' }] }, - { path: '/', icon: 'SmileOutlined', component: './welcome', name: '欢迎页' }, + { path: '/', icon: 'SmileOutlined', component: './welcome', name: '欢迎页', routes: []}, { icon: 'SettingOutlined', path: '/system', @@ -13,13 +13,13 @@ ], }, { - path: '/wmx', icon: 'SettingOutlined', name: '设备模型管理', + path: '/deviceModal', icon: 'SettingOutlined', name: '设备模型管理', routes: [{ name: '设备建模', - path: '/wmx/deviceProduct', + path: '/deviceModal/deviceProduct', component: './deviceProductInfo/index', }, - { path: '/wmx/deviceinfo', name: '设备管理', component: './deviceInfo/index' }, + { path: '/deviceModal/deviceinfo', name: '设备管理', component: './deviceInfo/index' }, ] }, { @@ -38,10 +38,10 @@ { path: '/production/final', name: '成品管理', component: './final/index' }, ] }, - { path: '/work', icon: 'SettingOutlined', name: '生产计划管理', + { path: '/work',icon: 'SmileOutlined', name: '生产计划管理', routes: [ - { path: '/work/workPlan', name: '生产计划', component: './workInfo/plan' }, - { path: '/work/workInfo', name: '工单管理', component: './workInfo/index' }, + { path: '/work/workPlan', name: '生产计划', component: './workInfo/plan', }, + { path: '/work/workInfo', name: '工单管理', component: './workInfo/index', }, ] }, diff --git a/frontend/src/app.tsx b/frontend/src/app.tsx index f387314..a645d10 100644 --- a/frontend/src/app.tsx +++ b/frontend/src/app.tsx @@ -11,23 +11,45 @@ import * as Icon from '@ant-design/icons'; const isDev = process.env.NODE_ENV === 'development'; const loopMenuItem = (menus: MenuDataItem[]): MenuDataItem[] => { - return menus?.map(({ icon, routes, ...item }) => ({ - ...item, - icon: icon && React.createElement(Icon && (Icon as any)[item.icon]), - routes: routes && loopMenuItem(routes), + + // menus.map((item:any)=>{ + // item.icon = React.createElement((Icon as any)[item.icon]) + // }) + return menus?.map(({ icon, routes, ...item }) => ( + { + ...item, + icon: (icon as string).trim() ? React.createElement((Icon as any)[icon as string]):React.createElement((Icon as any)['SettingOutlined']), + routes: routes && loopMenuItem(routes), })); }; + const formartRoutes = (menuTree: any[]) => { menuTree.forEach((item) => { item.path = item.url; - if (item.children && item.children.length > 0 && item.category < 2) { - formartRoutes(item.children); + item.component = item.component; + // item.icon = item.icon || 'SettingOutlined' + if (item.routes && item.routes.length > 0 && item.category < 2) { + formartRoutes(item.routes); } else { - delete item.children; + delete item.routes; + } + }); + // menuTree = menuTree.filter((item,index)=>item.routes.length = 0 && item.component == null&& item.category < 2) + // 要保留的属性列表 +const keepProps = ['name', 'path','routes','icon']; +// 使用map和扩展运算符删除多余的属性 +const filteredEntities = menuTree.map(entity => { + // 创建一个只包含要保留属性的对象 + const filtered:any = {}; + keepProps.forEach(prop => { + if (entity.hasOwnProperty(prop)) { + filtered[prop] = entity[prop]; } }); - return menuTree; + return filtered; +}); +return filteredEntities; }; /** @@ -50,8 +72,8 @@ export async function getInitialState(): Promise<{ }; const response = await fetchUserInfo(); if (response) { - localStorage.setItem('USER_INFO', JSON.stringify(response.userInfo)); - localStorage.setItem('USER_MENU', JSON.stringify(response.menus)); + sessionStorage.setItem(`USER_INFO-${response.userInfo.userId}`, JSON.stringify(response.userInfo)); + sessionStorage.setItem(`USER_MENU-${response.userInfo.userId}`, JSON.stringify(response.menus)); return { menuData: formartRoutes(response.menus), currentUser: response.userInfo, @@ -74,8 +96,8 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => { content: '黑菠萝科技研发部', }, token: { - layout:{ - bgLayout:'#001529' + layout: { + bgLayout: '#001529' }, // colorBgAppListIconHover: '#fff', // colorTextAppListIconHover: 'rgba(255,255,255,0.95)', @@ -86,7 +108,7 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => { // colorTextCollapsedButton: '#fff', colorMenuBackground: '#001529',//菜单背景色 //colorBgMenuItemCollapsedHover: '#fff', - colorBgMenuItemCollapsedElevated:'#001529', + colorBgMenuItemCollapsedElevated: '#001529', colorBgMenuItemCollapsedSelected: '#0960bd', colorMenuItemDivider: 'rgba(255,255,255,0.15)', colorBgMenuItemHover: '#0960bd', @@ -116,7 +138,7 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => { headerContentRender: () => , footerRender: () =>