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: () => ,
onPageChange: () => {
- const userToken = localStorage.getItem('USER_TOKEN');
+ const userToken = sessionStorage.getItem('USER_TOKEN');
if (userToken) {
const userInfo = JSON.parse(userToken);
//如果Token不存在跳转登录页面
@@ -139,9 +161,11 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => {
},
...initialState?.settings,
};
- if (config.menuDataRender) {
- delete config.menuDataRender;
- }
+ // if (process.env.NODE_ENV === 'development') {
+ // if (config.menuDataRender) {
+ // delete config.menuDataRender;
+ // }
+ // }
return config;
};
diff --git a/frontend/src/components/HeaderRight/index.tsx b/frontend/src/components/HeaderRight/index.tsx
index eabebf8..4cac907 100644
--- a/frontend/src/components/HeaderRight/index.tsx
+++ b/frontend/src/components/HeaderRight/index.tsx
@@ -18,7 +18,9 @@ const HeaderRight: React.FC = () => {
switch (key) {
case 'logout':
localStorage.clear();
+ sessionStorage.clear();
history.push('/user/login');
+ history.go(0);
case 'edit':
setIsEditPwd(true);
break;
diff --git a/frontend/src/pages/system/module/index.tsx b/frontend/src/pages/system/module/index.tsx
index e6276b1..d7c5fdb 100644
--- a/frontend/src/pages/system/module/index.tsx
+++ b/frontend/src/pages/system/module/index.tsx
@@ -90,7 +90,7 @@ const SystemManagement: React.FC = () => {
title: '操作',
valueType: 'option',
key: 'option',
- fixed:'right',
+ fixed: 'right',
render: (_, record) => [
{
setCurrentMenu(record);
@@ -217,15 +217,15 @@ const SystemManagement: React.FC = () => {
actionRef={tableRef}
columns={menuColumns}
cardBordered
- bordered
- scroll={{ x: true }}
- rowClassName={(record: any, index: number, indent: number) => {
- if (index % 2 === 0) {
- return ''; // 偶数行的类名
- } else {
- return 'even-row-background'; // 奇数行的类名
- }
- }}
+ bordered
+ scroll={{ x: true }}
+ rowClassName={(record: any, index: number, indent: number) => {
+ if (index % 2 === 0) {
+ return ''; // 偶数行的类名
+ } else {
+ return 'even-row-background'; // 奇数行的类名
+ }
+ }}
request={async (values) => {
const params = JSON.parse(JSON.stringify(values));
delete params.current;
@@ -270,7 +270,7 @@ const SystemManagement: React.FC = () => {
pagination={{
current: currentPage,
pageSize: 10,
- showSizeChanger:false,
+ showSizeChanger: false,
onChange: (page) => setCurrentPage(page),
}}
dateFormatter="string"
@@ -282,8 +282,21 @@ const SystemManagement: React.FC = () => {
]}
/>
setIsModalVisible(false)}>
+ maskClosable={false} footer={[
+ ,
+ ,
+ ]} width={1000} title={currentMenu.id ? '编辑菜单' : '新建菜单'} open={isModalVisible} onCancel={() => setIsModalVisible(false)}>
-
-
diff --git a/frontend/src/requestErrorConfig.ts b/frontend/src/requestErrorConfig.ts
index 1602bb7..e370667 100644
--- a/frontend/src/requestErrorConfig.ts
+++ b/frontend/src/requestErrorConfig.ts
@@ -50,8 +50,8 @@ export const errorConfig: RequestConfig = {
config.url = config.url?.replace("/api", '/api/api')
}
// 拦截请求配置,进行个性化处理。
- const userToken = localStorage.getItem('USER_TOKEN');
- const x_Token = localStorage.getItem('USER_X_TOKEN');
+ const userToken = sessionStorage.getItem('USER_TOKEN');
+ const x_Token = sessionStorage.getItem('USER_X_TOKEN');
if (userToken && config.headers) {
const userInfo = JSON.parse(userToken);
const x_Tokens = JSON.parse(x_Token!);
@@ -74,12 +74,17 @@ export const errorConfig: RequestConfig = {
[
(response: AxiosResponse) => {
const userToken = response.headers["access-token"]
+
if (userToken) {
- localStorage.setItem('USER_TOKEN', JSON.stringify(userToken));
+ const jwtinfo = jwt.ecryptJWT(userToken);
+ sessionStorage.setItem(`USER_TOKEN-${jwtinfo.UserId}`, JSON.stringify(userToken));
+ sessionStorage.setItem(`USER_TOKEN`, JSON.stringify(userToken));
}
const xAuth = response.headers["x-access-token"];
if (xAuth) {
- localStorage.setItem('USER_X_TOKEN', JSON.stringify(xAuth));
+ const jwtinfo = jwt.ecryptJWT(userToken);
+ sessionStorage.setItem(`USER_X_TOKEN-${jwtinfo.UserId}`, JSON.stringify(xAuth));
+ sessionStorage.setItem(`USER_X_TOKEN`, JSON.stringify(xAuth));
}
return response;
},