From a899d7322778b937d7d5b86272b89c5d2c665324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E5=88=BA=E8=9E=88?= Date: Tue, 26 Nov 2024 14:43:23 +0800 Subject: [PATCH] feat: BodyScrollbar --- docs/.vitepress/components/BodyScrollbar.vue | 184 +++++++++++++++++++ docs/.vitepress/theme/index.ts | 25 +++ 2 files changed, 209 insertions(+) create mode 100644 docs/.vitepress/components/BodyScrollbar.vue diff --git a/docs/.vitepress/components/BodyScrollbar.vue b/docs/.vitepress/components/BodyScrollbar.vue new file mode 100644 index 0000000..38c4e82 --- /dev/null +++ b/docs/.vitepress/components/BodyScrollbar.vue @@ -0,0 +1,184 @@ + + diff --git a/docs/.vitepress/theme/index.ts b/docs/.vitepress/theme/index.ts index db18e09..bc1fbc5 100644 --- a/docs/.vitepress/theme/index.ts +++ b/docs/.vitepress/theme/index.ts @@ -2,7 +2,16 @@ import 'uno.css'; import type { Theme } from 'vitepress'; import DefaultTheme from 'vitepress/theme'; import components from '../components'; +import BodyScrollbar from '../components/BodyScrollbar.vue'; import './custom.css'; +import { + Fragment, + h, + Teleport, + defineComponent, + shallowRef, + onMounted, +} from 'vue'; // 兼容旧链接/短链重定向 if (!import.meta.env.SSR) { @@ -31,8 +40,24 @@ if (!import.meta.env.SSR) { } } +const ScrollbarWrapper = defineComponent(() => { + const show = shallowRef(false); + onMounted(() => { + const isMobile = 'ontouchstart' in document.documentElement; + show.value = !isMobile; + }); + return () => { + return show.value + ? h(Teleport, { to: document.body }, h(BodyScrollbar)) + : undefined; + }; +}); + export default { extends: DefaultTheme, + Layout() { + return h(Fragment, null, [h(DefaultTheme.Layout), h(ScrollbarWrapper)]); + }, enhanceApp({ app }) { Object.entries(components).forEach(([name, component]) => { app.component(name, component);