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