You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.9 KiB

11 months ago
11 months ago
  1. import React from 'react'
  2. import { PageContainer, PageContainerProps } from '@ant-design/pro-components'
  3. import { Flexbox } from 'react-layout-kit'
  4. import { DraggablePanel, DraggablePanelProps } from '@/components/draggable-panel'
  5. import { useStyle } from './style'
  6. import { useAtom } from 'jotai/index'
  7. import { currentMenuAtom } from '@/store/system.ts'
  8. import useResizeObserver from '@/hooks/useResizeObserver.ts'
  9. import useInlineStyle from '@/hooks/useInlineStyle.ts'
  10. import { useNavigate } from '@tanstack/react-router'
  11. import { Space } from 'antd'
  12. import { ArrowLeftOutlined } from '@ant-design/icons'
  13. interface ITreePageLayoutProps {
  14. children?: React.ReactNode
  15. draggableProps?: DraggablePanelProps
  16. pageProps?: PageContainerProps
  17. leftPanel?: React.ReactNode
  18. className?: string
  19. }
  20. export const TwoColPageLayout: React.FC<ITreePageLayoutProps> = ({ className, ...props }) => {
  21. const { styles, cx } = useStyle({ className: 'two-col' })
  22. const navigate = useNavigate()
  23. const [ currentMenu, setCurrentMenu ] = useAtom(currentMenuAtom)
  24. const [ , headerSize ] = useResizeObserver({
  25. selector: '.ant-page-header',
  26. })
  27. useInlineStyle({
  28. styles: {
  29. '--pageHeader': `${headerSize.blockSize}px`,
  30. },
  31. selector: `.two-col`,
  32. })
  33. return (
  34. <PageContainer
  35. breadcrumbRender={false}
  36. title={
  37. <Space>
  38. {
  39. currentMenu?.parent && <span className={'black'}
  40. onClick={() => {
  41. navigate({
  42. to: currentMenu?.parent?.path,
  43. }).then(() => {
  44. setCurrentMenu(currentMenu.parent!)
  45. })
  46. }}> <ArrowLeftOutlined/></span>
  47. }
  48. <span>{currentMenu?.title}</span>
  49. </Space>
  50. }
  51. className={cx(styles.container, styles.pageCard, styles.layoutTable, className)}
  52. {...props.pageProps}
  53. >
  54. <Flexbox horizontal className={styles.authHeight}>
  55. <DraggablePanel expandable={false}
  56. placement="left"
  57. defaultSize={{ width: 300 }}
  58. maxWidth={500}
  59. style={{ position: 'relative' }}
  60. {...props.draggableProps}
  61. >
  62. {props.leftPanel}
  63. </DraggablePanel>
  64. <Flexbox className={styles.box}>
  65. {props.children}
  66. </Flexbox>
  67. </Flexbox>
  68. </PageContainer>
  69. )
  70. }
  71. export default TwoColPageLayout