Files
fe_service_ebtp_frontend/src/layouts/CosMenTabsLayout.tsx
2022-03-10 14:24:13 +08:00

72 lines
1.5 KiB
TypeScript

import React, { useEffect, useMemo, useRef } from 'react';
import { Link } from 'umi';
import { Result, Button } from 'antd';
import Authorized from '@/utils/Authorized';
import { getMatchMenu } from '@umijs/route-utils';
import BiddingRoom from '../components/BiddingRoom';
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 menuDataRender = (menuList: MenuDataItem[]): MenuDataItem[] =>
menuList.map((item) => {
const localItem = {
...item,
children: item.children ? menuDataRender(item.children) : undefined,
};
return Authorized.check(item.authority, localItem, null) as MenuDataItem;
});
const CosMenTabsLayout: React.FC<BasicLayoutProps> = (props) => {
const {
dispatch,
children,
location = {
pathname: '/',
},
} = props;
const menuDataRef = useRef<MenuDataItem[]>([]);
// useEffect(() => {
// if (dispatch) {
// dispatch({
// type: 'user/fetchCurrent',
// });
// }
// }, []);
const authorized = useMemo(
() =>
getMatchMenu(location.pathname || '/', menuDataRef.current).pop() || {
authority: undefined,
},
[location.pathname],
);
return (
<Authorized authority={authorized!.authority} noMatch={noMatch}>
<BiddingRoom />
{children}
</Authorized>
);
};
export default CosMenTabsLayout;