|
@@ -8,20 +8,31 @@ import {DownOutlined} from "@ant-design/icons";
|
|
import {ModifyPassword} from "../user/components/password";
|
|
import {ModifyPassword} from "../user/components/password";
|
|
import {LogoutComponent} from "../user/components/logout";
|
|
import {LogoutComponent} from "../user/components/logout";
|
|
import {UserInfoDialog} from "../user/info";
|
|
import {UserInfoDialog} from "../user/info";
|
|
-import {useMicroApps, useNavList} from "../../routes/hooks.ts";
|
|
|
|
|
|
+import HomeIcon from '../../assets/ic_home.png'
|
|
|
|
+import {Fullscreen} from "../../components/fullscreen";
|
|
|
|
+import {ItemType} from "antd/es/menu/hooks/useItems";
|
|
|
|
+import {Settings} from "../../api/settings.ts";
|
|
|
|
|
|
const BreadcrumbItem = Breadcrumb.Item
|
|
const BreadcrumbItem = Breadcrumb.Item
|
|
|
|
|
|
const {Header, Content} = Layout;
|
|
const {Header, Content} = Layout;
|
|
|
|
|
|
|
|
|
|
|
|
+type INavList = ItemType & {
|
|
|
|
+ data: Settings.Route
|
|
|
|
+ key: string
|
|
|
|
+ label: string
|
|
|
|
+ path: string
|
|
|
|
+}
|
|
|
|
+
|
|
export const MainLayout = () => {
|
|
export const MainLayout = () => {
|
|
|
|
|
|
- const _navList = useNavList()
|
|
|
|
- const microApps = useMicroApps()
|
|
|
|
- const [nav, setNav] = useState('')
|
|
|
|
|
|
+ const _navList = useAppSelector(state => state.user.navList)
|
|
|
|
+ const [nav, setNav] = useState<INavList>()
|
|
const navigate = useNavigate()
|
|
const navigate = useNavigate()
|
|
|
|
|
|
|
|
+ const fullScreen = useAppSelector(state => state.settings.fullScreen)
|
|
|
|
+
|
|
const matches = useMatches()
|
|
const matches = useMatches()
|
|
const user = useAppSelector(state => state.user.user)
|
|
const user = useAppSelector(state => state.user.user)
|
|
|
|
|
|
@@ -31,38 +42,52 @@ export const MainLayout = () => {
|
|
|
|
|
|
|
|
|
|
const navList = useMemo(() => {
|
|
const navList = useMemo(() => {
|
|
- return _navList.concat(microApps.map(item => {
|
|
|
|
|
|
+ return _navList.map(item => {
|
|
return {
|
|
return {
|
|
|
|
+ key: item.id,
|
|
label: item.title,
|
|
label: item.title,
|
|
- key: `micro/${item.name}`,
|
|
|
|
- roles: []
|
|
|
|
- }
|
|
|
|
- }))
|
|
|
|
- }, [_navList, microApps])
|
|
|
|
-
|
|
|
|
- const handleSetNav = (key: string) => {
|
|
|
|
- setNav(key)
|
|
|
|
- navigate(key)
|
|
|
|
- console.log('handleSetNav', key)
|
|
|
|
|
|
+ data: item,
|
|
|
|
+ path: item.navLink || item.path
|
|
|
|
+ } as INavList
|
|
|
|
+ })
|
|
|
|
+ }, [_navList])
|
|
|
|
+
|
|
|
|
+ const handleSetNav = ( menu: INavList) => {
|
|
|
|
+ if (!menu.data){
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if (menu.data.target == 'TARGET'){
|
|
|
|
+ window.open(menu.data.path)
|
|
|
|
+ }else if (menu.data.target == 'APP'){
|
|
|
|
+ setNav(menu)
|
|
|
|
+ navigate(`app/${menu.key}`)
|
|
|
|
+ }else {
|
|
|
|
+ setNav(menu)
|
|
|
|
+ navigate(menu.path)
|
|
|
|
+ }
|
|
|
|
+ console.log('handleSetNav', menu)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const handleMenuClick = (key: string) => {
|
|
|
|
+ const nav = navList.find(item=>item.key == key);
|
|
|
|
+ if (nav){
|
|
|
|
+ handleSetNav(nav)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
- if (nav || !matches.length){
|
|
|
|
|
|
+ if (nav || !matches.length) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
const first = matches[0]
|
|
const first = matches[0]
|
|
- const active = navList.find(item=>item.key == first.pathname);
|
|
|
|
- if (active){
|
|
|
|
- handleSetNav(active.key)
|
|
|
|
- }else if (navList.length){
|
|
|
|
- handleSetNav(navList[0].key)
|
|
|
|
|
|
+ const active = navList.find(item => item.key == first.pathname);
|
|
|
|
+ if (active) {
|
|
|
|
+ handleSetNav(active)
|
|
|
|
+ } else if (navList.length) {
|
|
|
|
+ handleSetNav(navList[0])
|
|
}
|
|
}
|
|
}, [matches, nav, navList]);
|
|
}, [matches, nav, navList]);
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
const personMenus = useMemo(() => {
|
|
const personMenus = useMemo(() => {
|
|
const items: MenuProps['items'] = [
|
|
const items: MenuProps['items'] = [
|
|
{
|
|
{
|
|
@@ -88,19 +113,21 @@ export const MainLayout = () => {
|
|
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
- <Layout className="customLayout">
|
|
|
|
|
|
+ <Layout className={`customLayout ${fullScreen ? 'fullScreen' : 'nonFullScreen'}`}>
|
|
<Header style={{display: 'flex', alignItems: 'center'}}>
|
|
<Header style={{display: 'flex', alignItems: 'center'}}>
|
|
- <div className="demo-logo"/>
|
|
|
|
|
|
+ <div className="demo-logo">
|
|
|
|
+ <img className="home-icon" src={HomeIcon} alt="logo"/>
|
|
|
|
+ </div>
|
|
<Menu
|
|
<Menu
|
|
theme="dark"
|
|
theme="dark"
|
|
mode="horizontal"
|
|
mode="horizontal"
|
|
- selectedKeys={[nav]}
|
|
|
|
- activeKey={nav}
|
|
|
|
|
|
+ selectedKeys={nav ? [nav.key]: undefined}
|
|
|
|
+ activeKey={nav?.key}
|
|
items={navList}
|
|
items={navList}
|
|
style={{flex: 1, minWidth: 0}}
|
|
style={{flex: 1, minWidth: 0}}
|
|
- onClick={event => handleSetNav(event.key)}
|
|
|
|
|
|
+ onClick={event => handleMenuClick(event.key)}
|
|
/>
|
|
/>
|
|
- <div style={{flex: 1}}/>
|
|
|
|
|
|
+ <Fullscreen/>
|
|
<Dropdown menu={personMenus}>
|
|
<Dropdown menu={personMenus}>
|
|
<a onClick={e => e.preventDefault()}>
|
|
<a onClick={e => e.preventDefault()}>
|
|
<Space style={{color: '#3f94e4'}}>
|
|
<Space style={{color: '#3f94e4'}}>
|