From 39261866312ca0fcf0bea8aa4ca34dc7f3d3c748 Mon Sep 17 00:00:00 2001 From: luckyasme <807254037@qq.com> Date: Fri, 14 Mar 2025 16:07:13 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?gitee?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/GiteeViewSource.vue | 49 +++++++++++++++++++ docs/.vitepress/src/layouts/LayoutDoc.vue | 43 ---------------- 2 files changed, 49 insertions(+), 43 deletions(-) diff --git a/docs/.vitepress/src/components/GiteeViewSource.vue b/docs/.vitepress/src/components/GiteeViewSource.vue index cd85af7..e40403b 100644 --- a/docs/.vitepress/src/components/GiteeViewSource.vue +++ b/docs/.vitepress/src/components/GiteeViewSource.vue @@ -3,8 +3,10 @@ import { onMounted, ref, watch } from 'vue'; import { isClient, OIcon } from '@opensig/opendesign'; import IconOutLink from '~icons/app/icon-outlink.svg'; + import { getGiteeUrl } from '@/utils/common'; import { useMenuStore } from '@/stores/menu'; +import { useScreen } from '@/composables/useScreen'; const menuStore = useMenuStore(); const giteeUrl = ref(''); @@ -21,6 +23,53 @@ watch( onMounted(() => { giteeUrl.value = getGiteeUrl(); }); + +// -------------------- 移动端插入gitee -------------------- +const { isPhone } = useScreen(); + +const insertGiteeBtn = () => { + if (isPhone.value) { + const link = document.querySelector('.markdown-body .gitee') as HTMLAnchorElement; + if (link) { + link.href = getGiteeUrl(); + return; + } + + const titleDom = document.querySelector('.markdown-body h1'); + if (titleDom && titleDom.nextSibling) { + titleDom.style.margin = '0'; + const container = document.createElement('div'); + container.className = 'article-detail-container'; + const a = document.createElement('a'); + a.className = 'gitee'; + a.href = getGiteeUrl(); + a.target = '_blank'; + a.textContent = '在Gitee上查看源文件'; + const svgString = ` + + + + + + `; + const parser = new DOMParser(); + const svgDoc = parser.parseFromString(svgString, "image/svg+xml"); + a.appendChild(svgDoc.documentElement); + container.appendChild(a); + titleDom.nextSibling.parentNode?.insertBefore(container, titleDom.nextSibling); + } + } else { + const link = document.querySelector('.markdown-body .gitee') as HTMLAnchorElement; + if (link) { + link.remove(); + } + } +}; + +watch(isPhone, () => { + console.log('updated'); + insertGiteeBtn(); +});