hookehuyr

refactor(views): 将MyCoursesPage和MyFavoritesPage封装到AppLayout中

为了提高代码的可维护性和一致性,将MyCoursesPage和MyFavoritesPage的页面内容封装到AppLayout组件中。这样可以统一页面的布局结构,减少重复代码。
1 <!-- 1 <!--
2 * @Date: 2025-03-21 12:17:03 2 * @Date: 2025-03-21 12:17:03
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-04-18 17:30:15 4 + * @LastEditTime: 2025-05-12 09:30:50
5 * @FilePath: /mlaj/src/views/courses/MyCoursesPage.vue 5 * @FilePath: /mlaj/src/views/courses/MyCoursesPage.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
8 <template> 8 <template>
9 - <div class="bg-gradient-to-b from-green-50/70 to-white/90 min-h-screen pb-20"> 9 + <AppLayout>
10 - <!-- Course List --> 10 + <div class="bg-gradient-to-b from-green-50/70 to-white/90 min-h-screen pb-20">
11 - <van-list 11 + <!-- Course List -->
12 - v-model:loading="loading" 12 + <van-list
13 - :finished="finished" 13 + v-model:loading="loading"
14 - finished-text="没有更多了" 14 + :finished="finished"
15 - @load="onLoad" 15 + finished-text="没有更多了"
16 - class="px-4 py-3 space-y-4" 16 + @load="onLoad"
17 - > 17 + class="px-4 py-3 space-y-4"
18 - <CourseCard v-for="course in courses" :key="course.good_id" :course="course" :linkTo="`/studyCourse/${course.good_id}`" /> 18 + >
19 - </van-list> 19 + <CourseCard v-for="course in courses" :key="course.good_id" :course="course" :linkTo="`/studyCourse/${course.good_id}`" />
20 + </van-list>
20 21
21 - <!-- 无数据提示 --> 22 + <!-- 无数据提示 -->
22 - <div v-if="!loading && courses.length === 0" class="flex flex-col items-center justify-center py-12"> 23 + <div v-if="!loading && courses.length === 0" class="flex flex-col items-center justify-center py-12">
23 - <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"> 24 + <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">
24 - <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" /> 25 + <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" />
25 - </svg> 26 + </svg>
26 - <p class="mt-4 text-gray-500">暂无课程记录</p> 27 + <p class="mt-4 text-gray-500">暂无课程记录</p>
28 + </div>
27 </div> 29 </div>
28 - </div> 30 + </AppLayout>
29 </template> 31 </template>
30 32
31 <script setup> 33 <script setup>
...@@ -33,6 +35,7 @@ import { ref } from 'vue'; ...@@ -33,6 +35,7 @@ import { ref } from 'vue';
33 import { useRoute, useRouter } from 'vue-router'; 35 import { useRoute, useRouter } from 'vue-router';
34 import CourseCard from '@/components/ui/CourseCard.vue'; 36 import CourseCard from '@/components/ui/CourseCard.vue';
35 import { useTitle } from '@vueuse/core'; 37 import { useTitle } from '@vueuse/core';
38 +import AppLayout from "@/components/layout/AppLayout.vue";
36 39
37 // 导入接口 40 // 导入接口
38 import { getOrderListAPI } from '@/api/order' 41 import { getOrderListAPI } from '@/api/order'
......
1 <template> 1 <template>
2 - <div class="bg-gradient-to-b from-green-50/70 to-white/90 min-h-screen pb-20"> 2 + <AppLayout>
3 - <!-- 分类切换 --> 3 + <div class="bg-gradient-to-b from-green-50/70 to-white/90 min-h-screen pb-20">
4 - <div class="px-4 py-3"> 4 + <!-- 分类切换 -->
5 - <van-tabs v-model:active="activeTab" @click-tab="onClickTab" sticky swipeable title-active-color="#4caf50" color="#4caf50"> 5 + <div class="px-4 py-3">
6 - <van-tab title="课程" name="courses"> 6 + <van-tabs v-model:active="activeTab" @click-tab="onClickTab" sticky swipeable title-active-color="#4caf50" color="#4caf50">
7 - <van-list 7 + <van-tab title="课程" name="courses">
8 - v-model:loading="coursesLoading" 8 + <van-list
9 - :finished="coursesFinished" 9 + v-model:loading="coursesLoading"
10 - finished-text="没有更多了" 10 + :finished="coursesFinished"
11 - @load="onCoursesLoad" 11 + finished-text="没有更多了"
12 - class="space-y-4 mt-4" 12 + @load="onCoursesLoad"
13 - > 13 + class="space-y-4 mt-4"
14 - <CourseCard v-for="course in favoriteCourses" :key="course.id" :course="course" /> 14 + >
15 - </van-list> 15 + <CourseCard v-for="course in favoriteCourses" :key="course.id" :course="course" />
16 + </van-list>
16 17
17 - <!-- 无数据提示 --> 18 + <!-- 无数据提示 -->
18 - <div v-if="!coursesLoading && favoriteCourses.length === 0" class="flex flex-col items-center justify-center py-12"> 19 + <div v-if="!coursesLoading && favoriteCourses.length === 0" class="flex flex-col items-center justify-center py-12">
19 - <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"> 20 + <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">
20 - <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z" /> 21 + <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z" />
21 - </svg> 22 + </svg>
22 - <p class="mt-4 text-gray-500">暂无收藏课程</p> 23 + <p class="mt-4 text-gray-500">暂无收藏课程</p>
23 - </div> 24 + </div>
24 - </van-tab> 25 + </van-tab>
25 26
26 - <van-tab title="活动" name="activities"> 27 + <van-tab title="活动" name="activities">
27 - <!--<van-list 28 + <!--<van-list
28 - v-model:loading="activitiesLoading" 29 + v-model:loading="activitiesLoading"
29 - :finished="activitiesFinished" 30 + :finished="activitiesFinished"
30 - finished-text="没有更多了" 31 + finished-text="没有更多了"
31 - @load="onActivitiesLoad" 32 + @load="onActivitiesLoad"
32 - class="space-y-4 mt-4" 33 + class="space-y-4 mt-4"
33 - > 34 + >
34 - <ActivityCard v-for="activity in favoriteActivities" :key="activity.id" :activity="activity" /> 35 + <ActivityCard v-for="activity in favoriteActivities" :key="activity.id" :activity="activity" />
35 - </van-list> 36 + </van-list>
36 37
37 - <!~~ 无数据提示 ~~> 38 + <!~~ 无数据提示 ~~>
38 - <div v-if="!activitiesLoading && favoriteActivities.length === 0" class="flex flex-col items-center justify-center py-12"> 39 + <div v-if="!activitiesLoading && favoriteActivities.length === 0" class="flex flex-col items-center justify-center py-12">
39 - <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"> 40 + <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">
40 - <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z" /> 41 + <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z" />
41 - </svg> 42 + </svg>
42 - <p class="mt-4 text-gray-500">暂无收藏活动</p> 43 + <p class="mt-4 text-gray-500">暂无收藏活动</p>
43 - </div>--> 44 + </div>-->
44 - </van-tab> 45 + </van-tab>
45 - </van-tabs> 46 + </van-tabs>
47 + </div>
46 </div> 48 </div>
47 - </div> 49 + </AppLayout>
48 </template> 50 </template>
49 51
50 <script setup> 52 <script setup>
...@@ -54,6 +56,7 @@ import CourseCard from '@/components/ui/CourseCard.vue'; ...@@ -54,6 +56,7 @@ import CourseCard from '@/components/ui/CourseCard.vue';
54 import ActivityCard from '@/components/ui/ActivityCard.vue'; 56 import ActivityCard from '@/components/ui/ActivityCard.vue';
55 import { courses as mockCourses, activities as mockActivities } from '@/utils/mockData'; 57 import { courses as mockCourses, activities as mockActivities } from '@/utils/mockData';
56 import { useTitle } from '@vueuse/core'; 58 import { useTitle } from '@vueuse/core';
59 +import AppLayout from "@/components/layout/AppLayout.vue";
57 60
58 // 导入接口 61 // 导入接口
59 import { getGroupFavoriteListAPI } from '@/api/favorite'; 62 import { getGroupFavoriteListAPI } from '@/api/favorite';
......