Files
it-tools-pro/src/layouts/base.layout.vue
T

217 lines
5.9 KiB
Vue

<script lang="ts" setup>
import { NIcon, useThemeVars } from 'naive-ui';
import { RouterLink } from 'vue-router';
import { Heart, Home2, Key, Menu2 } from '@vicons/tabler';
import { storeToRefs } from 'pinia';
import HeroGradient from '../assets/hero-gradient.svg?component';
import MenuLayout from '../components/MenuLayout.vue';
import NavbarButtons from '../components/NavbarButtons.vue';
import { useStyleStore } from '@/stores/style.store';
import { useCloudSync } from '@/composable/cloud-sync';
import { config } from '@/config';
import type { ToolCategory } from '@/tools/tools.types';
import { useToolStore } from '@/tools/tools.store';
import { useTracker } from '@/modules/tracker/tracker.services';
import CollapsibleToolMenu from '@/components/CollapsibleToolMenu.vue';
import UserMenu from '@/components/UserMenu.vue';
const themeVars = useThemeVars();
const styleStore = useStyleStore();
// 已登录用户每次打开页面:自动拉取一次云端数据(收藏/记录/对话等跨设备恢复)
const { syncNow, isLoggedIn } = useCloudSync();
if (isLoggedIn.value) {
setTimeout(() => syncNow(), 1500);
}
const version = config.app.version;
const commitSha = config.app.lastCommitSha.slice(0, 7);
const { tracker } = useTracker();
const { t } = useI18n();
const toolStore = useToolStore();
const { favoriteTools, toolsByCategory } = storeToRefs(toolStore);
// 全屏页面:不显示工具侧边栏
const NO_SIDEBAR = new Set(['/user-center', '/admin']);
const fullBleed = computed(() => NO_SIDEBAR.has(route.path));
const favoriteCategory = computed<ToolCategory | null>(() =>
favoriteTools.value.length > 0 ? { name: t('tools.categories.favorite-tools'), components: favoriteTools.value } : null,
);
const tools = computed<ToolCategory[]>(() => [
...toolsByCategory.value,
]);
</script>
<template>
<MenuLayout class="menu-layout" :class="{ isSmallScreen: styleStore.isSmallScreen }">
<template #sider>
<RouterLink to="/" class="hero-wrapper">
<HeroGradient class="gradient" />
<div class="text-wrapper">
<div class="title">
IT-TOOLS-PRO
</div>
<div class="divider" />
<div class="subtitle">
{{ $t('home.subtitle') }}
</div>
</div>
</RouterLink>
<div class="sider-content">
<div v-if="styleStore.isSmallScreen" flex flex-col items-center>
<locale-selector w="90%" />
<div flex justify-center>
<NavbarButtons />
</div>
</div>
<CollapsibleToolMenu :tools-by-category="tools" :favorite-category="favoriteCategory" />
<div class="footer">
<div>
© {{ new Date().getFullYear() }} IT-TOOLS-PRO
</div>
<div>
<c-link target="_blank" rel="noopener" href="https://nav.88531.cn">
🚀 更多应用尽在 nav.88531.cn
</c-link>
</div>
</div>
</div>
</template>
<template #content>
<div flex items-center justify-center gap-2>
<c-button
circle
variant="text"
:aria-label="$t('home.toggleMenu')"
@click="styleStore.isMenuCollapsed = !styleStore.isMenuCollapsed"
>
<NIcon size="25" :component="Menu2" />
</c-button>
<c-tooltip :tooltip="$t('home.home')" position="bottom">
<c-button to="/" circle variant="text" :aria-label="$t('home.home')">
<NIcon size="25" :component="Home2" />
</c-button>
</c-tooltip>
<c-tooltip :tooltip="$t('home.uiLib')" position="bottom">
<c-button v-if="config.app.env === 'development'" to="/c-lib" circle variant="text" :aria-label="$t('home.uiLib')">
<icon-mdi:brush-variant text-20px />
</c-button>
</c-tooltip>
<command-palette />
<locale-selector v-if="!styleStore.isSmallScreen" />
<div>
<NavbarButtons v-if="!styleStore.isSmallScreen" />
</div>
<UserMenu />
<c-tooltip position="bottom" :tooltip="'查看授权功能与购买'">
<RouterLink to="/pricing" class="pricing-link">
<c-button
round
class="support-button"
:bordered="false"
>
授权应用
<NIcon v-if="!styleStore.isSmallScreen" :component="Key" ml-2 />
</c-button>
</RouterLink>
</c-tooltip>
</div>
<slot />
</template>
</MenuLayout>
</template>
<style lang="less" scoped>
// ::v-deep(.n-layout-scroll-container) {
// @percent: 4%;
// @position: 25px;
// @size: 50px;
// @color: #eeeeee25;
// background-image: radial-gradient(@color @percent, transparent @percent),
// radial-gradient(@color @percent, transparent @percent);
// background-position: 0 0, @position @position;
// background-size: @size @size;
// }
.support-button {
background: rgb(37, 99, 108);
background: linear-gradient(48deg, rgba(37, 99, 108, 1) 0%, rgba(59, 149, 111, 1) 60%, rgba(20, 160, 88, 1) 100%);
color: #fff !important;
transition: padding ease 0.2s !important;
&:hover {
color: #fff;
padding-left: 30px;
padding-right: 30px;
}
}
.footer {
text-align: center;
color: #838587;
margin-top: 20px;
padding: 20px 0;
}
.sider-content {
padding-top: 160px;
padding-bottom: 200px;
}
.hero-wrapper {
position: absolute;
display: block;
left: 0;
width: 100%;
z-index: 10;
overflow: hidden;
.gradient {
margin-top: -65px;
}
.text-wrapper {
position: absolute;
left: 0;
width: 100%;
text-align: center;
top: 16px;
color: #fff;
.title {
font-size: 25px;
font-weight: 600;
}
.divider {
width: 50px;
height: 2px;
border-radius: 4px;
background-color: v-bind('themeVars.primaryColor');
margin: 0 auto 5px;
}
.subtitle {
font-size: 16px;
}
}
}
</style>