Files
it-tools-pro/src/layouts/base.layout.vue
T
personal82555 311ab1b139 fix(footer): 功能页页脚改为独立底栏,显示在功能区外且不产生滚动条
上一版遗留两问题:
1) 页脚压住内容:/json-prettify 底部工具行 828-877、页脚 869-888 -> 实际被压住
2) 滚动条:上一版用 padding-bottom:56px 留白,而撑满视口型工具高度按
   window.innerHeight-top-12 算(正好到888),888+56=944>900 -> 凭空多44px滚动条

改法(预留独立底栏,不用 padding):
- base.layout.vue 功能页滚动区 height:calc(100% - 44px)、padding-bottom:0 -> 滚动区缩到856
  页脚固定在其下方独立底栏(869-888),不在功能区之内
- 12个撑满视口工具(json-viewer/label-designer/ai-chat/translator/image-ocr/pdf-ocr/
  doc-convert/pdf-tools/image-tools/code-reader/site-bookmarks/ai-retouch/barcode-batch-generator)
  高度改为按滚动区底边计算,不再用 window.innerHeight,随底栏自动收缩

验证(20个功能页):fixed / 页脚在滚动区外(856<869) / 滚到底零遮挡(余13-421px) 全通过;
12个页面滚动条由有变无;仅4个内容本身超长页保留滚动条(/ai-chat,/emoji-picker,
/text-to-image,/encryption)且底部不被遮挡;视觉核验 /json-prettify 底部工具行完整可见
2026-10-15 11:18:54 +08:00

342 lines
10 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<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;
}
}
// 功能页:固定在视口底部居中,且滚动区为其预留一条独立底栏(见 MenuLayout 的 height 规则),
// 因此既不占文档流(不会把"刚好一屏"的页面顶出滚动条),也不会压在工具内容之上
&.fixed {
position: fixed;
left: 0;
right: 0;
bottom: 12px;
z-index: 350;
margin: 0;
padding: 0;
pointer-events: none; // 不拦截下方内容点击,仅链接可点
:deep(a) {
pointer-events: auto;
}
}
}
// 功能页:内容滚动区高度 = 100% - 底栏(44px),让页脚显示在功能区域外面,且不产生滚动条
// (注意:不能用 padding-bottom 留白,那会把"刚好一屏"的页面顶出滚动条)
.menu-layout.fixed-footer :deep(.content .n-layout-scroll-container) {
height: calc(100% - 44px);
padding-bottom: 0;
}
// 顶部导航:滚动时固定在最顶部(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>