SidebarItem.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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}" :disabled="isBizSelectPage">
  6. <item :icon="onlyOneChild.meta.icon||(item.meta&&item.meta.icon)" :title="onlyOneChild.meta.title" />
  7. <div v-show="onlyOneChild.meta.title === '个人工作台' && showTips" class="if-notice" />
  8. </el-menu-item>
  9. </app-link>
  10. </template>
  11. <el-submenu v-else ref="subMenu" :index="resolvePath(item.path)" popper-append-to-body :disabled="isBizSelectPage">
  12. <template slot="title">
  13. <item v-if="item.meta" :icon="item.meta && item.meta.icon" :title="item.meta.title" />
  14. </template>
  15. <sidebar-item
  16. v-for="child in item.children"
  17. :key="child.path"
  18. :is-nest="true"
  19. :item="child"
  20. :base-path="resolvePath(child.path)"
  21. class="nest-menu"
  22. />
  23. </el-submenu>
  24. </div>
  25. </template>
  26. <script>
  27. import path from 'path'
  28. import { isExternal } from '@/utils/validate'
  29. import Item from './Item'
  30. import AppLink from './Link'
  31. import FixiOSBug from './FixiOSBug'
  32. export default {
  33. name: 'SidebarItem',
  34. components: { Item, AppLink },
  35. mixins: [FixiOSBug],
  36. props: {
  37. // route object
  38. item: {
  39. type: Object,
  40. required: true
  41. },
  42. isNest: {
  43. type: Boolean,
  44. default: false
  45. },
  46. basePath: {
  47. type: String,
  48. default: ''
  49. },
  50. showTips: {
  51. type: Boolean,
  52. default: false,
  53. required: false
  54. }
  55. },
  56. data() {
  57. // To fix https://github.com/PanJiaChen/vue-admin-template/issues/237
  58. // TODO: refactor with render function
  59. this.onlyOneChild = null
  60. return {
  61. }
  62. },
  63. computed: {
  64. isBizSelectPage() {
  65. return this.$route.name === '业务线选择'
  66. }
  67. },
  68. watch: {
  69. showTips: {
  70. handler(newV) {},
  71. immediate: true
  72. }
  73. },
  74. methods: {
  75. hasOneShowingChild(children = [], parent) {
  76. const showingChildren = children.filter(item => {
  77. if (item.hidden) {
  78. return false
  79. } else {
  80. // Temp set(will be used if only has one showing child)
  81. this.onlyOneChild = item
  82. return true
  83. }
  84. })
  85. // When there is only one child router, the child router is displayed by default
  86. if (showingChildren.length === 1) {
  87. return true
  88. }
  89. // Show parent if there are no child router to display
  90. if (showingChildren.length === 0) {
  91. this.onlyOneChild = { ... parent, path: '', noShowingChildren: true }
  92. return true
  93. }
  94. return false
  95. },
  96. resolvePath(routePath) {
  97. if (isExternal(routePath)) {
  98. return routePath
  99. }
  100. if (isExternal(this.basePath)) {
  101. return this.basePath
  102. }
  103. return path.resolve(this.basePath, routePath)
  104. }
  105. }
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. .if-notice {
  110. position: absolute;
  111. height: 8px;
  112. width: 8px;
  113. background-color: #E02020;
  114. border-radius: 50%;
  115. top: 43%;
  116. right: 37%;
  117. transform: translateY(-50%);
  118. }
  119. </style>