8c3796ed921c0a1b05e026d21ca790c6339579cd.svn-base 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. // console.log(item)
  62. if (item.hidden) {
  63. return false
  64. } else {
  65. // Temp set(will be used if only has one showing child)
  66. if (item.name !== 'Changpwd') {
  67. this.onlyOneChild = item
  68. return true
  69. }
  70. }
  71. })
  72. // When there is only one child router, the child router is displayed by default
  73. if (showingChildren.length === 1) {
  74. return true
  75. }
  76. // Show parent if there are no child router to display
  77. if (showingChildren.length === 0) {
  78. this.onlyOneChild = { ... parent, path: '', noShowingChildren: true }
  79. return true
  80. }
  81. return false
  82. },
  83. resolvePath(routePath) {
  84. if (isExternal(routePath)) {
  85. return routePath
  86. }
  87. if (isExternal(this.basePath)) {
  88. return this.basePath
  89. }
  90. return path.resolve(this.basePath, routePath)
  91. }
  92. }
  93. }
  94. </script>