当前位置:   article > 正文

React+Ant Design左侧二级导航菜单_antdesign左侧菜单在哪个文件

antdesign左侧菜单在哪个文件

package.json:

  1. {
  2. "name": "antd-demo",
  3. "version": "0.1.0",
  4. "private": true,
  5. "dependencies": {
  6. "@ant-design/icons": "^4.2.1",
  7. "@babel/core": "7.9.0",
  8. "@svgr/webpack": "4.3.3",
  9. "@testing-library/jest-dom": "^4.2.4",
  10. "@testing-library/react": "^9.3.2",
  11. "@testing-library/user-event": "^7.1.2",
  12. "@typescript-eslint/eslint-plugin": "^2.10.0",
  13. "@typescript-eslint/parser": "^2.10.0",
  14. "antd": "^4.7.0",
  15. "axios": "^0.19.2",
  16. "babel-eslint": "10.1.0",
  17. "babel-jest": "^24.9.0",
  18. "babel-loader": "8.1.0",
  19. "babel-plugin-import": "^1.13.0",
  20. "babel-plugin-named-asset-import": "^0.3.6",
  21. "babel-preset-react-app": "^9.1.2",
  22. "camelcase": "^5.3.1",
  23. "case-sensitive-paths-webpack-plugin": "2.3.0",
  24. "css-loader": "3.4.2",
  25. "dotenv": "8.2.0",
  26. "dotenv-expand": "5.1.0",
  27. "echarts": "^4.9.0",
  28. "echarts-for-react": "^2.0.16",
  29. "eslint": "^6.6.0",
  30. "eslint-config-react-app": "^5.2.1",
  31. "eslint-loader": "3.0.3",
  32. "eslint-plugin-flowtype": "4.6.0",
  33. "eslint-plugin-import": "2.20.1",
  34. "eslint-plugin-jsx-a11y": "6.2.3",
  35. "eslint-plugin-react": "7.19.0",
  36. "eslint-plugin-react-hooks": "^1.6.1",
  37. "file-loader": "4.3.0",
  38. "fs-extra": "^8.1.0",
  39. "html-webpack-plugin": "4.0.0-beta.11",
  40. "identity-obj-proxy": "3.0.0",
  41. "jest": "24.9.0",
  42. "jest-environment-jsdom-fourteen": "1.0.1",
  43. "jest-resolve": "24.9.0",
  44. "jest-watch-typeahead": "0.4.2",
  45. "mini-css-extract-plugin": "0.9.0",
  46. "optimize-css-assets-webpack-plugin": "5.0.3",
  47. "pnp-webpack-plugin": "1.6.4",
  48. "postcss-flexbugs-fixes": "4.1.0",
  49. "postcss-loader": "3.0.0",
  50. "postcss-normalize": "8.0.1",
  51. "postcss-preset-env": "6.7.0",
  52. "postcss-safe-parser": "4.0.1",
  53. "react": "^16.13.1",
  54. "react-app-polyfill": "^1.0.6",
  55. "react-dev-utils": "^10.2.1",
  56. "react-dom": "^16.13.1",
  57. "react-router": "^4.2.0",
  58. "react-router-dom": "^4.2.0",
  59. "react-transition-group": "^4.4.1",
  60. "redux": "^4.0.5",
  61. "resolve": "1.15.0",
  62. "resolve-url-loader": "3.1.1",
  63. "sass-loader": "8.0.2",
  64. "semver": "6.3.0",
  65. "style-loader": "0.23.1",
  66. "terser-webpack-plugin": "2.3.5",
  67. "ts-pnp": "1.1.6",
  68. "url-loader": "2.3.0",
  69. "webpack": "4.42.0",
  70. "webpack-dev-server": "3.10.3",
  71. "webpack-manifest-plugin": "2.2.0",
  72. "workbox-webpack-plugin": "4.3.1"
  73. },
  74. "scripts": {
  75. "start": "node scripts/start.js",
  76. "build": "node scripts/build.js",
  77. "test": "node scripts/test.js"
  78. },
  79. "eslintConfig": {
  80. "extends": "react-app"
  81. },
  82. "proxy": "http://localhost:9999",
  83. "homepage": ".",
  84. "browserslist": {
  85. "production": [
  86. ">0.2%",
  87. "not dead",
  88. "not op_mini all"
  89. ],
  90. "development": [
  91. "last 1 chrome version",
  92. "last 1 firefox version",
  93. "last 1 safari version"
  94. ]
  95. },
  96. "jest": {
  97. "roots": [
  98. "<rootDir>/src"
  99. ],
  100. "collectCoverageFrom": [
  101. "src/**/*.{js,jsx,ts,tsx}",
  102. "!src/**/*.d.ts"
  103. ],
  104. "setupFiles": [
  105. "react-app-polyfill/jsdom"
  106. ],
  107. "setupFilesAfterEnv": [
  108. "<rootDir>/src/setupTests.js"
  109. ],
  110. "testMatch": [
  111. "<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
  112. "<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}"
  113. ],
  114. "testEnvironment": "jest-environment-jsdom-fourteen",
  115. "transform": {
  116. "^.+\\.(js|jsx|ts|tsx)$": "<rootDir>/node_modules/babel-jest",
  117. "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
  118. "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
  119. },
  120. "transformIgnorePatterns": [
  121. "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$",
  122. "^.+\\.module\\.(css|sass|scss)$"
  123. ],
  124. "modulePaths": [],
  125. "moduleNameMapper": {
  126. "^react-native$": "react-native-web",
  127. "^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy"
  128. },
  129. "moduleFileExtensions": [
  130. "web.js",
  131. "js",
  132. "web.ts",
  133. "ts",
  134. "web.tsx",
  135. "tsx",
  136. "json",
  137. "web.jsx",
  138. "jsx",
  139. "node"
  140. ],
  141. "watchPlugins": [
  142. "jest-watch-typeahead/filename",
  143. "jest-watch-typeahead/testname"
  144. ]
  145. },
  146. "devDependencies": {
  147. "less": "^3.12.2",
  148. "less-loader": "^6.2.0"
  149. }
  150. }

config/route-config.js(菜单配置文件):

  1. import { SnippetsFilled, PieChartFilled, PieChartOutlined, ProfileOutlined, FileWordOutlined, FileTextOutlined , BarChartOutlined, WhatsAppOutlined, ExclamationCircleOutlined, IeOutlined, SketchOutlined } from '@ant-design/icons';
  2. const MenuList = [
  3. {
  4. title: '首页', // 菜单标题名称
  5. key: '/home', // 对应的path
  6. icon: SnippetsFilled, // 图标名称,
  7. children: [ // 子菜单列表
  8. {
  9. title: '监控页',
  10. key: '/monitor',
  11. icon: 'bars'
  12. },
  13. {
  14. title: '分析页',
  15. key: '/home',
  16. icon: 'bars'
  17. },
  18. {
  19. title: '工作台',
  20. key: '/workbench',
  21. icon: 'bars'
  22. }
  23. ]
  24. },
  25. {
  26. title: '数据录入',
  27. key: '/data_input',
  28. icon: PieChartFilled,
  29. children: [ // 子菜单列表
  30. {
  31. title: 'form',
  32. key: '/form',
  33. icon: 'bars'
  34. }
  35. ]
  36. },
  37. {
  38. title: '数据展示',
  39. key: '/data_show',
  40. icon: BarChartOutlined,
  41. children: [
  42. {
  43. title: 'table',
  44. key: '/table',
  45. icon: 'bar-chart'
  46. },
  47. {
  48. title: 'timeline ',
  49. key: '/timeline',
  50. icon: 'line-chart'
  51. },
  52. {
  53. title: 'descriptions ',
  54. key: '/descriptions',
  55. icon: 'line-chart'
  56. }
  57. ]
  58. },
  59. {
  60. title: '反馈',
  61. key: '/feedback',
  62. icon: WhatsAppOutlined,
  63. children: [
  64. {
  65. title: 'modal',
  66. key: '/modal1',
  67. icon: 'bar-chart'
  68. },
  69. {
  70. title: 'notification',
  71. key: '/notification',
  72. icon: 'line-chart'
  73. }
  74. ]
  75. },
  76. {
  77. title: '图表',
  78. key: '/charts',
  79. icon: PieChartOutlined,
  80. children: [
  81. {
  82. title: 'bar',
  83. key: '/bar',
  84. icon: 'bar-chart'
  85. },
  86. {
  87. title: 'line',
  88. key: '/line',
  89. icon: 'line-chart'
  90. },
  91. {
  92. title: 'pie',
  93. key: '/pie',
  94. icon: 'pie-chart'
  95. }
  96. ]
  97. },
  98. {
  99. title: '异常页',
  100. key: '/abnormal',
  101. icon: ExclamationCircleOutlined,
  102. children: [
  103. {
  104. title: '403',
  105. key: '/403',
  106. icon: 'bar-chart'
  107. },
  108. {
  109. title: '404',
  110. key: '/404',
  111. icon: 'line-chart'
  112. },
  113. {
  114. title: '500',
  115. key: '/500',
  116. icon: 'pie-chart'
  117. }
  118. ]
  119. },
  120. {
  121. title: '表单页',
  122. key: '/form',
  123. icon: FileTextOutlined,
  124. children: [
  125. {
  126. title: '基础表单',
  127. key: '/base-form',
  128. icon: 'bar-chart'
  129. },
  130. {
  131. title: '模态表单',
  132. key: '/modal-form',
  133. icon: 'bar-chart'
  134. },
  135. {
  136. title: '分步表单',
  137. key: '/step-form',
  138. icon: 'line-chart'
  139. },
  140. {
  141. title: '高级表单',
  142. key: '/advanced-form',
  143. icon: 'pie-chart'
  144. }
  145. ]
  146. },
  147. {
  148. title: '列表页',
  149. key: '/list',
  150. icon: ProfileOutlined,
  151. children: [
  152. {
  153. title: '搜索列表',
  154. key: '/search-list',
  155. icon: 'bar-chart'
  156. },
  157. {
  158. title: '查询表格',
  159. key: '/query-table',
  160. icon: 'line-chart'
  161. },
  162. {
  163. title: '标准列表',
  164. key: '/standard-list',
  165. icon: 'pie-chart'
  166. },
  167. {
  168. title: '卡片列表',
  169. key: '/card-list',
  170. icon: 'pie-chart'
  171. },
  172. {
  173. title: '树列表',
  174. key: '/tree-list',
  175. icon: 'pie-chart'
  176. }
  177. ]
  178. },
  179. {
  180. title: '详情页',
  181. key: '/detail',
  182. icon: FileWordOutlined,
  183. children: [
  184. {
  185. title: '基础详情页',
  186. key: '/base-detail',
  187. icon: 'bar-chart'
  188. },
  189. {
  190. title: '高级详情页',
  191. key: '/senior-detail',
  192. icon: 'line-chart'
  193. }
  194. ]
  195. },
  196. {
  197. title: '网盘',
  198. key: '/webdisk',
  199. icon: IeOutlined,
  200. children: [
  201. {
  202. title: '管理员管理',
  203. key: '/administrator',
  204. icon: 'bar-chart'
  205. },
  206. {
  207. title: '审计日志管理',
  208. key: '/log',
  209. icon: 'line-chart'
  210. },
  211. {
  212. title: '收到的共享',
  213. key: '/myshare',
  214. icon: 'line-chart'
  215. },
  216. {
  217. title: 'USBKEY',
  218. key: '/usbkey',
  219. icon: 'line-chart'
  220. }
  221. ]
  222. },
  223. {
  224. title: '加固',
  225. key: '/firmstor',
  226. icon: SketchOutlined,
  227. children: [
  228. {
  229. title: '基本信息',
  230. key: '/baseinfo',
  231. icon: 'bar-chart'
  232. },
  233. {
  234. title: '保险箱文件恢复',
  235. key: '/file-recovery',
  236. icon: 'bar-chart'
  237. }
  238. ]
  239. }
  240. ]
  241. export default MenuList

left-nav.jsx:

  1. import React, { Component } from 'react'
  2. import { Menu } from 'antd';
  3. import { Link, withRouter } from 'react-router-dom'
  4. import MenuList from '../../config/route-config'
  5. import './index.less'
  6. const { SubMenu } = Menu;
  7. class LeftNav extends Component {
  8. state = {
  9. rootSubmenuKeys: [], //只展开当前父级菜单
  10. openKeys: [], // 默认展开的菜单项
  11. };
  12. // 只展开当前父级菜单
  13. onOpenChange = openKeys => {
  14. const latestOpenKey = openKeys.find(key => this.state.openKeys.indexOf(key) === -1);
  15. if (this.state.rootSubmenuKeys.indexOf(latestOpenKey) === -1) {
  16. this.setState({ openKeys });
  17. } else {
  18. this.setState({
  19. openKeys: latestOpenKey ? [latestOpenKey] : [],
  20. });
  21. }
  22. };
  23. // 获取左侧菜单
  24. getMenuNodes = MenuList => {
  25. const path = this.props.location.pathname;
  26. return MenuList.map(item => {
  27. if (!item.children) {
  28. return (
  29. <Menu.Item key={item.key} icon={<item.icon />}>
  30. <Link to={item.key}>
  31. <span>{item.title}</span>
  32. </Link>
  33. </Menu.Item>
  34. )
  35. } else {
  36. this.state.rootSubmenuKeys.push(item.key);
  37. // 查找一个与当前请求路径匹配的子Item
  38. const childItem = item.children.find(cItem => path.indexOf(cItem.key) === 0);
  39. // 如果存在, 说明当前item的子列表需要打开
  40. if (childItem) {
  41. this.setState({
  42. openKeys: [item.key]
  43. })
  44. }
  45. return (
  46. <SubMenu
  47. key={item.key}
  48. icon={<item.icon />}
  49. title={item.title}
  50. >
  51. {this.getMenuNodes(item.children)}
  52. </SubMenu>
  53. )
  54. }
  55. })
  56. }
  57. componentWillMount() {
  58. this.menuNodes = this.getMenuNodes(MenuList);
  59. }
  60. render() {
  61. /*selectedKeys:控制默认高亮菜单项,defaultOpenKeys、openKeys、onOpenChange:控制菜单展开*/
  62. return (
  63. <Menu
  64. theme="dark"
  65. mode="inline"
  66. selectedKeys={this.props.location.pathname}
  67. defaultOpenKeys={this.state.openKeys}
  68. openKeys={this.state.openKeys}
  69. onOpenChange={this.onOpenChange}
  70. style={{ height: '100%', borderRight: 0, paddingTop: '60px' }}
  71. >
  72. {
  73. this.menuNodes
  74. }
  75. </Menu>
  76. )
  77. }
  78. }
  79. export default withRouter(LeftNav)

index.less:

  1. .ant-menu {
  2. overflow: auto!important;
  3. }
  4. .ant-menu::-webkit-scrollbar {
  5. /*滚动条整体样式*/
  6. width : 5px; /*高宽分别对应横竖滚动条的尺寸*/
  7. height: 1px;
  8. }
  9. .ant-menu::-webkit-scrollbar-thumb {
  10. /*滚动条里面小方块*/
  11. border-radius: 10px;
  12. box-shadow : inset 0 0 5px rgba(0, 0, 0, 0.2);
  13. background : #535353;
  14. }
  15. .ant-menu::-webkit-scrollbar-track {
  16. /*滚动条里面轨道*/
  17. box-shadow : inset 0 0 5px rgba(0, 0, 0, 0.2);
  18. border-radius: 10px;
  19. background : #ededed;
  20. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/113154
推荐阅读
相关标签
  

闽ICP备14008679号