Files
wireguard-dashboard-admin/src/layout/components/sidebar/vertical.vue

81 lines
2.1 KiB
Vue
Raw Normal View History

2021-10-16 16:16:58 +08:00
<script setup lang="ts">
import Logo from "./logo.vue";
import { emitter } from "/@/utils/mitt";
2022-02-15 23:16:15 +08:00
import { useNav } from "../../hooks/nav";
2021-10-16 16:16:58 +08:00
import SidebarItem from "./sidebarItem.vue";
import { storageLocal } from "/@/utils/storage";
import { useRoute, useRouter } from "vue-router";
2022-02-15 23:16:15 +08:00
import { ref, computed, watch, onBeforeMount } from "vue";
import { findRouteByPath, getParentPaths } from "/@/router/utils";
2021-10-16 16:16:58 +08:00
import { usePermissionStoreHook } from "/@/store/modules/permission";
const route = useRoute();
2022-02-15 23:16:15 +08:00
const routers = useRouter().options.routes;
2022-01-05 14:17:06 +08:00
const showLogo = ref(
storageLocal.getItem("responsive-configure")?.showLogo ?? true
);
2022-02-15 23:16:15 +08:00
const { pureApp, isCollapse, menuSelect } = useNav();
let subMenuData = ref([]);
const menuData = computed(() => {
return pureApp.layout === "mix"
? subMenuData.value
: usePermissionStoreHook().wholeMenus;
2021-10-16 16:16:58 +08:00
});
2022-02-15 23:16:15 +08:00
function getSubMenuData(path) {
// path的上级路由组成的数组
const parentPathArr = getParentPaths(
path,
usePermissionStoreHook().wholeMenus
);
// 当前路由的父级路由信息
const parenetRoute = findRouteByPath(
parentPathArr[0] || path,
usePermissionStoreHook().wholeMenus
);
if (!parenetRoute?.children) return;
subMenuData.value = parenetRoute?.children;
}
getSubMenuData(route.path);
2021-10-16 16:16:58 +08:00
onBeforeMount(() => {
emitter.on("logoChange", key => {
showLogo.value = key;
});
});
2022-02-15 23:16:15 +08:00
watch(
() => route.path,
() => getSubMenuData(route.path)
);
2021-10-16 16:16:58 +08:00
</script>
<template>
<div :class="['sidebar-container', showLogo ? 'has-logo' : '']">
2022-01-05 14:17:06 +08:00
<Logo v-if="showLogo" :collapse="isCollapse" />
2021-10-16 16:16:58 +08:00
<el-scrollbar wrap-class="scrollbar-wrapper">
<el-menu
2022-02-15 23:16:15 +08:00
:default-active="route.path"
2021-10-16 16:16:58 +08:00
:collapse="isCollapse"
unique-opened
router
:collapse-transition="false"
mode="vertical"
class="outer-most"
2022-02-15 23:16:15 +08:00
@select="indexPath => menuSelect(indexPath, routers)"
2021-10-16 16:16:58 +08:00
>
<sidebar-item
2022-02-15 23:16:15 +08:00
v-for="routes in menuData"
:key="routes.path"
:item="routes"
class="outer-most"
2022-02-15 23:16:15 +08:00
:base-path="routes.path"
2021-10-16 16:16:58 +08:00
/>
</el-menu>
</el-scrollbar>
</div>
</template>