BaseMenu.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <script setup lang="ts">
  2. import { ref } from 'vue';
  3. import { useRoute, useRouter } from 'vue-router';
  4. import { NMenu } from 'naive-ui';
  5. import type { MenuOption } from 'naive-ui';
  6. defineProps<{
  7. mode : 'vertical' | 'horizontal';
  8. }>();
  9. const { t } = useI18n();
  10. const emit = defineEmits(['on-menu-item']);
  11. const route = useRoute();
  12. const router = useRouter();
  13. const activeMenuKey = ref(route.path);
  14. const menuOptions: MenuOption[] = [
  15. {
  16. label: () => h('span', [t("menu.home")]),
  17. key: "/",
  18. },
  19. // {
  20. // label: () => h('span', [t("menu.aiModel")]),
  21. // key: "/ai/model",
  22. // },
  23. /**
  24. * TODO 待后续完善
  25. * */
  26. {
  27. label: () => h('span', [t("menu.aiModel")]),
  28. key: "/ai",
  29. children: [
  30. {
  31. label: () => h('span', [t("menu.aiModelSubVertica")]),
  32. key: "/ai/model"
  33. },
  34. {
  35. label: () => h('span', [t("menu.aiModelSubWater")]),
  36. key: "/ai/water"
  37. },
  38. ]
  39. },
  40. {
  41. label: () => h('span', [t("menu.libraCarbonNeutral")]),
  42. key: "/carbon",
  43. children: [
  44. {
  45. label: () => h('span', [t("menu.libraCarbonNeutralSubDevelopment")]),
  46. key: "/carbon/dmrv"
  47. },
  48. {
  49. label:() => h('span', [t("menu.libraCarbonNeutralSubSustainable")]),
  50. key: "/carbon/develop"
  51. },
  52. // {
  53. // label: () => h('span', [t("menu.libraCarbonNeutralSubTrading")]),
  54. // key: "/carbon/deal"
  55. // },
  56. ]
  57. },
  58. {
  59. label: () => h('span', [t("menu.news")]),
  60. key: "/news",
  61. langKey: "menu.news"
  62. },
  63. {
  64. label: () => h('span', [t("menu.about")]),
  65. key: "/about",
  66. langKey: "menu.about"
  67. }
  68. ];
  69. const onMenuChange = (key: string) => {
  70. emit('on-menu-item');
  71. router.push(key);
  72. }
  73. watch(() => route.path, currentPath => {
  74. activeMenuKey.value = currentPath;
  75. });
  76. </script>
  77. <template>
  78. <NMenu v-model:value="activeMenuKey" :mode="mode" :options="menuOptions" @update:value="onMenuChange" />
  79. </template>