提交 84a61eca 作者: 郁骅焌

菜单控制

上级 a104a24e
export function patchRoutes({ routes }) {
console.log(JSON.parse(localStorage.menuTree))
console.log(routes)
}
......@@ -4,6 +4,8 @@ import { ReloadOutlined } from '@ant-design/icons';
import { useLocation, useIntl, history, dropByCacheKey } from 'umi';
import './style.less';
const { REACT_APP_ENV } = process.env;
const { TabPane } = Tabs;
const TabBar = (props, ref) => {
......@@ -49,7 +51,7 @@ const TabBar = (props, ref) => {
if (p) {
const newPanes = panes.slice();
newPanes.push({
title: formatMessage({id: p.menuName}),
title: REACT_APP_ENV === 'dev' ? formatMessage({id: p.menuName}) : p.menuName,
key: path,
});
setPanes(newPanes);
......@@ -86,7 +88,7 @@ const TabBar = (props, ref) => {
if (p) {
const newPanes = panes.slice();
newPanes.push({
title: formatMessage({id: p.menuName}),
title: REACT_APP_ENV === 'dev' ? formatMessage({id: p.menuName}) : p.menuName,
key: pathname,
});
setPanes(newPanes);
......
......@@ -6,7 +6,7 @@
import ProLayout, { DefaultFooter } from '@ant-design/pro-layout';
import React, { useState, useEffect, useRef, useMemo } from 'react';
import { Link, useIntl, connect, history, FormattedMessage, KeepAliveLayout } from 'umi';
import { GithubOutlined, MenuFoldOutlined, MenuUnfoldOutlined } from '@ant-design/icons';
import { createFromIconfontCN, GithubOutlined, MenuFoldOutlined, MenuUnfoldOutlined } from '@ant-design/icons';
import { Result, Button, Menu } from 'antd';
import Authorized from '@/utils/Authorized';
import RightContent from '@/components/GlobalHeader/RightContent';
......@@ -17,6 +17,12 @@ import logo from '../assets/logo.svg';
import './BasicLayout.less'
const { REACT_APP_ENV } = process.env;
const IconFont = createFromIconfontCN({
scriptUrl: '//at.alicdn.com/t/font_1873986_46xeik9dra8.js',
});
const { SubMenu } = Menu;
const noMatch = (
......@@ -111,6 +117,8 @@ const BasicLayout = (props) => {
// 处理菜单数据
const disposeMenu = (list, pname, pitem) => {
if (REACT_APP_ENV === 'dev') {
list.forEach(item => {
const menuName = pname ? `${pname}.${item.name}` : `menu.${item.name}`
item.menuName = menuName
......@@ -121,17 +129,43 @@ const BasicLayout = (props) => {
disposeMenu(item.children, menuName, item)
}
})
} else {
list.forEach(item => {
item.path = item.url
if (item.parentId !== 0) {
item.parentPath = pitem.path
}
if (item.children) {
if (item.children.length !== 0) {
disposeMenu(item.children, item.menuName, item)
} else {
delete item.children
}
}
})
}
return list
}
// 获取菜单
const getMenuTree = () => {
const menuList = []
if (REACT_APP_ENV === 'dev') {
route.children.forEach(item => {
if (!item.redirect) {
menuList.push(item)
}
})
} else {
const localMenuTree = JSON.parse(localStorage.menuTree)
console.log(localMenuTree)
localMenuTree.forEach(item => {
menuList.push(item)
})
}
return disposeMenu(menuList)
}
......@@ -141,7 +175,7 @@ const BasicLayout = (props) => {
return menuChildren.map(item => {
if (item.children) {
return (
<SubMenu key={item.path} icon={item.icon} title={<FormattedMessage id={item.menuName} />}>
<SubMenu key={item.path} icon={<IconFont type={`icon-${item.icon}`} />} title={REACT_APP_ENV === 'dev' ? <FormattedMessage id={item.menuName} /> : item.menuName }>
{
getMenuChildren(item.children)
}
......@@ -149,8 +183,10 @@ const BasicLayout = (props) => {
)
}
return (
<Menu.Item key={item.path} icon={item.icon}>
<FormattedMessage id={item.menuName} />
<Menu.Item key={item.path} icon={<IconFont type={`icon-${item.icon}`} />}>
{
REACT_APP_ENV === 'dev' ? <FormattedMessage id={item.menuName} /> : item.menuName
}
</Menu.Item>
)
})
......
......@@ -22,6 +22,8 @@ const Model = {
},
}); // Login successfully
// 菜单赋值
localStorage.menuTree = JSON.stringify(response.data.menuTree)
const urlParams = new URL(window.location.href);
const params = getPageQuery();
......
......@@ -19,7 +19,7 @@ const UserModel = {
if (response.isSuccess) {
const userInfo = response.data
userInfo.name = userInfo.user || '创世者'
userInfo.name = userInfo.loginName || '创世者'
userInfo.avatar = 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png'
yield put({
......
......@@ -112,13 +112,13 @@ const CreateForm = (props, ref) => {
},
{
name: 'status',
label: '部门状态',
type: 'radio',
initialValue: '1',
options: [
{ value: '1', text: '启用' },
{ value: '0', text: '禁用' },
]
label: '状态',
type: 'switch',
initialValue: true,
props: {
checkedChildren: '启用',
unCheckedChildren: '禁用'
}
},
]
......
......@@ -105,12 +105,11 @@ const UpdateForm = (props, ref) => {
{
name: 'status',
label: '部门状态',
type: 'radio',
initialValue: '1',
options: [
{ value: '1', text: '启用' },
{ value: '0', text: '禁用' },
]
type: 'switch',
props: {
checkedChildren: '启用',
unCheckedChildren: '禁用'
}
},
]
......
......@@ -100,7 +100,7 @@ const DeptList = () => {
leader: data.leader,
phone: data.phone,
email: data.email,
status: data.status
status: data.status === '1'
})
}
......@@ -165,7 +165,7 @@ const DeptList = () => {
title: '状态',
dataIndex: 'status',
key: 'status',
render: (text, record) => <Switch checked={text === '1'} onChange={(checked) => onChangeStatus(checked, record)} />
render: (text, record) => <Switch checkedChildren="启用" unCheckedChildren="禁用" checked={text === '1'} onChange={(checked) => onChangeStatus(checked, record)} />
},
{
title: '创建时间',
......
......@@ -87,12 +87,11 @@ const CreateForm = (props, ref) => {
},
{
name: 'url',
label: menuType === '1' ? '路由地址' : '请求地址',
label: menuType === '0' || menuType === '1' ? '路由地址' : '请求地址',
type: 'input',
props: {
placeholder: '请输入'
},
isShow: menuType === '1' || menuType === '2'
}
},
{
name: 'target',
......
......@@ -81,12 +81,11 @@ const UpdateForm = (props, ref) => {
},
{
name: 'url',
label: menuType === '1' ? '路由地址' : '请求地址',
label: menuType === '0' || menuType === '1' ? '路由地址' : '请求地址',
type: 'input',
props: {
placeholder: '请输入'
},
isShow: menuType === '1' || menuType === '2'
},
{
name: 'target',
......
......@@ -134,7 +134,7 @@ const MenuList = () => {
dataIndex: 'url',
key: 'url',
width: 200,
render: (text, record) => record.menuType === '1' ? text : ''
render: (text, record) => record.menuType === '0' || record.menuType === '1' ? text : ''
},
{
title: '请求地址',
......
......@@ -35,6 +35,10 @@ const CreateForm = (props, ref) => {
label: '状态',
type: 'switch',
initialValue: true,
props: {
checkedChildren: '启用',
unCheckedChildren: '禁用'
}
}
]
......
......@@ -33,7 +33,11 @@ const UpdateForm = (props, ref) => {
{
name: 'status',
label: '状态',
type: 'switch'
type: 'switch',
props: {
checkedChildren: '启用',
unCheckedChildren: '禁用'
}
}
]
......
......@@ -151,7 +151,7 @@ const TableList = () => {
title: '角色状态',
dataIndex: 'status',
key: 'status',
render: (text, record) => <Switch checked={text === '1'} onChange={(checked) => onChangeStatus(checked, record)} />
render: (text, record) => <Switch checkedChildren="启用" unCheckedChildren="禁用" checked={text === '1'} onChange={(checked) => onChangeStatus(checked, record)} />
},
{
title: '创建时间',
......
......@@ -133,6 +133,10 @@ const CreateForm = (props, ref) => {
label: '状态',
type: 'switch',
initialValue: true,
props: {
checkedChildren: '启用',
unCheckedChildren: '禁用'
}
},
{
name: 'headImage',
......
......@@ -133,6 +133,10 @@ const UpdateForm = (props, ref) => {
name: 'status',
label: '状态',
type: 'switch',
props: {
checkedChildren: '启用',
unCheckedChildren: '禁用'
}
},
{
name: 'headImage',
......
......@@ -166,7 +166,7 @@ const TableList = () => {
title: '状态',
dataIndex: 'status',
key: 'status',
render: (text, record) => <Switch checked={text === '1'} onChange={(checked) => onChangeStatus(checked, record)} />
render: (text, record) => <Switch checkedChildren="启用" unCheckedChildren="禁用" checked={text === '1'} onChange={(checked) => onChangeStatus(checked, record)} />
},
{
title: '操作',
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论