hookehuyr

refactor(welcome): 优化欢迎页访问逻辑

- 移除自动跳转逻辑:访问根目录或其他页面不再跳转到欢迎页
- 精准拦截:只有访问 /welcome 时才判断是否首次访问
- 首次访问:显示欢迎页并标记已访问
- 再次访问:直接跳转到首页
- 更新文档:说明新的访问逻辑

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
......@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Changed
#### 欢迎页访问逻辑优化
- **调整首次访问检测逻辑**: 不再自动拦截所有页面跳转到欢迎页
- **优化用户体验**: 访问根目录 `/` 时不会跳转到欢迎页
- **精准拦截**: 只有直接访问 `/welcome` 时才判断是否首次访问
- 如果首次访问:显示欢迎页并标记已访问
- 如果已访问过:直接跳转到首页
## [2026-01-28]
### Added
......@@ -17,7 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **新增 WelcomeContent 组件**: 欢迎页内容区域,采用不对称布局展示3个功能入口
- **新增 WelcomeEntryItem 组件**: 可复用的功能入口卡片组件
- **新增 welcomeEntries 配置**: 功能入口配置化管理,支持内部路由和外部链接
- **新增首次访问检测**: 基于 localStorage 的首次访问标志位和路由守卫
- **新增首次访问检测**: 基于 localStorage 的首次访问标志位和路由守卫(仅访问 /welcome 时触发)
- **新增调试工具**: 开发环境下提供 `window.resetWelcomeFlag()``window.showWelcome()` 调试函数
- **新增环境变量**:
- `VITE_WELCOME_PAGE_ENABLED`: 控制欢迎页功能开关
......@@ -42,7 +51,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
#### 欢迎页核心特性
- **视频背景**: 循环播放星空宇宙主题视频,自动生成封面图
- **首次访问检测**: 基于 localStorage,仅首次访问时展示
- **首次访问检测**: 基于 localStorage,仅访问 `/welcome` 时判断是否首次展示
- 首次访问欢迎页:显示欢迎页内容
- 再次访问欢迎页:自动跳转到首页
- **功能入口**: 3个核心功能入口(课程中心、活动中心、个人中心)
- **不对称布局**: 打破完美对称,更自然的视觉效果
- **浮动动画**: 入口图标带有上下浮动动画效果
......
......@@ -25,7 +25,7 @@ const router = createRouter({
// 导航守卫
router.beforeEach(async (to, from, next) => {
// 欢迎页首次访问检测
// 欢迎页访问逻辑
if (import.meta.env.VITE_WELCOME_PAGE_ENABLED === 'true') {
// 重置欢迎页标志(URL 参数)
if (to.query.reset_welcome === 'true') {
......@@ -37,13 +37,15 @@ router.beforeEach(async (to, from, next) => {
return next({ path: to.path, query })
}
// 首次访问检测
if (to.path !== '/welcome' && !hasVisitedWelcome()) {
// 欢迎页访问检测
if (to.path === '/welcome') {
if (hasVisitedWelcome()) {
// 已访问过,跳转到首页
return next('/')
} else {
// 首次访问,标记并显示欢迎页
markWelcomeVisited()
return next({
path: '/welcome',
query: { redirect: to.fullPath }
})
}
}
}
......