From b06703d706b728187bce196cc890e8d2a54c6318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=A6=82=E6=91=B8=E9=B1=BC=E5=8E=BB?= <1780903673@qq.com> Date: Wed, 3 Sep 2025 14:14:03 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=9A=80=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E8=BF=81=E7=A7=BB=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/.vitepress/theme/index.ts | 37 ++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/docs/.vitepress/theme/index.ts b/docs/.vitepress/theme/index.ts index 706a9e58..18a61d86 100644 --- a/docs/.vitepress/theme/index.ts +++ b/docs/.vitepress/theme/index.ts @@ -20,7 +20,7 @@ import CustomFooter from './components/CustomFooter.vue' import SvgImage from './components/SvgImage.vue' import HomeStar from './components/HomeStar.vue' import ExternalLink from './components/ExternalLink.vue' -import ElementPlus from 'element-plus' +import ElementPlus, { ElMessageBox } from 'element-plus' import 'element-plus/dist/index.css' // 声明百度统计全局变量 @@ -46,8 +46,41 @@ export default { app.component('ExternalLink',ExternalLink) app.use(ElementPlus) - // 百度统计路由监听 + // 站点迁移检测 if (typeof window !== 'undefined') { + // 检测是否为旧域名,只在页面首次加载时检测 + const checkSiteMigration = async () => { + if (window.location.hostname === 'wot-design-uni.pages.dev') { + try { + // 使用 Element Plus 的 MessageBox 弹出确认对话框 + await ElMessageBox.confirm( + '站点已迁移至新域名,为了获得更好的访问体验,建议您跳转到新站点。', + '站点迁移通知', + { + confirmButtonText: '立即跳转', + cancelButtonText: '稍后再说', + type: 'warning', + center: true + } + ) + // 用户点击确认后跳转 + // 保持当前路径,只替换域名 + const newUrl = `https://wot-ui.cn${window.location.pathname}${window.location.search}${window.location.hash}` + window.location.href = newUrl + } catch { + // 用户点击取消或关闭对话框,不做任何操作 + } + } + } + + // 页面加载完成后检测 + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', checkSiteMigration) + } else { + checkSiteMigration() + } + + // 百度统计路由监听 // 确保百度统计已加载 const trackPageView = (path: string) => { if (window._hmt) {