2022-01-18 01:17:09 +08:00
|
|
|
<template>
|
2022-04-27 16:39:20 +08:00
|
|
|
<dark-mode-container class="flex h-full" :inverted="theme.sider.inverted" @mouseleave="resetFirstDegreeMenus">
|
2022-01-18 01:17:09 +08:00
|
|
|
<div class="flex-1 flex-col-stretch h-full">
|
|
|
|
<global-logo :show-title="false" :style="{ height: theme.header.height + 'px' }" />
|
|
|
|
<n-scrollbar class="flex-1-hidden">
|
|
|
|
<mix-menu-detail
|
|
|
|
v-for="item in firstDegreeMenus"
|
|
|
|
:key="item.routeName"
|
|
|
|
:route-name="item.routeName"
|
|
|
|
:active-route-name="activeParentRouteName"
|
|
|
|
:label="item.label"
|
|
|
|
:icon="item.icon"
|
|
|
|
:is-mini="app.siderCollapse"
|
|
|
|
@click="handleMixMenu(item.routeName, item.hasChildren)"
|
|
|
|
/>
|
|
|
|
</n-scrollbar>
|
|
|
|
<mix-menu-collapse />
|
|
|
|
</div>
|
|
|
|
<mix-menu-drawer :visible="drawerVisible" :menus="activeChildMenus" />
|
|
|
|
</dark-mode-container>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
import { computed, ref, watch } from 'vue';
|
|
|
|
import { useRoute } from 'vue-router';
|
|
|
|
import { useAppStore, useThemeStore, useRouteStore } from '@/store';
|
|
|
|
import { useRouterPush } from '@/composables';
|
|
|
|
import { useBoolean } from '@/hooks';
|
|
|
|
import { GlobalLogo } from '@/layouts/common';
|
|
|
|
import { MixMenuDetail, MixMenuDrawer, MixMenuCollapse } from './components';
|
|
|
|
|
|
|
|
const route = useRoute();
|
|
|
|
const app = useAppStore();
|
|
|
|
const theme = useThemeStore();
|
|
|
|
const routeStore = useRouteStore();
|
|
|
|
const { routerPush } = useRouterPush();
|
|
|
|
const { bool: drawerVisible, setTrue: openDrawer, setFalse: hideDrawer } = useBoolean();
|
|
|
|
|
|
|
|
const activeParentRouteName = ref('');
|
|
|
|
function setActiveParentRouteName(routeName: string) {
|
|
|
|
activeParentRouteName.value = routeName;
|
|
|
|
}
|
|
|
|
|
|
|
|
const firstDegreeMenus = computed(() =>
|
2022-04-01 14:47:57 +08:00
|
|
|
routeStore.menus.map(item => {
|
2022-01-18 01:17:09 +08:00
|
|
|
const { routeName, label } = item;
|
|
|
|
const icon = item?.icon;
|
|
|
|
const hasChildren = Boolean(item.children && item.children.length);
|
|
|
|
|
|
|
|
return {
|
|
|
|
routeName,
|
|
|
|
label,
|
|
|
|
icon,
|
2022-04-01 14:47:57 +08:00
|
|
|
hasChildren
|
2022-01-18 01:17:09 +08:00
|
|
|
};
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
function getActiveParentRouteName() {
|
2022-04-01 14:47:57 +08:00
|
|
|
firstDegreeMenus.value.some(item => {
|
2022-01-18 01:17:09 +08:00
|
|
|
const routeName = route.name as string;
|
|
|
|
const flag = routeName?.includes(item.routeName);
|
|
|
|
if (flag) {
|
|
|
|
setActiveParentRouteName(item.routeName);
|
|
|
|
}
|
|
|
|
return flag;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleMixMenu(routeName: string, hasChildren: boolean) {
|
|
|
|
setActiveParentRouteName(routeName);
|
|
|
|
if (hasChildren) {
|
|
|
|
openDrawer();
|
|
|
|
} else {
|
|
|
|
routerPush({ name: routeName });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetFirstDegreeMenus() {
|
|
|
|
getActiveParentRouteName();
|
|
|
|
hideDrawer();
|
|
|
|
}
|
|
|
|
|
|
|
|
const activeChildMenus = computed(() => {
|
|
|
|
const menus: GlobalMenuOption[] = [];
|
2022-04-01 14:47:57 +08:00
|
|
|
routeStore.menus.some(item => {
|
2022-01-18 01:17:09 +08:00
|
|
|
const flag = item.routeName === activeParentRouteName.value && Boolean(item.children?.length);
|
|
|
|
if (flag) {
|
2022-03-12 16:21:40 +08:00
|
|
|
menus.push(...(item.children || []));
|
2022-01-18 01:17:09 +08:00
|
|
|
}
|
|
|
|
return flag;
|
|
|
|
});
|
|
|
|
return menus;
|
|
|
|
});
|
|
|
|
|
|
|
|
watch(
|
|
|
|
() => route.name,
|
|
|
|
() => {
|
|
|
|
getActiveParentRouteName();
|
|
|
|
},
|
|
|
|
{ immediate: true }
|
|
|
|
);
|
|
|
|
</script>
|
|
|
|
<style scoped></style>
|