99e11e612d28001be1724bd94cf8f3ef602be44e.svn-base 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. <template v-for="child in item.children">
  15. <sidebar-item
  16. v-if="child.path!='Changpwd' && child.path!='ChartPanel' && child.path!='Addboard' "
  17. :key="child.path"
  18. :is-nest="true"
  19. :item="child"
  20. :base-path="resolvePath(child.path)"
  21. class="nest-menu"
  22. />
  23. </template>
  24. </el-submenu>
  25. </div>
  26. </template>
  27. <script>
  28. import path from 'path'
  29. import { isExternal } from '@/utils/validate'
  30. import Item from './Item'
  31. import AppLink from './Link'
  32. import FixiOSBug from './FixiOSBug'
  33. export default {
  34. name: 'SidebarItem',
  35. components: { Item, AppLink },
  36. mixins: [FixiOSBug],
  37. props: {
  38. // route object
  39. item: {
  40. type: Object,
  41. required: true
  42. },
  43. isNest: {
  44. type: Boolean,
  45. default: false
  46. },
  47. basePath: {
  48. type: String,
  49. default: ''
  50. }
  51. },
  52. data() {
  53. // To fix https://github.com/PanJiaChen/vue-admin-template/issues/237
  54. // TODO: refactor with render function
  55. this.onlyOneChild = null
  56. return {}
  57. },
  58. methods: {
  59. hasOneShowingChild(children = [], parent) {
  60. const showingChildren = children.filter(item => {
  61. if (item.hidden) {
  62. return false
  63. } else {
  64. // Temp set(will be used if only has one showing child)
  65. this.onlyOneChild = item
  66. return true
  67. }
  68. })
  69. // When there is only one child router, the child router is displayed by default
  70. if (showingChildren.length === 1) {
  71. return true
  72. }
  73. // Show parent if there are no child router to display
  74. if (showingChildren.length === 0) {
  75. this.onlyOneChild = { ... parent, path: '', noShowingChildren: true }
  76. return true
  77. }
  78. return false
  79. },
  80. resolvePath(routePath) {
  81. if (isExternal(routePath)) {
  82. return routePath
  83. }
  84. if (isExternal(this.basePath)) {
  85. return this.basePath
  86. }
  87. return path.resolve(this.basePath, routePath)
  88. }
  89. }
  90. }
  91. </script>