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.

150 lines
4.5 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. import PageBreadcrumb from '@/components/breadcrumb'
  2. import ErrorPage from '@/components/error/error.tsx'
  3. import SelectLang from '@/components/select-lang'
  4. import { useTranslation } from '@/i18n.ts'
  5. import { MenuItem } from '@/types'
  6. import { ProConfigProvider, ProLayout, } from '@ant-design/pro-components'
  7. import { CatchBoundary, Link, Outlet, useRouteContext } from '@tanstack/react-router'
  8. import { ConfigProvider, Dropdown } from 'antd'
  9. import { useState } from 'react'
  10. import Icon from '../components/icon'
  11. import defaultProps from './_defaultProps'
  12. //根据menuData生成Breadcrumb所需的数据
  13. const getBreadcrumbData = (menuData: MenuItem[], pathname: string) => {
  14. const breadcrumbData: any[] = []
  15. const findItem = (menuData: any[], pathname: string) => {
  16. for (let i = 0; i < menuData.length; i++) {
  17. if (menuData[i].path === pathname) {
  18. breadcrumbData.push(menuData[i])
  19. return true
  20. }
  21. if (menuData[i].children) {
  22. if (findItem(menuData[i].children, pathname)) {
  23. breadcrumbData.push(menuData[i])
  24. return true
  25. }
  26. }
  27. }
  28. return false
  29. }
  30. findItem(menuData, pathname)
  31. return breadcrumbData.reverse()
  32. }
  33. export default () => {
  34. const { t } = useTranslation()
  35. const { menuData } = useRouteContext({
  36. from: undefined,
  37. strict: false,
  38. select: (state) => state
  39. })
  40. const items = getBreadcrumbData(menuData, location.pathname)
  41. const [ pathname, setPathname ] = useState(location.pathname)
  42. return (
  43. <div
  44. id="crazy-pro-layout"
  45. style={{
  46. height: '100vh',
  47. // overflow: 'auto',
  48. }}
  49. >
  50. <CatchBoundary
  51. getResetKey={() => 'reset-page'}
  52. errorComponent={ErrorPage}
  53. >
  54. <ProConfigProvider hashed={false}>
  55. <ConfigProvider
  56. getTargetContainer={() => {
  57. return document.getElementById('crazy-pro-layout') || document.body
  58. }}
  59. >
  60. <ProLayout
  61. headerContentRender={() => <PageBreadcrumb
  62. className={'top-breadcrumb'}
  63. showIcon={false}
  64. items={items}/>}
  65. title="Crazy Pro"
  66. {...defaultProps}
  67. route={{
  68. path: '/',
  69. routes: menuData
  70. }}
  71. location={{
  72. pathname,
  73. }}
  74. token={{
  75. header: {
  76. colorBgMenuItemSelected: 'rgba(0,0,0,0.04)',
  77. },
  78. }}
  79. menu={{
  80. collapsedShowGroupTitle: true,
  81. }}
  82. avatarProps={{
  83. src: 'https://gw.alipayobjects.com/zos/antfincdn/efFD%24IOql2/weixintupian_20170331104822.jpg',
  84. size: 'small',
  85. title: '管理员',
  86. render: (_, dom) => {
  87. return (
  88. <Dropdown
  89. menu={{
  90. items: [
  91. {
  92. key: 'logout',
  93. icon: <Icon type={'Logout'}/>,
  94. label: t('app.header.logout'),
  95. },
  96. ],
  97. }}
  98. >
  99. {dom}
  100. </Dropdown>
  101. )
  102. },
  103. }}
  104. actionsRender={(props) => {
  105. if (props.isMobile) return []
  106. if (typeof window === 'undefined') return []
  107. return [
  108. <SelectLang/>
  109. ]
  110. }}
  111. menuRender={(_, defaultDom) => (
  112. <>
  113. {defaultDom}
  114. </>
  115. )}
  116. menuItemRender={(item, dom) => {
  117. return <div onClick={() => {
  118. setPathname(item.path || '/welcome')
  119. }}
  120. >
  121. <Link to={item.path} target={item.type === 3 ? '_blank' : '_self'}>
  122. {dom}
  123. </Link>
  124. </div>
  125. }}
  126. {...{
  127. 'layout': 'mix',
  128. 'navTheme': 'light',
  129. 'contentWidth': 'Fluid',
  130. 'fixSiderbar': true,
  131. 'colorPrimary': '#1677FF',
  132. 'siderMenuType': 'group',
  133. // layout: 'side',
  134. }}
  135. >
  136. <Outlet/>
  137. </ProLayout>
  138. </ConfigProvider>
  139. </ProConfigProvider>
  140. </CatchBoundary>
  141. </div>
  142. )
  143. }