mirror of
https://github.com/zuiidea/antd-admin
synced 2026-11-01 07:20:20 +00:00
Optimize mock related files and variable names.
This commit is contained in:
@@ -10,31 +10,31 @@ import styles from './Layout.less'
|
||||
@withI18n()
|
||||
class Bread extends PureComponent {
|
||||
render() {
|
||||
const { menu, location, i18n } = this.props
|
||||
const { menuList, location, i18n } = this.props
|
||||
// 匹配当前路由
|
||||
let pathArray = []
|
||||
let current
|
||||
for (let index in menu) {
|
||||
for (let index in menuList) {
|
||||
if (
|
||||
menu[index].route &&
|
||||
pathMatchRegexp(menu[index].route, location.pathname)
|
||||
menuList[index].route &&
|
||||
pathMatchRegexp(menuList[index].route, location.pathname)
|
||||
) {
|
||||
current = menu[index]
|
||||
current = menuList[index]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
const getPathArray = item => {
|
||||
pathArray.unshift(item)
|
||||
if (item.bpid) {
|
||||
getPathArray(queryArray(menu, 'id', item.bpid))
|
||||
if (item.breadcrumbParentId) {
|
||||
getPathArray(queryArray(menuList, 'id', item.breadcrumbParentId))
|
||||
}
|
||||
}
|
||||
|
||||
let paramMap = {}
|
||||
if (!current) {
|
||||
pathArray.push(
|
||||
menu[0] || {
|
||||
menuList[0] || {
|
||||
id: 1,
|
||||
icon: 'laptop',
|
||||
name: i18n.t`Dashboard`,
|
||||
|
||||
@@ -18,11 +18,11 @@ const Header = ({
|
||||
switchMenuPopover,
|
||||
navOpenKeys,
|
||||
changeOpenKeys,
|
||||
menu,
|
||||
menuList,
|
||||
}) => {
|
||||
let handleClickMenu = e => e.key === 'logout' && logout()
|
||||
const menusProps = {
|
||||
menu,
|
||||
menuList,
|
||||
siderFold: false,
|
||||
darkTheme: false,
|
||||
isNavbar,
|
||||
@@ -81,7 +81,7 @@ const Header = ({
|
||||
}
|
||||
|
||||
Header.propTypes = {
|
||||
menu: PropTypes.array,
|
||||
menuList: PropTypes.array,
|
||||
user: PropTypes.object,
|
||||
logout: PropTypes.func,
|
||||
switchSider: PropTypes.func,
|
||||
|
||||
@@ -14,14 +14,14 @@ class Menus extends PureComponent {
|
||||
darkTheme,
|
||||
navOpenKeys,
|
||||
changeOpenKeys,
|
||||
menu,
|
||||
menuList,
|
||||
location,
|
||||
} = this.props
|
||||
// 生成树状
|
||||
const menuTree = arrayToTree(
|
||||
menu.filter(_ => _.mpid !== '-1'),
|
||||
menuList.filter(_ => _.menuParentId !== '-1'),
|
||||
'id',
|
||||
'mpid'
|
||||
'menuParentId'
|
||||
)
|
||||
const levelMap = {}
|
||||
|
||||
@@ -29,8 +29,8 @@ class Menus extends PureComponent {
|
||||
const getMenus = (menuTreeN, siderFoldN) => {
|
||||
return menuTreeN.map(item => {
|
||||
if (item.children) {
|
||||
if (item.mpid) {
|
||||
levelMap[item.id] = item.mpid
|
||||
if (item.menuParentId) {
|
||||
levelMap[item.id] = item.menuParentId
|
||||
}
|
||||
return (
|
||||
<SubMenu
|
||||
@@ -106,10 +106,10 @@ class Menus extends PureComponent {
|
||||
// 寻找选中路由
|
||||
let currentMenu
|
||||
let defaultSelectedKeys
|
||||
for (let item of menu) {
|
||||
for (let item of menuList) {
|
||||
if (item.route && pathMatchRegexp(item.route, location.pathname)) {
|
||||
if (!navOpenKeys.length && item.mpid && !openKeysFlag)
|
||||
changeOpenKeys([String(item.mpid)])
|
||||
if (!navOpenKeys.length && item.menuParentId && !openKeysFlag)
|
||||
changeOpenKeys([String(item.menuParentId)])
|
||||
currentMenu = item
|
||||
break
|
||||
}
|
||||
@@ -119,7 +119,7 @@ class Menus extends PureComponent {
|
||||
const getPath = item => {
|
||||
if (item && item[pid]) {
|
||||
if (item[pid] === '-1') {
|
||||
result.unshift(String(item['bpid']))
|
||||
result.unshift(String(item['breadcrumbParentId']))
|
||||
} else {
|
||||
result.unshift(String(item[pid]))
|
||||
getPath(queryArray(array, id, item[pid]))
|
||||
@@ -130,7 +130,12 @@ class Menus extends PureComponent {
|
||||
return result
|
||||
}
|
||||
if (currentMenu) {
|
||||
defaultSelectedKeys = getPathArray(menu, currentMenu, 'mpid', 'id')
|
||||
defaultSelectedKeys = getPathArray(
|
||||
menuList,
|
||||
currentMenu,
|
||||
'menuParentId',
|
||||
'id'
|
||||
)
|
||||
}
|
||||
|
||||
if (!defaultSelectedKeys) {
|
||||
@@ -151,7 +156,7 @@ class Menus extends PureComponent {
|
||||
}
|
||||
}
|
||||
Menus.propTypes = {
|
||||
menu: PropTypes.array,
|
||||
menuList: PropTypes.array,
|
||||
siderFold: PropTypes.bool,
|
||||
darkTheme: PropTypes.bool,
|
||||
navOpenKeys: PropTypes.array,
|
||||
|
||||
@@ -16,12 +16,12 @@ class Sider extends PureComponent {
|
||||
changeTheme,
|
||||
navOpenKeys,
|
||||
changeOpenKeys,
|
||||
menu,
|
||||
menuList,
|
||||
i18n,
|
||||
} = this.props
|
||||
|
||||
const menusProps = {
|
||||
menu,
|
||||
menuList,
|
||||
siderFold,
|
||||
darkTheme,
|
||||
location,
|
||||
@@ -57,7 +57,7 @@ class Sider extends PureComponent {
|
||||
}
|
||||
|
||||
Sider.propTypes = {
|
||||
menu: PropTypes.array,
|
||||
menuList: PropTypes.array,
|
||||
siderFold: PropTypes.bool,
|
||||
darkTheme: PropTypes.bool,
|
||||
location: PropTypes.object,
|
||||
|
||||
@@ -6,10 +6,11 @@ import withRouter from 'umi/withRouter'
|
||||
import { connect } from 'dva'
|
||||
import { MyLayout } from 'components'
|
||||
import { BackTop, Layout } from 'antd'
|
||||
import { GlobalFooter } from 'ant-design-pro'
|
||||
import { classnames, config, pathMatchRegexp } from 'utils'
|
||||
import Error from '../pages/404'
|
||||
|
||||
const { Content, Footer, Sider } = Layout
|
||||
const { Content, Sider } = Layout
|
||||
const { Header, Bread, styles } = MyLayout
|
||||
const { prefix } = config
|
||||
|
||||
@@ -25,12 +26,12 @@ class PrimaryLayout extends PureComponent {
|
||||
isNavbar,
|
||||
menuPopoverVisible,
|
||||
navOpenKeys,
|
||||
menu,
|
||||
menuList,
|
||||
permissions,
|
||||
} = app
|
||||
let { pathname } = location
|
||||
pathname = pathname.startsWith('/') ? pathname : `/${pathname}`
|
||||
const current = menu.filter(item =>
|
||||
const current = menuList.filter(item =>
|
||||
pathMatchRegexp(item.route || '', pathname)
|
||||
)
|
||||
const hasPermission = current.length
|
||||
@@ -38,7 +39,7 @@ class PrimaryLayout extends PureComponent {
|
||||
: false
|
||||
|
||||
const headerProps = {
|
||||
menu,
|
||||
menuList,
|
||||
user,
|
||||
location,
|
||||
siderFold,
|
||||
@@ -63,7 +64,7 @@ class PrimaryLayout extends PureComponent {
|
||||
}
|
||||
|
||||
const siderProps = {
|
||||
menu,
|
||||
menuList,
|
||||
location,
|
||||
siderFold,
|
||||
darkTheme,
|
||||
@@ -84,7 +85,7 @@ class PrimaryLayout extends PureComponent {
|
||||
}
|
||||
|
||||
const breadProps = {
|
||||
menu,
|
||||
menuList,
|
||||
location,
|
||||
}
|
||||
|
||||
@@ -96,26 +97,26 @@ class PrimaryLayout extends PureComponent {
|
||||
[styles.light]: !darkTheme,
|
||||
})}
|
||||
>
|
||||
{!isNavbar && (
|
||||
{!isNavbar ? (
|
||||
<Sider trigger={null} collapsible collapsed={siderFold}>
|
||||
{siderProps.menu.length === 0 ? null : (
|
||||
{siderProps.menuList.length === 0 ? null : (
|
||||
<MyLayout.Sider {...siderProps} />
|
||||
)}
|
||||
</Sider>
|
||||
)}
|
||||
) : null}
|
||||
<Layout
|
||||
style={{ height: '100vh', overflow: 'scroll' }}
|
||||
id="PrimaryLayoutContainer"
|
||||
>
|
||||
<BackTop
|
||||
target={() => document.getElementById('PrimaryLayoutContainer')}
|
||||
/>
|
||||
<Header {...headerProps} />
|
||||
<Content>
|
||||
<Bread {...breadProps} />
|
||||
{hasPermission ? children : <Error />}
|
||||
</Content>
|
||||
<Footer>{config.footerText}</Footer>
|
||||
<BackTop
|
||||
target={() => document.getElementById('PrimaryLayoutContainer')}
|
||||
/>
|
||||
<GlobalFooter copyright={config.copyright} />
|
||||
</Layout>
|
||||
</Layout>
|
||||
</Fragment>
|
||||
|
||||
+4
-4
@@ -18,7 +18,7 @@ export default {
|
||||
permissions: {
|
||||
visit: [],
|
||||
},
|
||||
menu: [
|
||||
menuList: [
|
||||
{
|
||||
id: 1,
|
||||
icon: 'laptop',
|
||||
@@ -66,14 +66,14 @@ export default {
|
||||
if (success && user) {
|
||||
const { list } = yield call(queryMenuList)
|
||||
const { permissions } = user
|
||||
let menu = list
|
||||
let menuList = list
|
||||
if (
|
||||
permissions.role === RoleType.ADMIN ||
|
||||
permissions.role === RoleType.DEVELOPER
|
||||
) {
|
||||
permissions.visit = list.map(item => item.id)
|
||||
} else {
|
||||
menu = list.filter(item => {
|
||||
menuList = list.filter(item => {
|
||||
const cases = [
|
||||
permissions.visit.includes(item.id),
|
||||
item.mpid
|
||||
@@ -89,7 +89,7 @@ export default {
|
||||
payload: {
|
||||
user,
|
||||
permissions,
|
||||
menu,
|
||||
menuList,
|
||||
},
|
||||
})
|
||||
if (location.pathname === '/login') {
|
||||
|
||||
+10
-12
@@ -25,18 +25,16 @@ class User extends PureComponent {
|
||||
} = user
|
||||
|
||||
const handleRefresh = newQuery => {
|
||||
dispatch(
|
||||
router.push({
|
||||
pathname,
|
||||
search: stringify(
|
||||
{
|
||||
...query,
|
||||
...newQuery,
|
||||
},
|
||||
{ arrayFormat: 'repeat' }
|
||||
),
|
||||
})
|
||||
)
|
||||
router.push({
|
||||
pathname,
|
||||
search: stringify(
|
||||
{
|
||||
...query,
|
||||
...newQuery,
|
||||
},
|
||||
{ arrayFormat: 'repeat' }
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
const modalProps = {
|
||||
|
||||
Reference in New Issue
Block a user