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