Logo.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <div class="app-logo" @click="handleGoHome" :style="wrapStyle">
  3. <img :src="logo" />
  4. <div v-if="show" class="logo-title ml-2 ellipsis">{{ globSetting.title }}</div>
  5. </div>
  6. </template>
  7. <script lang="ts">
  8. import { computed, defineComponent, PropType, ref, watch } from 'vue';
  9. // hooks
  10. import { useSetting } from '/@/hooks/core/useSetting';
  11. import { useTimeout } from '/@/hooks/core/useTimeout';
  12. import { useGo } from '/@/hooks/web/usePage';
  13. import { PageEnum } from '/@/enums/pageEnum';
  14. import { MenuTypeEnum } from '../enums/menuEnum';
  15. import logo from '/@/assets/images/logo.png';
  16. import { menuStore } from '../store/modules/menu';
  17. import { appStore } from '../store/modules/app';
  18. export default defineComponent({
  19. name: 'Logo',
  20. props: {
  21. showTitle: {
  22. type: Boolean as PropType<boolean>,
  23. default: true,
  24. },
  25. },
  26. setup(props) {
  27. const showRef = ref<boolean>(!!props.showTitle);
  28. const { globSetting } = useSetting();
  29. const go = useGo();
  30. function handleGoHome() {
  31. go(PageEnum.BASE_HOME);
  32. }
  33. watch(
  34. () => props.showTitle,
  35. (show: boolean) => {
  36. if (show) {
  37. useTimeout(() => {
  38. showRef.value = show;
  39. }, 280);
  40. } else {
  41. showRef.value = show;
  42. }
  43. }
  44. );
  45. const wrapStyle = computed(() => {
  46. const { getCollapsedState } = menuStore;
  47. const {
  48. menuSetting: { menuWidth, type },
  49. } = appStore.getProjectConfig;
  50. const miniWidth = { minWidth: `${menuWidth}px` };
  51. if (type !== MenuTypeEnum.SIDEBAR) {
  52. return miniWidth;
  53. }
  54. return getCollapsedState ? {} : miniWidth;
  55. });
  56. return {
  57. handleGoHome,
  58. globSetting,
  59. show: showRef,
  60. logo,
  61. wrapStyle,
  62. };
  63. },
  64. });
  65. </script>
  66. <style lang="less" scoped>
  67. @import (reference) '../design/index.less';
  68. .app-logo {
  69. display: flex;
  70. align-items: center;
  71. padding-left: 16px;
  72. cursor: pointer;
  73. .logo-title {
  74. display: none;
  75. font-size: 16px;
  76. font-weight: 400;
  77. .respond-to(medium,{
  78. display: block;
  79. });
  80. }
  81. }
  82. </style>