index.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <el-scrollbar :class="['app-sidebar', collapse && 'is-hide']" view-class="app-sidebar__view">
  3. <div :class="['app-sidebar__header', isMobile ? 'is-show' : collapse && 'is-hide']" v-if="false">
  4. <span class="logo">{{ $t('app.name') }}</span>
  5. </div>
  6. <div class="app-sidebar__menu">
  7. <app-sidemenu :collapse="isMobile ? false : collapse" @click="routerTo" />
  8. </div>
  9. <div :class="['app-sidebar__copyright', isMobile ? 'is-show' : collapse && 'is-hide']" v-if="false">
  10. <span>&copy;{{ year }} Muchinfo</span>
  11. </div>
  12. <div :class="['app-sidebar__mask', collapse && 'is-hide']" @click="hideSidebar()" v-if="isMobile"></div>
  13. </el-scrollbar>
  14. </template>
  15. <script lang="ts" setup>
  16. import { watch } from 'vue'
  17. import { useMenu } from '@/hooks/menu'
  18. import { globalStore } from '@/stores'
  19. import AppSidemenu from '../sidemenu/index.vue'
  20. const emit = defineEmits(['update:collapse'])
  21. defineProps({
  22. // 折叠收起菜单栏
  23. collapse: Boolean,
  24. })
  25. const { router, getChildrenMenus } = useMenu()
  26. const { isMobile } = globalStore.$mapState()
  27. const year = new Date().getFullYear()
  28. const hideSidebar = () => {
  29. if (isMobile.value) {
  30. emit('update:collapse', true)
  31. }
  32. }
  33. // 路由跳转
  34. const routerTo = (active: string) => {
  35. hideSidebar()
  36. const submenus = getChildrenMenus(active)
  37. // 判断是否存在子菜单
  38. if (submenus.length) {
  39. router.push({ name: submenus[0].code })
  40. } else {
  41. router.push({ name: active })
  42. }
  43. }
  44. // 监听设备变化
  45. watch(isMobile, () => hideSidebar())
  46. </script>
  47. <style lang="less">
  48. @import './index.less';
  49. </style>