asyncSubmenu.vue 2.0 KB
Newer Older
Mr.奇淼('s avatar
Mr.奇淼( 已提交
1
<template>
2
  <el-sub-menu ref="subMenu" :index="routerInfo.name">
3

4
    <template #title>
5 6 7 8 9 10 11 12 13 14 15 16
      <div v-if="!isCollapse" class="gva-subMenu">
        <el-icon v-if="routerInfo.meta.icon">
          <component :is="routerInfo.meta.icon" />
        </el-icon>
        <span>{{ routerInfo.meta.title }}</span>
      </div>
      <template v-else>
        <el-icon v-if="routerInfo.meta.icon">
          <component :is="routerInfo.meta.icon" />
        </el-icon>
        <span>{{ routerInfo.meta.title }}</span>
      </template>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
17
    </template>
何秀钢 已提交
18
    <slot />
19
  </el-sub-menu>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
20 21 22 23
</template>

<script>
export default {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
24
  name: 'AsyncSubmenu',
Mr.奇淼('s avatar
Mr.奇淼( 已提交
25 26
}
</script>
27 28

<script setup>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
29 30
import { ref, watch } from 'vue'
const props = defineProps({
31 32 33 34 35
  routerInfo: {
    default: function() {
      return null
    },
    type: Object
Mr.奇淼('s avatar
Mr.奇淼( 已提交
36 37 38 39 40 41 42 43 44 45 46 47
  },
  isCollapse: {
    default: function() {
      return false
    },
    type: Boolean
  },
  theme: {
    default: function() {
      return {}
    },
    type: Object
48 49
  }
})
Mr.奇淼('s avatar
Mr.奇淼( 已提交
50

51 52
const activeBackground = ref(props.theme.activeBackground)
const activeText = ref(props.theme.activeText)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
53 54 55 56 57
const normalText = ref(props.theme.normalText)
// const hoverBackground = ref(props.theme.hoverBackground)
// const hoverText = ref(props.theme.hoverText)

watch(() => props.theme, () => {
58 59
  activeBackground.value = props.theme.activeBackground
  activeText.value = props.theme.activeText
Mr.奇淼('s avatar
Mr.奇淼( 已提交
60 61 62 63 64
  normalText.value = props.theme.normalText
  // hoverBackground.value = props.theme.hoverBackground
  // hoverText.value = props.theme.hoverText
})

65
</script>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
66 67 68 69

<style lang="scss" scoped>
.el-sub-menu{
  ::v-deep(.el-sub-menu__title){
70
      padding: 6px;
Mr.奇淼('s avatar
Mr.奇淼( 已提交
71 72 73 74
      color: v-bind(normalText);
  }
}

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
  .is-active:not(.is-opened){
  ::v-deep(.el-sub-menu__title) .gva-subMenu{
      flex:1;
      height: 100%;
      line-height: 44px;
      background: v-bind(activeBackground) !important;
      border-radius: 4px;
      box-shadow: 0 0 2px 1px v-bind(activeBackground) !important;
      i{
        color: v-bind(activeText);
      }
      span{
        color: v-bind(activeText);
      }
    }
  }

Mr.奇淼('s avatar
Mr.奇淼( 已提交
92
</style>