feat(router): 添加我的课程页面路由和组件
在路由配置中添加了 `/profile/courses` 路径,并创建了 `MyCoursesPage.vue` 组件,用于展示用户的课程列表。该组件使用了 `van-list` 实现分页加载功能,并提供了无数据时的提示界面。
Showing
2 changed files
with
61 additions
and
0 deletions
| ... | @@ -90,6 +90,12 @@ const routes = [ | ... | @@ -90,6 +90,12 @@ const routes = [ |
| 90 | props: true, | 90 | props: true, |
| 91 | meta: { title: '结账' } | 91 | meta: { title: '结账' } |
| 92 | }, | 92 | }, |
| 93 | + { | ||
| 94 | + path: '/profile/courses', | ||
| 95 | + name: 'MyCourses', | ||
| 96 | + component: () => import('../views/courses/MyCoursesPage.vue'), | ||
| 97 | + meta: { title: '我的课程' } | ||
| 98 | + }, | ||
| 93 | ] | 99 | ] |
| 94 | 100 | ||
| 95 | const router = createRouter({ | 101 | const router = createRouter({ | ... | ... |
src/views/courses/MyCoursesPage.vue
0 → 100644
| 1 | +<template> | ||
| 2 | + <div class="bg-gradient-to-b from-green-50/70 to-white/90 min-h-screen pb-20"> | ||
| 3 | + <!-- Course List --> | ||
| 4 | + <van-list | ||
| 5 | + v-model:loading="loading" | ||
| 6 | + :finished="finished" | ||
| 7 | + finished-text="没有更多了" | ||
| 8 | + @load="onLoad" | ||
| 9 | + class="px-4 py-3 space-y-4" | ||
| 10 | + > | ||
| 11 | + <CourseCard v-for="course in courses" :key="course.id" :course="course" /> | ||
| 12 | + </van-list> | ||
| 13 | + | ||
| 14 | + <!-- 无数据提示 --> | ||
| 15 | + <div v-if="!loading && courses.length === 0" class="flex flex-col items-center justify-center py-12"> | ||
| 16 | + <svg xmlns="http://www.w3.org/2000/svg" class="h-16 w-16 text-gray-300" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | ||
| 17 | + <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2" /> | ||
| 18 | + </svg> | ||
| 19 | + <p class="mt-4 text-gray-500">暂无课程记录</p> | ||
| 20 | + </div> | ||
| 21 | + </div> | ||
| 22 | +</template> | ||
| 23 | + | ||
| 24 | +<script setup> | ||
| 25 | +import { ref } from 'vue'; | ||
| 26 | +import { useRoute, useRouter } from 'vue-router'; | ||
| 27 | +import CourseCard from '@/components/ui/CourseCard.vue'; | ||
| 28 | +import { courses as mockCourses } from '@/utils/mockData'; | ||
| 29 | +import { useTitle } from '@vueuse/core'; | ||
| 30 | + | ||
| 31 | +const $route = useRoute(); | ||
| 32 | +const $router = useRouter(); | ||
| 33 | +useTitle($route.meta.title); | ||
| 34 | +const courses = ref([]) | ||
| 35 | +const loading = ref(false) | ||
| 36 | +const finished = ref(false) | ||
| 37 | +const page = ref(1) | ||
| 38 | +const pageSize = 10 | ||
| 39 | + | ||
| 40 | +const onLoad = () => { | ||
| 41 | + loading.value = true | ||
| 42 | + // 模拟异步加载数据 | ||
| 43 | + setTimeout(() => { | ||
| 44 | + const start = (page.value - 1) * pageSize | ||
| 45 | + const end = start + pageSize | ||
| 46 | + const newCourses = mockCourses.slice(start, end) | ||
| 47 | + courses.value.push(...newCourses) | ||
| 48 | + loading.value = false | ||
| 49 | + if (courses.value.length >= mockCourses.length) { | ||
| 50 | + finished.value = true | ||
| 51 | + } | ||
| 52 | + page.value++ | ||
| 53 | + }, 1000) | ||
| 54 | +} | ||
| 55 | +</script> |
-
Please register or login to post a comment