|
|
@@ -1,64 +1,35 @@
|
|
|
<template>
|
|
|
- <el-scrollbar :class="[ 'app-sidebar', modelValue && 'is-hide' ]" view-class="app-sidebar__view">
|
|
|
+ <el-scrollbar :class="['app-sidebar', modelValue && 'is-hide']" view-class="app-sidebar__view">
|
|
|
<div class="app-sidebar__menu">
|
|
|
<el-menu :default-active="$route.name" :collapse="modelValue" @select="routerTo" unique-opened>
|
|
|
<app-submenu :data-source="menus"></app-submenu>
|
|
|
</el-menu>
|
|
|
</div>
|
|
|
- <div :class="[ 'app-sidebar__mask', modelValue && 'is-hide' ]" @click="hideSidebar(true)" v-if="isMobile"></div>
|
|
|
+ <div :class="['app-sidebar__mask', modelValue && 'is-hide']" @click="hideSidebar(true)" v-if="isMobile"></div>
|
|
|
</el-scrollbar>
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
-import router from "@pc/router"
|
|
|
-import { computed, ref } from "vue"
|
|
|
-import { sessionCache, globalState } from "@/store"
|
|
|
-import { SideMenu } from './interface'
|
|
|
-import AppSubmenu from "../submenu/index.vue"
|
|
|
+import { computed, ref } from 'vue'
|
|
|
+import { useRouter } from 'vue-router'
|
|
|
+import { useMenu } from '@/hooks/menu'
|
|
|
+import { globalState } from '@/store'
|
|
|
+import AppSubmenu from '../submenu/index.vue'
|
|
|
|
|
|
const emit = defineEmits(["update:modelValue"]);
|
|
|
+
|
|
|
defineProps({
|
|
|
// 折叠收起菜单栏
|
|
|
modelValue: Boolean,
|
|
|
-});
|
|
|
-
|
|
|
-const menus = ref<SideMenu[]>([]);
|
|
|
-const hideSidebar = (value: boolean) => {
|
|
|
- emit("update:modelValue", value);
|
|
|
-};
|
|
|
+})
|
|
|
|
|
|
-const getAuthMenu = (): SideMenu[] => {
|
|
|
- const filterRouter = (routes: Ermcp.AccountMenu[], parentPath = ""): SideMenu[] => {
|
|
|
- let result: SideMenu[] = [];
|
|
|
- routes.forEach((item) => {
|
|
|
- let menuPath = item.path;
|
|
|
- if (parentPath) {
|
|
|
- menuPath = [
|
|
|
- parentPath.length > 1 ? parentPath : "",
|
|
|
- "/",
|
|
|
- item.path,
|
|
|
- ].join("");
|
|
|
- }
|
|
|
- const menu: SideMenu = {
|
|
|
- path: menuPath,
|
|
|
- name: item.code,
|
|
|
- label: item.title,
|
|
|
- icon: item.icon,
|
|
|
- };
|
|
|
- if (item.children && item.children.length) {
|
|
|
- const children = filterRouter(item.children, menuPath);
|
|
|
- if (children.length) {
|
|
|
- menu.children = children;
|
|
|
- }
|
|
|
- }
|
|
|
- result = [...result, menu];
|
|
|
- });
|
|
|
- return result;
|
|
|
- };
|
|
|
- return filterRouter(sessionCache.getValue('menus'));
|
|
|
-};
|
|
|
+const { getAuthMenu } = useMenu();
|
|
|
+const router = useRouter();
|
|
|
+const menus = ref(getAuthMenu());
|
|
|
|
|
|
-menus.value = getAuthMenu();
|
|
|
+const hideSidebar = (value: boolean) => {
|
|
|
+ emit('update:modelValue', value);
|
|
|
+}
|
|
|
|
|
|
// 监听设备变化
|
|
|
const isMobile = computed(() => {
|
|
|
@@ -69,13 +40,13 @@ const isMobile = computed(() => {
|
|
|
hideSidebar(false);
|
|
|
}
|
|
|
return flag;
|
|
|
-});
|
|
|
+})
|
|
|
|
|
|
// 菜单跳转
|
|
|
const routerTo = (routerName: string) => {
|
|
|
isMobile.value && hideSidebar(true);
|
|
|
router.replace({ name: routerName });
|
|
|
-};
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
<style lang="less">
|