vue-vben-admin/src/layouts/logo/index.vue

106 lines
2.5 KiB
Vue
Raw Normal View History

2020-09-28 20:19:10 +08:00
<template>
2020-11-06 22:41:00 +08:00
<div class="app-logo anticon" :class="theme" @click="handleGoHome" :style="wrapStyle">
2020-11-10 21:25:57 +08:00
<img src="/@/assets/images/logo.png" />
2020-10-31 19:51:24 +08:00
<div v-if="show" class="logo-title ml-2 ellipsis">{{ globSetting.title }}</div>
2020-09-28 20:19:10 +08:00
</div>
</template>
<script lang="ts">
2020-10-31 19:51:24 +08:00
import { computed, defineComponent, PropType, ref, watch } from 'vue';
2020-09-28 20:19:10 +08:00
// hooks
2020-11-23 00:35:15 +08:00
import { useGlobSetting } from '/@/settings/use';
2020-11-21 22:47:10 +08:00
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
2020-10-31 19:51:24 +08:00
import { useGo } from '/@/hooks/web/usePage';
2020-09-28 20:19:10 +08:00
import { PageEnum } from '/@/enums/pageEnum';
2020-11-10 23:50:47 +08:00
import { MenuTypeEnum } from '/@/enums/menuEnum';
2020-10-31 19:51:24 +08:00
2020-11-10 23:50:47 +08:00
import { menuStore } from '/@/store/modules/menu';
import { appStore } from '/@/store/modules/app';
2020-09-28 20:19:10 +08:00
export default defineComponent({
name: 'Logo',
props: {
showTitle: {
type: Boolean as PropType<boolean>,
default: true,
},
2020-11-06 22:41:00 +08:00
theme: {
type: String,
},
2020-09-28 20:19:10 +08:00
},
setup(props) {
2020-10-30 21:32:05 +08:00
const showRef = ref<boolean>(!!props.showTitle);
2020-11-23 00:35:15 +08:00
const globSetting = useGlobSetting();
2020-09-28 20:19:10 +08:00
const go = useGo();
2020-10-30 21:32:05 +08:00
2020-09-28 20:19:10 +08:00
function handleGoHome() {
go(PageEnum.BASE_HOME);
}
2020-10-30 21:32:05 +08:00
2020-09-28 20:19:10 +08:00
watch(
() => props.showTitle,
(show: boolean) => {
if (show) {
useTimeoutFn(() => {
2020-09-28 20:19:10 +08:00
showRef.value = show;
}, 280);
} else {
showRef.value = show;
}
}
);
2020-10-30 21:32:05 +08:00
2020-10-31 19:51:24 +08:00
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;
});
2020-09-28 20:19:10 +08:00
return {
handleGoHome,
globSetting,
show: showRef,
2020-10-31 19:51:24 +08:00
wrapStyle,
2020-09-28 20:19:10 +08:00
};
},
});
</script>
2020-10-11 00:05:29 +08:00
<style lang="less" scoped>
2020-11-10 23:50:47 +08:00
@import (reference) '../../design/index.less';
2020-10-11 00:05:29 +08:00
.app-logo {
display: flex;
align-items: center;
2020-10-31 19:51:24 +08:00
padding-left: 16px;
2020-10-11 00:05:29 +08:00
cursor: pointer;
2020-11-03 21:00:14 +08:00
// justify-content: center;
2020-11-06 22:41:00 +08:00
&.light {
border-bottom: 1px solid @border-color-base;
}
2020-10-11 00:05:29 +08:00
.logo-title {
2020-11-03 21:00:14 +08:00
font-size: 18px;
2020-11-03 22:26:26 +08:00
font-weight: 700;
2020-11-03 21:00:14 +08:00
opacity: 0;
transition: all 0.5s;
2020-10-11 00:05:29 +08:00
.respond-to(medium,{
2020-11-03 21:00:14 +08:00
opacity: 1;
2020-10-11 00:05:29 +08:00
});
}
// &.dark .logo-title {
// font-weight: 400;
// }
&.light .logo-title {
color: @primary-color;
}
2020-10-11 00:05:29 +08:00
}
</style>