topbar.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <div class="app-topbar-menu">
  3. <el-menu :default-active="index" mode="horizontal" @select="onSelect">
  4. <el-menu-item v-for="(item, index) in menuGroup" :index="`${index}`" :key="index">
  5. <icon-svg v-if="item.icon" :name="item.icon"></icon-svg>
  6. <span>{{ item.name }}</span>
  7. </el-menu-item>
  8. </el-menu>
  9. </div>
  10. </template>
  11. <script>
  12. import { mapMutations, mapGetters } from "vuex";
  13. import { firstMenu } from "cool/modules/base/utils";
  14. export default {
  15. name: "cl-menu-topbar",
  16. data() {
  17. return {
  18. index: "0"
  19. };
  20. },
  21. computed: {
  22. ...mapGetters(["menuGroup"])
  23. },
  24. mounted() {
  25. this.menuGroup.forEach((e, i) => {
  26. if (this.$route.path.includes(e.path) && e.path != "/") {
  27. this.index = String(i);
  28. this.SET_MENU_LIST(i);
  29. }
  30. });
  31. },
  32. methods: {
  33. ...mapMutations(["SET_MENU_LIST"]),
  34. onSelect(index) {
  35. this.SET_MENU_LIST(index);
  36. const url = firstMenu(this.menuGroup[index].children);
  37. this.$router.push(url);
  38. }
  39. }
  40. };
  41. </script>
  42. <style lang="scss" scoped>
  43. .app-topbar-menu {
  44. /deep/.el-menu {
  45. height: 50px;
  46. background: transparent;
  47. border-bottom: 0;
  48. overflow: hidden;
  49. .el-menu-item {
  50. height: 50px;
  51. display: flex;
  52. align-items: center;
  53. background: transparent;
  54. border-bottom: 0;
  55. padding: 0 30px;
  56. span {
  57. font-size: 12px;
  58. margin-left: 3px;
  59. line-height: normal;
  60. }
  61. &.is-active {
  62. background: rgba(255, 255, 255, 0.13);
  63. }
  64. /deep/.icon-svg {
  65. height: 18px;
  66. width: 18px;
  67. margin-right: 5px;
  68. }
  69. }
  70. }
  71. }
  72. </style>