56 lines
2.2 KiB
Vue
Raw Normal View History

2023-03-04 09:16:33 +08:00
<template>
<template v-for="subItem in menuList" :key="subItem.path">
<el-sub-menu v-if="subItem.children && subItem.children.length > 0" :index="subItem.path">
<template #title>
2023-06-26 17:51:39 +08:00
<!-- <img :src="activeMenu == subItem.path ? `${subItem.meta.icon}` : `${'un' + subItem.meta.icon}`" style="width: 14px" /> -->
<img :src="getImageUrl(activeMenu == subItem.path ? subItem.meta.icon : 'un' + subItem.meta.icon)" style="width: 14px" />
2023-03-27 14:17:30 +08:00
<span style="margin-left: 8px">{{ subItem.meta.title }}</span>
2023-03-04 09:16:33 +08:00
</template>
<SubMenu :menuList="subItem.children" />
</el-sub-menu>
<el-menu-item v-else :index="subItem.path" @click="handleClickMenu(subItem)">
2023-03-24 19:36:11 +08:00
<!-- <img :src="`${subItem.meta.icon}`" /> -->
<img :src="getImageUrl(activeMenu == subItem.path ? subItem.meta.icon : 'un' + subItem.meta.icon)" style="width: 14px" />
2023-03-04 09:16:33 +08:00
<template #title>
2023-03-27 14:17:30 +08:00
<span style="margin-left: 8px">{{ subItem.meta.title }}</span>
2023-03-04 09:16:33 +08:00
</template>
</el-menu-item>
</template>
</template>
<script setup lang="ts">
2023-03-27 14:17:30 +08:00
import { ref, computed } from "vue";
import { useRouter, useRoute } from "vue-router";
2023-08-01 15:07:16 +08:00
import { getButtonAuth } from "@/api/modules/auth";
2023-04-25 10:48:27 +08:00
import { GlobalStore } from "@/stores";
2023-08-01 15:07:16 +08:00
import { AuthStore } from "@/stores/modules/auth";
const authStore = AuthStore();
2023-03-27 14:17:30 +08:00
const route = useRoute();
2023-04-25 10:48:27 +08:00
const globalStore = GlobalStore();
2023-03-27 14:17:30 +08:00
const activeMenu = computed(() => (route.meta.activeMenu ? route.meta.activeMenu : route.path));
2023-03-04 09:16:33 +08:00
function getImageUrl(name: string) {
2023-04-25 10:48:27 +08:00
return new URL(`../../../assets/images/leftTab/${name}` + ".png", import.meta.url).href;
}
2023-03-04 09:16:33 +08:00
defineProps<{ menuList: Menu.MenuOptions[] }>();
const router = useRouter();
// const imgUrl = "/src/assets/images/leftTab/";
// const imgUrl = "/src/assets/images/leftTab/";
const baseImgURl = import.meta.env.VITE_BASE_IMAGE_URL;
// const imgUrl = "@/assets/images/leftTab/";
2023-04-25 10:48:27 +08:00
const handleClickMenu = async (subItem: Menu.MenuOptions) => {
2023-03-04 09:16:33 +08:00
if (subItem.meta.isLink) return window.open(subItem.meta.isLink, "_blank");
2023-08-01 15:07:16 +08:00
if (globalStore.accountType != 1) {
const res = await getButtonAuth({ menuId: subItem.name });
if (res && res.result) {
authStore.authButtonList = res.result;
}
}
2023-03-04 09:16:33 +08:00
router.push(subItem.path);
};
</script>