index.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <template>
  2. <el-scrollbar :class="['app-sidebar', collapse && 'is-hide']" view-class="app-sidebar__view">
  3. <div :class="['app-sidebar__header', state.isMobile ? 'is-show' : collapse && 'is-hide']">
  4. <span class="logo">{{ $t('app.name') }}</span>
  5. </div>
  6. <div class="app-sidebar__menu">
  7. <app-sidemenu :collapse="state.isMobile ? false : collapse" @click="routerTo" />
  8. </div>
  9. <div :class="['app-sidebar__copyright', state.isMobile ? 'is-show' : collapse && 'is-hide']">
  10. <span>&copy;{{ year }} Muchinfo</span>
  11. </div>
  12. <div :class="['app-sidebar__mask', collapse && 'is-hide']" @click="hideSidebar()" v-if="state.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 client from '@/utils/client'
  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 { state } = client
  27. const year = new Date().getFullYear()
  28. const hideSidebar = () => {
  29. emit('update:collapse', state.isMobile)
  30. }
  31. // 路由跳转
  32. const routerTo = (active: string) => {
  33. hideSidebar()
  34. const submenus = getChildrenMenus(active)
  35. // 判断是否存在子菜单
  36. if (submenus.length) {
  37. router.push({ name: submenus[0].code })
  38. } else {
  39. router.push({ name: active })
  40. }
  41. }
  42. // 监听设备变化
  43. watch(() => state.isMobile, () => hideSidebar())
  44. </script>
  45. <style lang="less">
  46. @import './index.less';
  47. </style>