TheMenu.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <script setup lang="tsx">
  2. import { h } from 'vue'
  3. import { NMenu } from 'naive-ui'
  4. import { RouterLink } from 'vue-router'
  5. import SvgIcon from '@/components/SvgIcon/index.vue'
  6. function renderIcon(props: {name: string, size?: number, class?: string[], color?: string}) {
  7. return () => h(SvgIcon, { ...props })
  8. }
  9. function renderChildrenIcon({ name, size = 20 }:{ name:string, size?: number }) {
  10. return () => (
  11. <div class="flex items-center justify-center">
  12. { renderIcon({ name, size, class: ['icon-default'] })() }
  13. { renderIcon({ name: name + '-active', size, class: ['icon-active', 'hidden'] })() }
  14. </div>
  15. )
  16. }
  17. function renderLabel (val: string) {
  18. return (<span class="pl-1 test">{ val }</span>);
  19. }
  20. const menuOptions: MenuOption[] = [
  21. {
  22. label: () => renderLabel('智慧总控'),
  23. icon: renderIcon({name: 'menu-control'}),
  24. key: '/'
  25. },
  26. {
  27. label: () => renderLabel('专家问答'),
  28. icon: renderIcon({name: 'menu-answers'}),
  29. key: '/'
  30. },
  31. {
  32. label: () => renderLabel('智能分析'),
  33. icon: renderIcon({ name: 'menu-analyse' }),
  34. key: '/',
  35. children: [
  36. {
  37. label:() => renderLabel('水质报警'),
  38. icon: renderChildrenIcon({ name: 'menu-analyse-water' }),
  39. key: 'key1',
  40. },
  41. {
  42. label: '生化报警',
  43. icon: renderChildrenIcon({ name: 'menu-analyse-pymol' }),
  44. key: 'key2',
  45. },
  46. {
  47. label: '预测报警',
  48. icon: renderChildrenIcon({ name: 'menu-analyse-notice' }),
  49. key: 'key3',
  50. },
  51. {
  52. label: '智能工单',
  53. icon: renderChildrenIcon({ name: 'menu-analyse-order' }),
  54. key: 'key4',
  55. }
  56. ]
  57. },
  58. {
  59. label: () => renderLabel('智能助手'),
  60. icon: renderIcon({ name: 'menu-user' }),
  61. key: '/'
  62. },
  63. {
  64. label: () => renderLabel('用户中心'),
  65. icon: renderIcon({ name: 'menu-help' }),
  66. key: '/'
  67. },
  68. ]
  69. const handleUpdateValue = () => {
  70. console.log(123123);
  71. }
  72. </script>
  73. <template>
  74. <n-menu
  75. :options="menuOptions"
  76. :icon-size="30"
  77. @update:value="handleUpdateValue"
  78. >
  79. </n-menu>
  80. </template>
  81. <style scoped lang="scss">
  82. </style>
  83. <style lang="scss">
  84. @mixin sub-menu-active {
  85. .n-menu-item-content__icon {
  86. .icon-default {
  87. display: none;
  88. }
  89. .icon-active {
  90. display: block;
  91. }
  92. }
  93. .n-menu-item-content-header {
  94. font-weight: bold;
  95. }
  96. }
  97. .n-menu .n-menu-item-content:not(.n-menu-item-content--disabled):hover::before {
  98. border: 1px solid #fff;
  99. background: #FCFDFE;
  100. }
  101. // 子菜单hover
  102. .n-submenu-children {
  103. .n-menu-item-content:hover {
  104. @include sub-menu-active();
  105. }
  106. }
  107. // reset - 选中状态
  108. .n-menu-item-content--selected {
  109. @include sub-menu-active();
  110. &:not(.n-menu-item-content--disabled)::before {
  111. border: 1px solid #fff;
  112. background: #FCFDFE;
  113. }
  114. }
  115. // reset - 选中状态
  116. // .n-menu-item-content--selected {
  117. // font-weight: bold;
  118. // }
  119. // .n-base-icon {
  120. // background: url('@/assets/svgs/menu/arrow.svg') center center no-repeat;
  121. // svg {
  122. // display: none;
  123. // }
  124. // }
  125. </style>