|
|
@@ -3,33 +3,22 @@
|
|
|
* You can view component api by:
|
|
|
* https://github.com/ant-design/ant-design-pro-layout
|
|
|
*/
|
|
|
-import ProLayout, { DefaultFooter } from '@ant-design/pro-layout'
|
|
|
+import ProLayout from '@ant-design/pro-layout'
|
|
|
import zhCN from 'antd/lib/locale/zh_CN'
|
|
|
-import React, { useEffect, useMemo, useRef } from 'react'
|
|
|
+import React, { useMemo, useRef } from 'react'
|
|
|
import { Link, useIntl, connect, history } from 'umi'
|
|
|
-import { Result, Button, message, ConfigProvider } from 'antd'
|
|
|
+import { Result, ConfigProvider } from 'antd'
|
|
|
import Authorized from '@/utils/Authorized'
|
|
|
import RightContent from '@/components/GlobalHeader/RightContent'
|
|
|
-import { getMatchMenu } from '@umijs/route-utils'
|
|
|
import logo from '../assets/logo.svg'
|
|
|
import styles from './BasicLayout.less'
|
|
|
import '@icon-park/react/styles/index.less'
|
|
|
import { IconPark } from '@/components/SvgIcon'
|
|
|
import BasicModal from '@/components/Modal'
|
|
|
import { BasicDrawer } from '@/components/Modal'
|
|
|
+import { matchPath } from 'umi'
|
|
|
|
|
|
-const noMatch = (
|
|
|
- <Result
|
|
|
- status={403}
|
|
|
- title="403"
|
|
|
- subTitle="Sorry, you are not authorized to access this page."
|
|
|
- extra={
|
|
|
- <Button type="primary">
|
|
|
- <Link to="/user/login">Go Login</Link>
|
|
|
- </Button>
|
|
|
- }
|
|
|
- />
|
|
|
-)
|
|
|
+const noMatch = <Result status={403} title="403" subTitle="抱歉, 您没有权限访问此页面" />
|
|
|
|
|
|
/**
|
|
|
* use Authorized check all menu item
|
|
|
@@ -46,32 +35,6 @@ const menuDataRender = menuList =>
|
|
|
return Authorized.check(item.authority, localItem, null)
|
|
|
})
|
|
|
|
|
|
-// const defaultFooterDom = (
|
|
|
-// <DefaultFooter
|
|
|
-// copyright={`${new Date().getFullYear()} 蚂蚁集团体验技术部出品`}
|
|
|
-// links={[
|
|
|
-// {
|
|
|
-// key: 'Ant Design Pro',
|
|
|
-// title: 'Ant Design Pro',
|
|
|
-// href: 'https://pro.ant.design',
|
|
|
-// blankTarget: true,
|
|
|
-// },
|
|
|
-// {
|
|
|
-// key: 'github',
|
|
|
-// title: <GithubOutlined />,
|
|
|
-// href: 'https://github.com/ant-design/ant-design-pro',
|
|
|
-// blankTarget: true,
|
|
|
-// },
|
|
|
-// {
|
|
|
-// key: 'Ant Design',
|
|
|
-// title: 'Ant Design',
|
|
|
-// href: 'https://ant.design',
|
|
|
-// blankTarget: true,
|
|
|
-// },
|
|
|
-// ]}
|
|
|
-// />
|
|
|
-// );
|
|
|
-
|
|
|
const BasicLayout = props => {
|
|
|
const {
|
|
|
dispatch,
|
|
|
@@ -80,16 +43,17 @@ const BasicLayout = props => {
|
|
|
location = {
|
|
|
pathname: '/',
|
|
|
key: ''
|
|
|
- }
|
|
|
+ },
|
|
|
+ route: routeForAuthorized
|
|
|
} = props
|
|
|
const menuDataRef = useRef([])
|
|
|
- useEffect(() => {
|
|
|
- if (dispatch) {
|
|
|
- dispatch({
|
|
|
- type: 'user/fetchCurrent'
|
|
|
- })
|
|
|
- }
|
|
|
- }, [])
|
|
|
+ // useEffect(() => {
|
|
|
+ // if (dispatch) {
|
|
|
+ // dispatch({
|
|
|
+ // type: 'user/fetchCurrent'
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ // }, [])
|
|
|
/**
|
|
|
* init variables
|
|
|
*/
|
|
|
@@ -103,13 +67,33 @@ const BasicLayout = props => {
|
|
|
}
|
|
|
} // get children authority
|
|
|
|
|
|
- const authorized = useMemo(
|
|
|
- () =>
|
|
|
- getMatchMenu(location.pathname || '/', menuDataRef.current).pop() || {
|
|
|
- authority: undefined
|
|
|
- },
|
|
|
- [location.pathname]
|
|
|
- )
|
|
|
+ // const authorized = useMemo(() => {
|
|
|
+ // return (
|
|
|
+ // getMatchMenu(location.pathname || '/', menuDataRef.current).pop() || {
|
|
|
+ // authority: undefined
|
|
|
+ // }
|
|
|
+ // )
|
|
|
+ // }, [location.pathname])
|
|
|
+
|
|
|
+ const authorized = useMemo(() => {
|
|
|
+ const path = location.pathname
|
|
|
+ // 必然匹配了
|
|
|
+ const list = [routeForAuthorized]
|
|
|
+ let current = routeForAuthorized
|
|
|
+ while (current) {
|
|
|
+ if (!current.children) break
|
|
|
+ current = current.children
|
|
|
+ .filter(it => it.path)
|
|
|
+ .sort((a, b) => b.path.length - a.path.length)
|
|
|
+ .find(it => matchPath(path, it))
|
|
|
+ if (!current) break
|
|
|
+ list.unshift(current)
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ authority: list.map(it => it.authority).find(it => it)
|
|
|
+ }
|
|
|
+ }, [routeForAuthorized, location.pathname])
|
|
|
+
|
|
|
const { formatMessage } = useIntl()
|
|
|
return (
|
|
|
<ProLayout
|
|
|
@@ -148,12 +132,15 @@ const BasicLayout = props => {
|
|
|
menuDataRender={menuDataRender}
|
|
|
rightContentRender={() => <RightContent />}
|
|
|
postMenuData={menuData => {
|
|
|
+ // console.log('menuData', menuData)
|
|
|
menuDataRef.current = menuData || []
|
|
|
return menuData || []
|
|
|
}}>
|
|
|
- <ConfigProvider locale={zhCN}>{children}</ConfigProvider>
|
|
|
- {/* <Authorized authority={authorized.authority} noMatch={noMatch}> */}
|
|
|
- {/* </Authorized> */}
|
|
|
+ <ConfigProvider locale={zhCN}>
|
|
|
+ <Authorized authority={authorized.authority} noMatch={noMatch}>
|
|
|
+ {children}
|
|
|
+ </Authorized>
|
|
|
+ </ConfigProvider>
|
|
|
<BasicDrawer />
|
|
|
<BasicModal />
|
|
|
</ProLayout>
|