多媒体信息发布平台
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.

82 lines
2.2 KiB

3 years ago
  1. <template>
  2. <div v-if="!item.hidden" class="menu-wrapper">
  3. <template v-if="hasOneShowingChild(item.children, item) && (!onlyOneChild.children || onlyOneChild.noShowingChildren) && !item.alwaysShow">
  4. <app-link v-if="onlyOneChild.meta" :to="resolvePath(onlyOneChild.path)">
  5. <el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{ 'submenu-title-noDropdown': !isNest }">
  6. <item :icon="onlyOneChild.meta.icon || (item.meta && item.meta.icon)" :title="onlyOneChild.meta.title" />
  7. </el-menu-item>
  8. </app-link>
  9. </template>
  10. <el-submenu v-else ref="subMenu" :index="resolvePath(item.path)" popper-append-to-body>
  11. <template slot="title">
  12. <item v-if="item.meta" :icon="item.meta && item.meta.icon" :title="item.meta.title" />
  13. </template>
  14. <sidebar-item v-for="child in item.children" :key="child.path" :is-nest="true" :item="child" :base-path="resolvePath(child.path)" class="nest-menu" />
  15. </el-submenu>
  16. </div>
  17. </template>
  18. <script>
  19. import path from 'path'
  20. import { isExternal } from '@/utils/validate'
  21. import Item from './Item'
  22. import AppLink from './Link'
  23. import FixiOSBug from './FixiOSBug'
  24. export default {
  25. name: 'SidebarItem',
  26. components: { Item, AppLink },
  27. mixins: [FixiOSBug],
  28. props: {
  29. // route object
  30. item: {
  31. type: Object,
  32. required: true
  33. },
  34. isNest: {
  35. type: Boolean,
  36. default: false
  37. },
  38. basePath: {
  39. type: String,
  40. default: ''
  41. }
  42. },
  43. data() {
  44. this.onlyOneChild = null
  45. return {}
  46. },
  47. methods: {
  48. hasOneShowingChild(children = [], parent) {
  49. const showingChildren = children.filter((item) => {
  50. if (item.hidden) {
  51. return false
  52. } else {
  53. this.onlyOneChild = item
  54. return true
  55. }
  56. })
  57. if (showingChildren.length === 1) {
  58. return true
  59. }
  60. if (showingChildren.length === 0) {
  61. this.onlyOneChild = { ...parent, path: '', noShowingChildren: true }
  62. return true
  63. }
  64. return false
  65. },
  66. resolvePath(routePath) {
  67. if (isExternal(routePath)) {
  68. return routePath
  69. }
  70. if (isExternal(this.basePath)) {
  71. return this.basePath
  72. }
  73. return path.resolve(this.basePath, routePath)
  74. }
  75. }
  76. }
  77. </script>