ec9acb27926bb89846878e10afc77ea248757524.svn-base 2.8 KB

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