问题:上一版页脚改为流内元素后,功能页出现莫名滚动条。实测根因=页脚在流内占位 (margin-top40+高41=81px),把'内容刚好一屏'的功能页(848/900)顶出27px。实测/hash-text 溢出27px、隐藏页脚后=0,页脚是唯一成因。 改法:BaseLayout 加 fixedFooter 开关,功能页(tool.layout.vue -> <BaseLayout fixed-footer>) 页脚 position:fixed 固定视口底部;首页等仍流内最底部。 - fixed 态不占文档流 -> /hash-text 等多余滚动条消失(27->0) - 功能页内容底部补 padding-bottom:56px,避免滚到底时压住最后一块内容(余量25px起) 对齐修正:固定页脚默认以视口居中(720),首页静态页脚居中于内容区(840,侧栏240px), 切换页面横向跳动120px -> .content 加 transform:translateZ(0) 建立包含块,两边偏差均为0 验证(20个功能页):fixed/padB56/距底12/居中偏差0/单行/滚到底无遮挡(余25-477px)全通过; 受控页试用浮条在顶部与页脚无冲突;非功能页(/,/about,/pricing)仍 static
339 lines
9.7 KiB
Vue
339 lines
9.7 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();
|
||
|
||
// 页脚模式:默认随内容排在页面最底部(首页等);功能页传入 fixedFooter 改为固定在视口底部
|
||
const props = withDefaults(defineProps<{ fixedFooter?: boolean }>(), { fixedFooter: false });
|
||
|
||
// 已登录用户每次打开页面:自动拉取一次云端数据(收藏/记录/对话等跨设备恢复)
|
||
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,
|
||
]);
|
||
|
||
// 右下角回到顶部火箭
|
||
const showTop = ref(false);
|
||
// 页面可能有多层 .n-layout-scroll-container(嵌套 n-layout),外层往往不滚、内层才滚;
|
||
// 全部绑定,任一层滚动超过阈值即显示,避免挂在不滚的那层导致火箭永不出现
|
||
const scrollEls: Element[] = [];
|
||
function onWinScroll() {
|
||
showTop.value = scrollEls.some((el) => el.scrollTop > 300);
|
||
}
|
||
function scrollToTop() {
|
||
const el = scrollEls.find((e) => e.scrollTop > 0) ?? scrollEls[0];
|
||
el?.scrollTo({ top: 0, behavior: 'smooth' });
|
||
}
|
||
function bindTopScroll() {
|
||
document.querySelectorAll('.n-layout-scroll-container').forEach((el) => {
|
||
if (!scrollEls.includes(el)) {
|
||
scrollEls.push(el);
|
||
el.addEventListener('scroll', onWinScroll, { passive: true });
|
||
}
|
||
});
|
||
}
|
||
onMounted(() => {
|
||
// 等布局渲染后再绑定滚动容器(内层容器可能晚于挂载出现,多试几次)
|
||
let tries = 0;
|
||
const timer = setInterval(() => {
|
||
bindTopScroll();
|
||
tries++;
|
||
if (scrollEls.length >= 2 || tries >= 10) clearInterval(timer);
|
||
}, 300);
|
||
});
|
||
onBeforeUnmount(() => {
|
||
scrollEls.forEach((el) => el.removeEventListener('scroll', onWinScroll));
|
||
});
|
||
</script>
|
||
|
||
<template>
|
||
<MenuLayout class="menu-layout" :class="{ isSmallScreen: styleStore.isSmallScreen, 'fixed-footer': props.fixedFooter }">
|
||
<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>
|
||
</template>
|
||
|
||
<template #content>
|
||
<div class="top-nav" 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 />
|
||
|
||
<!-- 页脚:功能页固定在底部,其它页随内容排在页面最底部 -->
|
||
<div class="footer" :class="{ fixed: props.fixedFooter }">
|
||
<span>© {{ new Date().getFullYear() }} IT-TOOLS-PRO</span>
|
||
<span class="footer-sep">·</span>
|
||
<span>
|
||
<c-link target="_blank" rel="noopener" href="https://nav.88531.cn">🚀 更多应用尽在 nav.88531.cn</c-link>
|
||
</span>
|
||
</div>
|
||
|
||
<!-- 右下角回到顶部火箭 -->
|
||
<button v-show="showTop" class="back-top" title="回到顶部" aria-label="回到顶部" @click="scrollToTop">🚀</button>
|
||
</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;
|
||
// }
|
||
|
||
// 右下角回到顶部火箭(页脚已改为底部居中,右下角不再冲突,恢复原始位置)
|
||
.back-top {
|
||
position: fixed;
|
||
right: 26px;
|
||
bottom: 26px;
|
||
z-index: 400;
|
||
width: 50px;
|
||
height: 50px;
|
||
border: none;
|
||
border-radius: 50%;
|
||
background: linear-gradient(48deg, #0e9384, #14b8a6);
|
||
color: #fff;
|
||
font-size: 22px;
|
||
line-height: 1;
|
||
cursor: pointer;
|
||
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
|
||
transition: transform 0.18s, box-shadow 0.18s;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
|
||
&:hover {
|
||
transform: translateY(-4px);
|
||
box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
|
||
}
|
||
|
||
&:active {
|
||
transform: translateY(-1px);
|
||
}
|
||
}
|
||
|
||
.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 {
|
||
margin-top: 40px;
|
||
padding: 0 0 22px;
|
||
text-align: center;
|
||
color: #838587;
|
||
font-size: 12px;
|
||
line-height: 1.55;
|
||
white-space: nowrap; // 强制单行,不折行
|
||
user-select: none;
|
||
|
||
.footer-sep {
|
||
margin: 0 8px;
|
||
opacity: 0.55;
|
||
}
|
||
|
||
:deep(a) {
|
||
color: #838587;
|
||
text-decoration: none;
|
||
|
||
&:hover {
|
||
color: #0e9384;
|
||
}
|
||
}
|
||
|
||
// 功能页:固定在视口底部居中;不再占据文档流,因此不会把"刚好一屏"的页面顶出滚动条
|
||
&.fixed {
|
||
position: fixed;
|
||
left: 0;
|
||
right: 0;
|
||
bottom: 12px;
|
||
z-index: 350;
|
||
margin: 0;
|
||
padding: 0;
|
||
pointer-events: none; // 不拦截下方内容点击,仅链接可点
|
||
|
||
:deep(a) {
|
||
pointer-events: auto;
|
||
}
|
||
}
|
||
}
|
||
|
||
/* 功能页:内容底部留出页脚高度,避免滚到底时页脚压住最后一块内容 */
|
||
.menu-layout.fixed-footer :deep(.content .n-layout-scroll-container) {
|
||
padding-bottom: 56px;
|
||
}
|
||
|
||
// 顶部导航:滚动时固定在最顶部(sticky),通栏贴顶遮挡滚动内容
|
||
.top-nav {
|
||
position: sticky;
|
||
// -26px 抵消滚动容器 padding-top 内缩,使导航真正贴到视口最顶(0)
|
||
top: -26px;
|
||
z-index: 200;
|
||
// 通栏:抵消滚动容器的 26px padding
|
||
margin: -26px -26px 0 -26px;
|
||
padding: 12px 26px;
|
||
background: v-bind('themeVars.bodyColor');
|
||
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.08);
|
||
flex-shrink: 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>
|