-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(projects): refactor part of the menu code
- Loading branch information
Showing
20 changed files
with
356 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { MenuProps } from 'antd'; | ||
import { createPortal } from 'react-dom'; | ||
import { GLOBAL_HEADER_MENU_ID, GLOBAL_SIDER_MENU_ID } from '@/constants/app'; | ||
import VerticalMixMenu from './modules/VerticalMixMenu'; | ||
import HorizontalMenu from './modules/HorizontalMenu'; | ||
import HorizontalMixMenu from './modules/HorizontalMixMenu'; | ||
|
||
interface Props { | ||
mode: UnionKey.ThemeLayoutMode; | ||
menus: MenuProps['items']; | ||
} | ||
|
||
const headerContainer = document.getElementById(GLOBAL_HEADER_MENU_ID); | ||
|
||
const siderContainer = document.getElementById(GLOBAL_SIDER_MENU_ID); | ||
|
||
const GlobalMenu: FC<Props> = memo(({ mode, menus }) => { | ||
if (!headerContainer || !siderContainer) return null; | ||
|
||
const componentsMap = { | ||
vertical: createPortal(<VerticalMixMenu menus={menus} />, siderContainer), | ||
'vertical-mix': <VerticalMixMenu menus={menus} />, | ||
horizontal: createPortal(<HorizontalMenu />, headerContainer), | ||
'horizontal-mix': <HorizontalMixMenu /> | ||
}; | ||
|
||
return componentsMap[mode]; | ||
}); | ||
|
||
export default GlobalMenu; |
45 changes: 45 additions & 0 deletions
45
src/layouts/modules/global-menu/modules/HorizontalMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import {useRoute} from '@sa/simple-router' | ||
import type {RouteLocationNormalizedLoaded} from '@sa/simple-router' | ||
import type { MenuInfo } from 'rc-menu/lib/interface'; | ||
import { headerContainer } from './shared'; | ||
import {useRouterPush} from '@/hooks/common/routerPush' | ||
|
||
|
||
|
||
const HorizontalMenu = () => { | ||
if (!headerContainer) return null; | ||
|
||
const route = useRoute(); | ||
|
||
console.log(route); | ||
|
||
|
||
const menus = useMenu(); | ||
|
||
const router = useRouterPush(); | ||
function getSelectKey(route:RouteLocationNormalizedLoaded) { | ||
const { hideInMenu, activeMenu } = route.meta; | ||
const name = route.name as string; | ||
|
||
const routeName = (hideInMenu ? activeMenu : name) || name; | ||
|
||
return [routeName]; | ||
}; | ||
|
||
const selectKey=getSelectKey(route) | ||
|
||
function handleClickMenu(menuInfo: MenuInfo) { | ||
router.menuPush(menuInfo.key); | ||
} | ||
|
||
|
||
return <AMenu | ||
mode='horizontal' | ||
items={menus} | ||
inlineIndent={18} | ||
onSelect={handleClickMenu} | ||
selectedKeys={selectKey} | ||
/>; | ||
}; | ||
|
||
export default HorizontalMenu; |
Oops, something went wrong.