Blame view

src/layouts/Logo.vue 2.27 KB
陈文彬 authored
1
<template>
vben authored
2
  <div class="app-logo anticon" @click="handleGoHome" :style="wrapStyle">
陈文彬 authored
3
    <img :src="logo" />
4
    <div v-if="show" class="logo-title ml-2 ellipsis">{{ globSetting.title }}</div>
陈文彬 authored
5
6
7
  </div>
</template>
<script lang="ts">
8
  import { computed, defineComponent, PropType, ref, watch } from 'vue';
陈文彬 authored
9
10
  // hooks
  import { useSetting } from '/@/hooks/core/useSetting';
11
12
  import { useTimeout } from '/@/hooks/core/useTimeout';
  import { useGo } from '/@/hooks/web/usePage';
陈文彬 authored
13
14

  import { PageEnum } from '/@/enums/pageEnum';
15
16
  import { MenuTypeEnum } from '../enums/menuEnum';
陈文彬 authored
17
  import logo from '/@/assets/images/logo.png';
18
19
20

  import { menuStore } from '../store/modules/menu';
  import { appStore } from '../store/modules/app';
陈文彬 authored
21
22
23
24
25
26
27
28
29
30

  export default defineComponent({
    name: 'Logo',
    props: {
      showTitle: {
        type: Boolean as PropType<boolean>,
        default: true,
      },
    },
    setup(props) {
vben authored
31
      const showRef = ref<boolean>(!!props.showTitle);
陈文彬 authored
32
33
      const { globSetting } = useSetting();
      const go = useGo();
vben authored
34
陈文彬 authored
35
36
37
      function handleGoHome() {
        go(PageEnum.BASE_HOME);
      }
vben authored
38
陈文彬 authored
39
40
41
42
43
44
45
46
47
48
49
50
      watch(
        () => props.showTitle,
        (show: boolean) => {
          if (show) {
            useTimeout(() => {
              showRef.value = show;
            }, 280);
          } else {
            showRef.value = show;
          }
        }
      );
vben authored
51
52
53
54
55
56
57
58
59
60
61
62
63
      const wrapStyle = computed(() => {
        const { getCollapsedState } = menuStore;
        const {
          menuSetting: { menuWidth, type },
        } = appStore.getProjectConfig;
        const miniWidth = { minWidth: `${menuWidth}px` };
        if (type !== MenuTypeEnum.SIDEBAR) {
          return miniWidth;
        }
        return getCollapsedState ? {} : miniWidth;
      });
陈文彬 authored
64
65
66
67
68
      return {
        handleGoHome,
        globSetting,
        show: showRef,
        logo,
69
        wrapStyle,
陈文彬 authored
70
71
72
73
      };
    },
  });
</script>
74
75
76
77
78
79
<style lang="less" scoped>
  @import (reference) '../design/index.less';

  .app-logo {
    display: flex;
    align-items: center;
80
    padding-left: 16px;
81
    cursor: pointer;
vben authored
82
    // justify-content: center;
83
84

    .logo-title {
vben authored
85
      font-size: 18px;
86
      font-weight: 400;
vben authored
87
88
      opacity: 0;
      transition: all 0.5s;
89
      .respond-to(medium,{
vben authored
90
       opacity: 1;
91
92
93
94
     });
    }
  }
</style>