SideMenu.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div class="side-menu-wrapper">
  3. <slot></slot>
  4. <!--侧边菜单栏展开时显示方式-->
  5. <Menu ref="menu" :active-name="activeName" :open-names="openedNames"
  6. :accordion="accordion" :theme="theme" width="auto" @on-select="handleSelect" v-show="!collapsed">
  7. <MenuItem name="1">
  8. <Icon type="ios-home" />
  9. 首页
  10. </MenuItem>
  11. <MenuItem name="2">
  12. <Icon type="ios-reorder" />
  13. 订单管理
  14. </MenuItem>
  15. </Menu>
  16. <!--侧边菜单栏叠起时显示方式-->
  17. <div class="menu-collapsed" v-show="collapsed"></div>
  18. </div>
  19. </template>
  20. <script>
  21. // import SideMenuItem from './SideMenuItem.vue'
  22. // import CollapsedMenu from './CollapseMenu.vue'
  23. // import { getUnion } from '@/libs/tools'
  24. // import mixin from './mixin'
  25. export default {
  26. name: "SideMenu",
  27. // mixins: [mixin],
  28. props: {
  29. menuList: {
  30. type: Array,
  31. default () {
  32. return []
  33. }
  34. },
  35. collapsed: {
  36. type: Boolean
  37. },
  38. theme: {
  39. type: String,
  40. default: 'dark'
  41. },
  42. accordion: {
  43. type: Boolean
  44. },
  45. rootIconSize: {
  46. type: Number,
  47. default: 20
  48. },
  49. iconSize: {
  50. type: Number,
  51. default: 16
  52. },
  53. activeName: {
  54. type: String,
  55. default: ''
  56. },
  57. openNames: {
  58. type: Array,
  59. default: () => []
  60. }
  61. },
  62. data(){
  63. return {
  64. openedNames: []
  65. }
  66. },
  67. methods: {
  68. handleSelect(name){
  69. this.$emit('on-select',name)
  70. },
  71. getOpenedNamesByActiveName(name){
  72. return this.$route.matched.map(item => item.name).filter(item => item !== name)
  73. },
  74. updateOpenName(name){
  75. if(name === this.$config.homeName){
  76. this.openedNames = [];
  77. }else {
  78. this.openedNames = this.getOpenedNamesByActiveName(name)
  79. }
  80. }
  81. },
  82. computed: {
  83. textColor(){
  84. return this.theme === 'dark' ? '#ffffff' : '#495060';
  85. }
  86. },
  87. watch: {
  88. // activeName (name) {
  89. // if (this.accordion) this.openedNames = this.getOpenedNamesByActiveName(name)
  90. // else this.openedNames = getUnion(this.openedNames, this.getOpenedNamesByActiveName(name))
  91. // },
  92. // openNames (newNames) {
  93. // this.openedNames = newNames
  94. // },
  95. // openedNames () {
  96. // this.$nextTick(() => {
  97. // this.$refs.menu.updateOpened()
  98. // })
  99. // }
  100. },
  101. mounted () {
  102. // this.openedNames = getUnion(this.openedNames, this.getOpenedNamesByActiveName(name))
  103. }
  104. }
  105. </script>
  106. <style lang="less" scoped>
  107. </style>