index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <div :class="{'has-logo':showLogo}">
  3. <logo v-if="showLogo" :collapse="isCollapse" />
  4. <el-scrollbar wrap-class="scrollbar-wrapper">
  5. <el-menu
  6. :default-active="activeMenu"
  7. :collapse="isCollapse"
  8. :background-color="variables.menuBg"
  9. :text-color="variables.menuText"
  10. :unique-opened="false"
  11. :active-text-color="variables.menuActiveText"
  12. :collapse-transition="false"
  13. mode="vertical"
  14. @select="handleSelect"
  15. >
  16. <sidebar-item v-for="route in routes" :key="route.path" :item="route" :base-path="route.path" />
  17. <el-submenu index="100">
  18. <template slot="title">
  19. <i class="el-icon-menu" />
  20. <span slot="title" @mouseover="getGlobalInterface">数据中心</span>
  21. </template>
  22. <el-menu-item index="/data/upload-file">jar包上传</el-menu-item>
  23. <el-submenu v-for="(myMenu,index) in menu" :key="myMenu.menuName" :index="'100-' + index">
  24. <template slot="title">{{ myMenu.menuName }}</template>
  25. <el-menu-item v-for="(subMenu,index2) in myMenu.subMenus" :key="subMenu.path" :index="getIndex(index,index2)" @click="handleClick(subMenu)">{{ subMenu.subMenuName }}</el-menu-item>
  26. </el-submenu>
  27. </el-submenu>
  28. </el-menu>
  29. </el-scrollbar>
  30. </div>
  31. </template>
  32. <script>
  33. import { mapGetters } from 'vuex'
  34. import Logo from './Logo'
  35. import SidebarItem from './SidebarItem'
  36. import variables from '@/styles/variables.scss'
  37. import { getGlobalInterface } from '@/api/data.js'
  38. export default {
  39. components: { SidebarItem, Logo },
  40. computed: {
  41. ...mapGetters([
  42. 'sidebar',
  43. 'menu'
  44. ]),
  45. routes() {
  46. return this.$router.options.routes
  47. },
  48. activeMenu() {
  49. const route = this.$route
  50. const { meta, path } = route
  51. // if set path, the sidebar will highlight the path you set
  52. if (meta.activeMenu) {
  53. return meta.activeMenu
  54. }
  55. return path
  56. },
  57. showLogo() {
  58. return this.$store.state.settings.sidebarLogo
  59. },
  60. variables() {
  61. return variables
  62. },
  63. isCollapse() {
  64. return !this.sidebar.opened
  65. }
  66. },
  67. mounted() {
  68. this.getGlobalInterface()
  69. },
  70. methods: {
  71. handleSelect(key, keypath) {
  72. switch (key) {
  73. case '/data/upload-file':
  74. this.$router.push({ name: 'jar包上传' })
  75. break
  76. }
  77. },
  78. handleClick(subMenu) {
  79. this.$store.dispatch('data/setSubMenu', subMenu)
  80. this.$router.push({ name: '动态数据' })
  81. },
  82. getGlobalInterface() {
  83. getGlobalInterface()
  84. .then(res => {
  85. this.$store.dispatch('data/setMenu', res.data)
  86. this.$store.dispatch('data/setSubMenu', res.data[0].subMenus[0])
  87. })
  88. },
  89. getIndex(index, index2) {
  90. if (index + index2 === 0) {
  91. return '/data/item'
  92. }
  93. return '100-' + index + '-' + index2
  94. }
  95. }
  96. }
  97. </script>