NavItem.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <router-link :to="to">
  3. <div class="nav-item" :class="{ 'is-active': is_active }">
  4. <component class="nav-item-icon" :is="icon" />
  5. <span>{{ label }}</span>
  6. </div>
  7. </router-link>
  8. </template>
  9. <script setup>
  10. import { computed } from 'vue';
  11. import { useRoute } from 'vue-router';
  12. const props = defineProps({
  13. label: String,
  14. to: String,
  15. icon: String
  16. });
  17. const route = useRoute();
  18. const target = props.to;
  19. const isChatType = (cur_path) => {
  20. return cur_path === '/chat' || cur_path === '/chat/history' || cur_path === '/chat/board' || cur_path === '/chat/qa';
  21. };
  22. const isKnowLedgeType = (cur_path) => {
  23. return cur_path === '/knowledge' || cur_path === '/knowledge/detail';
  24. };
  25. const isIntelligentType = (cur_path) => {
  26. return cur_path === '/intelligent' || cur_path === '/intelligent/detail';
  27. };
  28. const is_active = computed(() => {
  29. const cur_path = route.path;
  30. if (target === '/chat/history') {
  31. // 对话
  32. const is_chat = isChatType(cur_path);
  33. if (is_chat) {
  34. return true;
  35. } else {
  36. return false;
  37. }
  38. }
  39. if (['/knowledge', '/knowledge/detail'].includes(target)) {
  40. return isKnowLedgeType(cur_path);
  41. }
  42. if (['/intelligent', '/intelligent/detail'].includes(target)) {
  43. return isIntelligentType(cur_path);
  44. }
  45. return cur_path === target;
  46. });
  47. </script>
  48. <style lang="css" scoped>
  49. .nav-item {
  50. display: flex;
  51. justify-content: center;
  52. align-items: center;
  53. height: 40px;
  54. border-radius: 20px;
  55. padding-left: 15px;
  56. padding-right: 15px;
  57. margin-left: 5px;
  58. margin-right: 5px;
  59. color: var(--color-text-1);
  60. }
  61. .nav-item:hover {
  62. background-color: var(--color-fill-4);
  63. color: #fff;
  64. }
  65. .nav-item.is-active {
  66. background-color: rgb(var(--primary-6));
  67. color: #fff;
  68. }
  69. .nav-item-icon {
  70. font-size: 22px;
  71. margin-right: 5px;
  72. }
  73. </style>