浏览代码

菜单信息

master
Yanko 2 个月前
父节点
当前提交
cdf35df09e
共有 5 个文件被更改,包括 84 次插入45 次删除
  1. +7
    -7
      frontend/config/routes.ts
  2. +41
    -17
      frontend/src/app.tsx
  3. +2
    -0
      frontend/src/components/HeaderRight/index.tsx
  4. +25
    -17
      frontend/src/pages/system/module/index.tsx
  5. +9
    -4
      frontend/src/requestErrorConfig.ts

+ 7
- 7
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', },
]

},


+ 41
- 17
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: () => <ProBreadcrumb />,
footerRender: () => <Footer />,
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;
};



+ 2
- 0
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;


+ 25
- 17
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) => [
<a key="edit" onClick={() => {
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 = () => {
]}
/>
<Modal
maskClosable={false} footer={null} width={1000} title={currentMenu.id ? '编辑菜单' : '新建菜单'} open={isModalVisible} onCancel={() => setIsModalVisible(false)}>
maskClosable={false} footer={[
<Button
key="back"
onClick={() => {
setIsModalVisible(false)
}}
>
返回
</Button>,
<Button key="submit" form="moduleForm" type="primary" htmlType="submit">
提交
</Button>,
]} width={1000} title={currentMenu.id ? '编辑菜单' : '新建菜单'} open={isModalVisible} onCancel={() => setIsModalVisible(false)}>
<Form
id='moduleForm'
form={menuForm}
onFinish={onFinishMenu}
>
@@ -347,11 +360,6 @@ const SystemManagement: React.FC = () => {
</Form.Item>
</Col>
</Row>
<Form.Item>
<Button type="primary" htmlType="submit">
确定
</Button>
</Form.Item>
</Form>
</Modal>
</div>


+ 9
- 4
frontend/src/requestErrorConfig.ts 查看文件

@@ -50,8 +50,8 @@ export const errorConfig: RequestConfig<MyResponse.Content> = {
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<MyResponse.Content> = {
[
(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;
},


正在加载...
取消
保存