diff --git a/schoolNewsWeb/src/utils/route-generator.ts b/schoolNewsWeb/src/utils/route-generator.ts index 0dae56c..c2f82b9 100644 --- a/schoolNewsWeb/src/utils/route-generator.ts +++ b/schoolNewsWeb/src/utils/route-generator.ts @@ -8,7 +8,7 @@ import type { RouteRecordRaw } from 'vue-router'; import type { SysMenu } from '@/types'; import { MenuType } from '@/types/enums'; import { routes } from '@/router'; -import { getResponsiveLayout } from './routeAdapter'; +import { getResponsiveLayout, createResponsiveRoute, type RouteAdapter } from './routeAdapter'; // 预注册所有视图组件,构建时由 Vite 解析并生成按需加载的 chunk const VIEW_MODULES = import.meta.glob('../views/**/*.vue'); @@ -280,7 +280,7 @@ function findFirstMenuWithUrl(menus: SysMenu[]): SysMenu | null { } /** - * 根据组件名称获取组件 + * 根据组件名称获取组件(支持响应式组件) * @param componentName 组件名称/路径 * @returns 组件异步加载函数 */ @@ -302,17 +302,23 @@ function getComponent(componentName: string) { } // 将别名 @/ 转为相对于当前文件的路径,必须与 import.meta.glob 中的模式一致 - componentPath = componentPath.replace(/^@\//, '../'); // => '../views/user/home/HomeView' + const originalPath = componentPath.replace(/^@\//, '../'); // => '../views/user/home/HomeView' // 补全 .vue 后缀 - if (!componentPath.endsWith('.vue')) { - componentPath += '.vue'; + if (!originalPath.endsWith('.vue')) { + componentPath = originalPath + '.vue'; + } else { + componentPath = originalPath; } - // 3. 从 VIEW_MODULES 中查找对应的 loader - const loader = VIEW_MODULES[componentPath]; + // 3. 检查是否有移动端版本 + const mobileComponentPath = componentPath.replace('.vue', '.mobile.vue'); + + // 从 VIEW_MODULES 中查找对应的 loader + const originalLoader = VIEW_MODULES[componentPath]; + const mobileLoader = VIEW_MODULES[mobileComponentPath]; - if (!loader) { + if (!originalLoader) { console.error('[路由生成] 未找到组件模块', { 原始组件名: componentName, 期望路径: componentPath, @@ -322,7 +328,17 @@ function getComponent(componentName: string) { return () => import('@/views/public/error/404.vue'); } - return loader as () => Promise; + // 4. 如果有移动端版本,创建响应式路由适配器 + if (mobileLoader) { + const adapter: RouteAdapter = { + original: originalLoader as () => Promise, + mobile: mobileLoader as () => Promise + }; + return createResponsiveRoute(adapter); + } + + // 5. 没有移动端版本,直接返回原始组件 + return originalLoader as () => Promise; } /** diff --git a/schoolNewsWeb/src/views/public/course/components/CourseDetail.vue b/schoolNewsWeb/src/views/public/course/components/CourseDetail.vue index e92df51..9bb93d9 100644 --- a/schoolNewsWeb/src/views/public/course/components/CourseDetail.vue +++ b/schoolNewsWeb/src/views/public/course/components/CourseDetail.vue @@ -15,7 +15,7 @@
- +
- +
@@ -65,14 +65,6 @@
- - {{ isEnrolled ? '继续学习' : '开始学习' }} - 收藏课程 + + {{ isEnrolled ? '继续学习' : '开始学习' }} + +
@@ -500,6 +501,13 @@ function formatDuration(minutes?: number): string { background: #FFFFFF; border-radius: 10px; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05); + + // 移动端垂直布局 + @media (max-width: 768px) { + flex-direction: column; + gap: 20px; + padding: 20px 16px; + } } } @@ -515,6 +523,12 @@ function formatDuration(minutes?: number): string { height: 100%; object-fit: cover; } + + // 移动端全宽 + @media (max-width: 768px) { + width: 100%; + height: 200px; + } } .course-info { @@ -529,6 +543,11 @@ function formatDuration(minutes?: number): string { gap: 10px; } + // 移动端样式调整 + @media (max-width: 768px) { + gap: 16px; + } + .course-title { font-family: "Source Han Sans SC"; font-weight: 600; @@ -634,6 +653,12 @@ function formatDuration(minutes?: number): string { align-items: center; gap: 27px; + // 移动端按钮布局 - 保持水平排列 + @media (max-width: 768px) { + gap: 12px; + justify-content: space-between; + } + :deep(.el-button) { height: 42px; border-radius: 8px; @@ -651,6 +676,12 @@ function formatDuration(minutes?: number): string { background: #d32f2f; border-color: #d32f2f; } + + // 移动端等宽 + @media (max-width: 768px) { + flex: 1; + width: auto; + } } &.el-button--default { @@ -658,6 +689,12 @@ function formatDuration(minutes?: number): string { border-color: #86909C; color: #86909C; + // 移动端等宽 + @media (max-width: 768px) { + flex: 1; + width: auto; + } + img { width: 20px; height: 20px; diff --git a/schoolNewsWeb/src/views/public/course/components/CourseLearning.vue b/schoolNewsWeb/src/views/public/course/components/CourseLearning.vue index 72609dd..a478d6a 100644 --- a/schoolNewsWeb/src/views/public/course/components/CourseLearning.vue +++ b/schoolNewsWeb/src/views/public/course/components/CourseLearning.vue @@ -22,6 +22,9 @@
+ +
+
-
+ +
+
正在加载更多...
+
已加载全部数据
+
+ +
@@ -42,12 +48,18 @@