|
1 |
| -import { AdminLayout } from '@sa/materials'; |
2 |
| - |
3 |
| -import './index.scss'; |
| 1 | +import { AdminLayout, LAYOUT_SCROLL_EL_ID } from '@sa/materials'; |
| 2 | +import type { LayoutMode } from '@sa/materials'; |
| 3 | +import { configResponsive } from 'ahooks'; |
4 | 4 | import { Suspense } from 'react';
|
5 | 5 |
|
| 6 | +import './index.scss'; |
6 | 7 | import {
|
7 | 8 | LAYOUT_MODE_HORIZONTAL,
|
8 | 9 | LAYOUT_MODE_HORIZONTAL_MIX,
|
9 | 10 | LAYOUT_MODE_VERTICAL,
|
10 | 11 | LAYOUT_MODE_VERTICAL_MIX
|
11 | 12 | } from '@/constants/common';
|
12 |
| -import { MenuProvider } from '@/features/menu'; |
| 13 | +import { MenuProvider, useMixMenuContext } from '@/features/menu'; |
13 | 14 | import GlobalTab from '@/features/tab/GlobalTab';
|
14 |
| -import { getThemeSettings } from '@/features/theme'; |
15 |
| -import { getSiderCollapse } from '@/layouts/appStore'; |
| 15 | +import { getThemeSettings, setLayoutMode } from '@/features/theme'; |
16 | 16 |
|
| 17 | +import { getFullContent, getMixSiderFixed, getSiderCollapse, setIsMobile, setSiderCollapse } from '../appStore'; |
17 | 18 | import GlobalContent from '../modules/GlobalContent';
|
| 19 | +import GlobalFooter from '../modules/GlobalFooter'; |
18 | 20 | import GlobalSider from '../modules/GlobalSider';
|
19 | 21 | import GlobalHeader from '../modules/global-header/GlobalHeader';
|
20 | 22 | import GlobalMenu from '../modules/global-menu';
|
21 | 23 | import ThemeDrawer from '../modules/theme-drawer';
|
22 | 24 |
|
| 25 | +configResponsive({ sm: 640 }); |
| 26 | + |
23 | 27 | const BaseLayout = () => {
|
| 28 | + const dispatch = useAppDispatch(); |
| 29 | + |
24 | 30 | const themeSettings = useAppSelector(getThemeSettings);
|
25 | 31 |
|
26 | 32 | const siderCollapse = useAppSelector(getSiderCollapse);
|
27 | 33 |
|
| 34 | + const fullContent = useAppSelector(getFullContent); |
| 35 | + |
| 36 | + const responsive = useResponsive(); |
| 37 | + |
| 38 | + const mixSiderFixed = useAppSelector(getMixSiderFixed); |
| 39 | + |
| 40 | + const { childLevelMenus, isActiveFirstLevelMenuHasChildren } = useMixMenuContext(); |
| 41 | + |
28 | 42 | const siderVisible = themeSettings.layout.mode !== LAYOUT_MODE_HORIZONTAL;
|
29 | 43 |
|
30 | 44 | const isVerticalMix = themeSettings.layout.mode === LAYOUT_MODE_VERTICAL_MIX;
|
31 | 45 |
|
32 | 46 | const isHorizontalMix = themeSettings.layout.mode === LAYOUT_MODE_HORIZONTAL_MIX;
|
33 | 47 |
|
| 48 | + const layoutMode = themeSettings.layout.mode.includes(LAYOUT_MODE_VERTICAL) |
| 49 | + ? LAYOUT_MODE_VERTICAL |
| 50 | + : LAYOUT_MODE_HORIZONTAL; |
| 51 | + |
| 52 | + const isMobile = !responsive.sm; |
| 53 | + |
| 54 | + function getSiderWidth() { |
| 55 | + const { reverseHorizontalMix } = themeSettings.layout; |
| 56 | + |
| 57 | + const { mixChildMenuWidth, mixWidth, width } = themeSettings.sider; |
| 58 | + |
| 59 | + if (isHorizontalMix && reverseHorizontalMix) { |
| 60 | + return isActiveFirstLevelMenuHasChildren ? width : 0; |
| 61 | + } |
| 62 | + |
| 63 | + let w = isVerticalMix || isHorizontalMix ? mixWidth : width; |
| 64 | + |
| 65 | + if (isVerticalMix && mixSiderFixed && childLevelMenus.length) { |
| 66 | + w += mixChildMenuWidth; |
| 67 | + } |
| 68 | + |
| 69 | + return w; |
| 70 | + } |
| 71 | + |
| 72 | + const siderWidth = getSiderWidth(); |
| 73 | + |
| 74 | + function getSiderCollapsedWidth() { |
| 75 | + const { reverseHorizontalMix } = themeSettings.layout; |
| 76 | + const { collapsedWidth, mixChildMenuWidth, mixCollapsedWidth } = themeSettings.sider; |
| 77 | + |
| 78 | + if (isHorizontalMix && reverseHorizontalMix) { |
| 79 | + return isActiveFirstLevelMenuHasChildren ? collapsedWidth : 0; |
| 80 | + } |
| 81 | + |
| 82 | + let w = isVerticalMix || isHorizontalMix ? mixCollapsedWidth : collapsedWidth; |
| 83 | + |
| 84 | + if (isVerticalMix && mixSiderFixed && childLevelMenus.length) { |
| 85 | + w += mixChildMenuWidth; |
| 86 | + } |
| 87 | + |
| 88 | + return w; |
| 89 | + } |
| 90 | + const siderCollapsedWidth = getSiderCollapsedWidth(); |
| 91 | + |
| 92 | + function updateSiderCollapse() { |
| 93 | + dispatch(setSiderCollapse(true)); |
| 94 | + } |
| 95 | + |
| 96 | + useLayoutEffect(() => { |
| 97 | + dispatch(setIsMobile(isMobile)); |
| 98 | + if (isMobile) { |
| 99 | + dispatch(setLayoutMode('vertical')); |
| 100 | + } |
| 101 | + }, [isMobile, dispatch]); |
| 102 | + |
34 | 103 | return (
|
35 | 104 | <MenuProvider>
|
36 | 105 | <AdminLayout
|
| 106 | + fixedFooter={themeSettings.footer.fixed} |
| 107 | + fixedTop={themeSettings.fixedHeaderAndTab} |
| 108 | + Footer={<GlobalFooter />} |
| 109 | + footerHeight={themeSettings.footer.height} |
| 110 | + footerVisible={themeSettings.footer.visible} |
| 111 | + fullContent={fullContent} |
| 112 | + headerHeight={themeSettings.header.height} |
| 113 | + isMobile={isMobile} |
| 114 | + mode={layoutMode as LayoutMode} |
| 115 | + rightFooter={themeSettings.footer.right} |
| 116 | + scrollElId={LAYOUT_SCROLL_EL_ID} |
37 | 117 | scrollMode={themeSettings.layout.scrollMode}
|
38 | 118 | siderCollapse={siderCollapse}
|
| 119 | + siderCollapsedWidth={siderCollapsedWidth} |
| 120 | + siderVisible={siderVisible} |
| 121 | + siderWidth={siderWidth} |
39 | 122 | Tab={<GlobalTab />}
|
| 123 | + tabHeight={themeSettings.tab.height} |
| 124 | + tabVisible={themeSettings.tab.visible} |
| 125 | + updateSiderCollapse={updateSiderCollapse} |
40 | 126 | Header={
|
41 | 127 | <GlobalHeader
|
| 128 | + isMobile={isMobile} |
42 | 129 | mode={themeSettings.layout.mode}
|
43 | 130 | reverse={themeSettings.layout.reverseHorizontalMix}
|
44 | 131 | siderWidth={themeSettings.sider.width}
|
|
0 commit comments