| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <template>
- <el-scrollbar :class="['app-sidebar', collapse && 'is-hide']" view-class="app-sidebar__view">
- <div :class="['app-sidebar__header', isMobile ? 'is-show' : collapse && 'is-hide']" v-if="false">
- <span class="logo">{{ $t('app.name') }}</span>
- </div>
- <div class="app-sidebar__menu">
- <app-sidemenu :collapse="isMobile ? false : collapse" @click="routerTo" />
- </div>
- <div :class="['app-sidebar__copyright', isMobile ? 'is-show' : collapse && 'is-hide']" v-if="false">
- <span>©{{ year }} Muchinfo</span>
- </div>
- <div :class="['app-sidebar__mask', collapse && 'is-hide']" @click="hideSidebar()" v-if="isMobile"></div>
- </el-scrollbar>
- </template>
- <script lang="ts" setup>
- import { watch } from 'vue'
- import { useMenu } from '@/hooks/menu'
- import { globalStore } from '@/stores'
- import AppSidemenu from '../sidemenu/index.vue'
- const emit = defineEmits(['update:collapse'])
- defineProps({
- // 折叠收起菜单栏
- collapse: Boolean,
- })
- const { router, getChildrenMenus } = useMenu()
- const { isMobile } = globalStore.$mapState()
- const year = new Date().getFullYear()
- const hideSidebar = () => {
- if (isMobile.value) {
- emit('update:collapse', true)
- }
- }
- // 路由跳转
- const routerTo = (active: string) => {
- hideSidebar()
- const submenus = getChildrenMenus(active)
- // 判断是否存在子菜单
- if (submenus.length) {
- router.push({ name: submenus[0].code })
- } else {
- router.push({ name: active })
- }
- }
- // 监听设备变化
- watch(isMobile, () => hideSidebar())
- </script>
- <style lang="less">
- @import './index.less';
- </style>
|