menuItem.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <el-menu-item :index="routerInfo.name">
  3. <template v-if="isCollapse">
  4. <el-tooltip
  5. class="box-item"
  6. effect="light"
  7. :content="routerInfo.meta.title"
  8. placement="right"
  9. >
  10. <el-icon v-if="routerInfo.meta.icon">
  11. <component :is="routerInfo.meta.icon" />
  12. </el-icon>
  13. </el-tooltip>
  14. </template>
  15. <template v-else>
  16. <div class="gva-menu-item">
  17. <el-icon v-if="routerInfo.meta.icon">
  18. <component :is="routerInfo.meta.icon" />
  19. </el-icon>
  20. <span class="gva-menu-item-title">{{ routerInfo.meta.title }}</span>
  21. </div>
  22. </template>
  23. </el-menu-item>
  24. </template>
  25. <script setup>
  26. import { ref, watch } from 'vue'
  27. defineOptions({
  28. name: 'MenuItem',
  29. })
  30. const props = defineProps({
  31. routerInfo: {
  32. default: function() {
  33. return null
  34. },
  35. type: Object
  36. },
  37. isCollapse: {
  38. default: function() {
  39. return false
  40. },
  41. type: Boolean
  42. },
  43. theme: {
  44. default: function() {
  45. return {}
  46. },
  47. type: Object
  48. }
  49. })
  50. const activeBackground = ref(props.theme.activeBackground)
  51. const activeText = ref(props.theme.activeText)
  52. const normalText = ref(props.theme.normalText)
  53. const hoverBackground = ref(props.theme.hoverBackground)
  54. const hoverText = ref(props.theme.hoverText)
  55. watch(() => props.theme, () => {
  56. activeBackground.value = props.theme.activeBackground
  57. activeText.value = props.theme.activeText
  58. normalText.value = props.theme.normalText
  59. hoverBackground.value = props.theme.hoverBackground
  60. hoverText.value = props.theme.hoverText
  61. })
  62. </script>
  63. <style lang="scss" scoped>
  64. .gva-menu-item{
  65. width: 100%;
  66. flex:1;
  67. height: 44px;
  68. display: flex;
  69. justify-content: flex-start;
  70. align-items: center;
  71. padding-left: 4px;
  72. .gva-menu-item-title {
  73. flex:1;
  74. }
  75. }
  76. .el-menu--collapse{
  77. .el-menu-item.is-active{
  78. color: v-bind(activeBackground);
  79. }
  80. }
  81. .el-menu-item{
  82. color: v-bind(normalText);
  83. font-size:11px;
  84. }
  85. .el-menu-item.is-active{
  86. .gva-menu-item{
  87. background: v-bind(activeBackground) !important;
  88. border-radius: 4px;
  89. box-shadow: 0 0 2px 1px v-bind(activeBackground) !important;
  90. i{
  91. color: v-bind(activeText);
  92. }
  93. span{
  94. color: v-bind(activeText);
  95. }
  96. }
  97. }
  98. .el-menu-item:hover{
  99. .gva-menu-item{
  100. background: v-bind(hoverBackground);
  101. border-radius: 4px;
  102. box-shadow: 0 0 2px 1px v-bind(hoverBackground);
  103. color: v-bind(hoverText);
  104. }
  105. }
  106. </style>