zhitong.yu
8 天以前 378d781e6f35f89652aa36e079a8b7fc44cea77e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<template>
  <template v-for="subItem in menuList" :key="subItem.path">
    <el-sub-menu v-if="subItem.children?.length" :index="subItem.path">
      <template #title>
        <i v-if="subItem.meta.icon" :class="'ri-' + subItem.meta.icon" style="margin-right: 8px; font-size: 1.2em" />
        <span class="sle">{{ getMenuTitle(subItem) }}</span>
      </template>
      <SubMenu :menu-list="subItem.children" />
    </el-sub-menu>
    <el-menu-item
      v-else
      :index="subItem.path"
      style="width: 90%; height: 50px; margin: auto; border-radius: 5px"
      @click="handleClickMenu(subItem)"
    >
      <i v-if="subItem.meta.icon" :class="'ri-' + subItem.meta.icon" style="margin-right: 8px; font-size: 1.2em" />
      <template #title>
        <span class="sle">{{ getMenuTitle(subItem) }}</span>
      </template>
    </el-menu-item>
  </template>
</template>
 
<script setup lang="ts">
import { useRouter } from "vue-router";
 
import { computed } from "vue";
import { useGlobalStore } from "@/stores/modules/global";
 
defineProps<{ menuList: Menu.MenuOptions[] }>();
 
const globalStore = useGlobalStore();
const router = useRouter();
 
// 获取当前语言
const currentLanguage = computed(() => globalStore.language);
 
// 根据当前语言获取菜单标题
const getMenuTitle = (subItem: Menu.MenuOptions) => {
  // 如果是英文且存在英文标题,则使用英文标题
  if (currentLanguage.value === "en" && subItem.meta.entitle) {
    return subItem.meta.entitle;
  }
  // 否则使用默认标题
  return subItem.meta.title;
};
 
const handleClickMenu = (subItem: Menu.MenuOptions) => {
  if (subItem.meta.isLink) return window.open(subItem.meta.isLink, "_blank");
  router.push(subItem.path);
};
</script>
 
<style lang="scss">
.el-sub-menu .el-sub-menu__title:hover {
  color: var(--el-menu-hover-text-color) !important;
  background-color: transparent !important;
}
.el-menu--collapse {
  .is-active {
    .el-sub-menu__title {
      color: #ffffff !important;
      background-color: var(--el-color-primary) !important;
    }
  }
}
.el-menu-item {
  &:hover {
    color: var(--el-menu-hover-text-color);
  }
  &.is-active {
    color: var(--el-menu-active-color) !important;
    background-color: var(--el-menu-active-bg-color) !important;
    &::before {
      position: absolute;
      top: 0;
      bottom: 0;
      width: 4px;
      content: "";
 
      // background-color: var(--el-color-primary);
    }
  }
}
.vertical,
.classic,
.transverse {
  .el-menu-item {
    &.is-active {
      &::before {
        left: 0;
      }
    }
  }
}
.columns {
  .el-menu-item {
    &.is-active {
      &::before {
        right: 0;
      }
    }
  }
}
</style>