chen.lin
昨天 7e5973a3061989a976e2c19ef588bb2f34f29cf4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { createPortal } from 'react-dom';
import { Layout as RALayout, CheckForApplicationUpdate, useSidebarState } from "react-admin";
import AppBar from './AppBar';
import { MyMenu } from './MyMenu';
import TabsBar from './TabsBar';
import { Box } from '@mui/material';
 
const LayoutContent = ({ children }) => {
  const [sidebarIsOpen] = useSidebarState();
  const sidebarWidth = sidebarIsOpen ? 200 : 50;
 
  const tabsBarEl = (
    <Box sx={{
      position: 'fixed',
      top: 48,
      left: sidebarWidth + 5,
      right: 0,
      zIndex: 1400, // 高于 Dialog/Modal(1300),通过 Portal 挂到 body 才能盖住弹窗
      transition: (theme) =>
        theme.transitions.create('left', {
          easing: theme.transitions.easing.sharp,
          duration: theme.transitions.duration.leavingScreen,
        }),
    }}>
      <TabsBar />
    </Box>
  );
 
  return (
    <RALayout
      appBar={AppBar}
      menu={MyMenu}
      sx={{
        '& .RaLayout-content': {
          position: 'absolute',
          left: `${sidebarWidth}px`,
          overflowY: 'auto',
          width: `calc(100% - ${sidebarWidth}px)`,
          height: 'calc(100% - 86px)', // 减去TabsBar的高度 (50px AppBar + 36px TabsBar)
          top: '86px',
          transition: (theme) =>
            theme.transitions.create(['left', 'width'], {
              easing: theme.transitions.easing.sharp,
              duration: theme.transitions.duration.leavingScreen,
            }),
        }
      }}
    >
      {createPortal(tabsBarEl, document.body)}
      {children}
      <CheckForApplicationUpdate />
    </RALayout>
  );
};
 
export const Layout = ({ children }) => (
  <LayoutContent>{children}</LayoutContent>
);