CourseListQRPage.vue
2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!--
* @Date: 2025-03-21 14:31:21
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-05-21 16:57:36
* @FilePath: /mlaj/src/views/courses/CourseListQRPage.vue
* @Description: 课程列表页面 - 支持列表和卡片两种显示模式
-->
<template>
<AppLayout title="课程列表">
<div class="pb-16">
<!-- Course List -->
<div class="px-4">
<van-list
v-model:loading="loading"
:finished="finished"
finished-text="没有更多课程了"
@load="onLoad"
class="space-y-4"
>
<!-- 根据type参数显示不同组件 -->
<template v-if="displayType === 'card'">
<CourseImageCard v-for="course in courses" :key="course.id" :course="course" />
</template>
<template v-else>
<CourseCard v-for="course in courses" :key="course.id" :course="course" />
</template>
</van-list>
</div>
</div>
</AppLayout>
</template>
<script setup>
import { ref, onMounted, computed } from 'vue';
import { useRoute } from 'vue-router';
import AppLayout from '@/components/layout/AppLayout.vue';
import CourseCard from '@/components/ui/CourseCard.vue';
import CourseImageCard from '@/components/ui/CourseImageCard.vue';
// 导入接口
import { getCourseListAPI } from "@/api/course";
import { List } from 'vant';
const $route = useRoute();
const courses = ref([]);
const loading = ref(false);
const finished = ref(false);
const limit = ref(5);
const page = ref(0);
// 根据URL参数确定显示类型
const displayType = computed(() => {
return $route.query.type || 'list'; // 默认为list模式
});
// 获取URL参数中的ID
const courseId = computed(() => {
return $route.query.id || '';
});
// Load more courses
const onLoad = async () => {
const nextPage = page.value;
const params = {
limit: limit.value,
page: nextPage
};
// 如果有ID参数,添加到请求中
if (courseId.value) {
params.id = courseId.value;
}
const res = await getCourseListAPI(params);
if (res.code) {
courses.value = [...courses.value, ...res.data];
finished.value = res.data.length < limit.value;
page.value = nextPage + 1;
}
loading.value = false;
};
</script>