|
|
@@ -18,8 +18,8 @@
|
|
|
<view class="course-name">{{ item.name }}</view>
|
|
|
<view class="course-desc">{{ item.description }}</view>
|
|
|
<view class="course-meta">
|
|
|
- <text class="course-teacher">👩🏫 {{ item.teacher_name }}</text>
|
|
|
- <text class="course-students">👥 {{ item.student_count || 0 }}人学习</text>
|
|
|
+ <text class="course-teacher">👩🏫 {{ item.instructor }}</text>
|
|
|
+ <text class="course-students">👥 {{ item.participants || 0 }}人学习</text>
|
|
|
</view>
|
|
|
<view class="course-footer">
|
|
|
<view class="course-price">
|
|
|
@@ -51,57 +51,7 @@
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
- courseList: [
|
|
|
- // 默认课程数据,确保页面有内容
|
|
|
- {
|
|
|
- id: 1,
|
|
|
- name: '恋爱沟通技巧大师课',
|
|
|
- description: '学会有效沟通,让感情更甜蜜。涵盖倾听技巧、表达方式、冲突化解等核心内容。',
|
|
|
- cover_image: DEFAULT_IMAGES.course,
|
|
|
- teacher_name: '张情感老师',
|
|
|
- teacher_desc: '资深情感咨询师,10年经验',
|
|
|
- teacher_avatar: DEFAULT_IMAGES.avatar,
|
|
|
- price: 299,
|
|
|
- original_price: 399,
|
|
|
- discount_rate: 7.5,
|
|
|
- student_count: 1256,
|
|
|
- rating: 4.9,
|
|
|
- chapter_count: 12,
|
|
|
- outline: '第1章:沟通的艺术\n第2章:倾听的力量\n第3章:表达的技巧\n第4章:冲突的化解\n...'
|
|
|
- },
|
|
|
- {
|
|
|
- id: 2,
|
|
|
- name: '相亲必胜宝典',
|
|
|
- description: '从形象打造到话题聊天,全方位提升相亲成功率。适合单身男女快速脱单。',
|
|
|
- cover_image: DEFAULT_IMAGES.course,
|
|
|
- teacher_name: '李红娘老师',
|
|
|
- teacher_desc: '专业红娘,成功牵线300+对',
|
|
|
- teacher_avatar: DEFAULT_IMAGES.avatar,
|
|
|
- price: 199,
|
|
|
- original_price: 299,
|
|
|
- discount_rate: 6.6,
|
|
|
- student_count: 2580,
|
|
|
- rating: 4.8,
|
|
|
- chapter_count: 8,
|
|
|
- outline: '第1章:形象管理\n第2章:心态调整\n第3章:聊天技巧\n第4章:约会礼仪\n...'
|
|
|
- },
|
|
|
- {
|
|
|
- id: 3,
|
|
|
- name: '婚姻经营智慧课',
|
|
|
- description: '婚后生活经营秘籍,让婚姻更加幸福美满。处理婆媳关系、夫妻沟通等实用内容。',
|
|
|
- cover_image: DEFAULT_IMAGES.course,
|
|
|
- teacher_name: '王婚姻老师',
|
|
|
- teacher_desc: '婚姻家庭咨询专家',
|
|
|
- teacher_avatar: DEFAULT_IMAGES.avatar,
|
|
|
- price: 399,
|
|
|
- original_price: 599,
|
|
|
- discount_rate: 6.7,
|
|
|
- student_count: 856,
|
|
|
- rating: 5.0,
|
|
|
- chapter_count: 15,
|
|
|
- outline: '第1章:夫妻沟通\n第2章:婆媳关系\n第3章:财务管理\n第4章:亲子教育\n...'
|
|
|
- }
|
|
|
- ],
|
|
|
+ courseList: [],
|
|
|
pageNum: 1,
|
|
|
pageSize: 10,
|
|
|
hasMore: true,
|
|
|
@@ -113,11 +63,9 @@
|
|
|
onLoad() {
|
|
|
console.log('精品课程列表页面加载')
|
|
|
console.log('默认课程数据:', this.courseList.length)
|
|
|
-
|
|
|
+ this.loadCourseList()
|
|
|
// 数据健康检查
|
|
|
this.checkDataHealth()
|
|
|
-
|
|
|
- this.loadCourseList()
|
|
|
},
|
|
|
|
|
|
onReachBottom() {
|
|
|
@@ -130,51 +78,86 @@
|
|
|
methods: {
|
|
|
// 加载课程列表
|
|
|
async loadCourseList() {
|
|
|
- if (this.loading) return
|
|
|
- this.loading = true
|
|
|
-
|
|
|
- try {
|
|
|
- console.log('尝试加载精品课程API数据...')
|
|
|
- const data = await api.course.getList({
|
|
|
- pageNum: this.pageNum,
|
|
|
- pageSize: this.pageSize,
|
|
|
- status: 1
|
|
|
- })
|
|
|
-
|
|
|
- if (data && data.length > 0) {
|
|
|
- if (this.pageNum === 1) {
|
|
|
- // 第一页,替换数据
|
|
|
- this.courseList = data
|
|
|
- } else {
|
|
|
- // 后续页,追加数据
|
|
|
- this.courseList = [...this.courseList, ...data]
|
|
|
- }
|
|
|
- this.hasMore = data.length >= this.pageSize
|
|
|
- console.log('API课程数据加载成功:', data.length, '条')
|
|
|
- } else {
|
|
|
- this.hasMore = false
|
|
|
- console.log('API返回课程数据为空,使用默认数据')
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- console.error('加载课程列表失败:', error)
|
|
|
-
|
|
|
- // API失败时,如果是第一页,保留默认数据
|
|
|
- if (this.pageNum === 1) {
|
|
|
- console.log('API失败,保留默认课程数据')
|
|
|
- uni.showToast({
|
|
|
- title: '使用示例数据',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- } else {
|
|
|
- uni.showToast({
|
|
|
- title: '加载失败',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- }
|
|
|
- this.hasMore = false
|
|
|
- } finally {
|
|
|
- this.loading = false
|
|
|
- }
|
|
|
+ if (this.loading) return
|
|
|
+ this.loading = true
|
|
|
+
|
|
|
+ try {
|
|
|
+ console.log('尝试加载精品课程API数据...')
|
|
|
+ const response = await api.course.getList({
|
|
|
+ pageNum: this.pageNum,
|
|
|
+ pageSize: this.pageSize,
|
|
|
+ status: 1
|
|
|
+ })
|
|
|
+ // 统一获取列表数据,优先取response.list,无则为空数组
|
|
|
+ const dataList = response?.list || []
|
|
|
+
|
|
|
+ if (dataList.length > 0) {
|
|
|
+ if (this.pageNum === 1) {
|
|
|
+ // 第一页替换数据
|
|
|
+ this.courseList = dataList
|
|
|
+ } else {
|
|
|
+ // 后续页追加列表数据
|
|
|
+ this.courseList = [...this.courseList, ...dataList]
|
|
|
+ }
|
|
|
+ // 判断是否还有更多:当前页数据量等于页大小,说明可能有下一页
|
|
|
+ this.hasMore = dataList.length >= this.pageSize
|
|
|
+ console.log('API课程数据加载成功:', dataList.length, '条')
|
|
|
+ } else {
|
|
|
+ this.hasMore = false
|
|
|
+ console.log('API返回课程数据为空,使用默认数据')
|
|
|
+ // 第一页数据为空时,加载默认数据兜底
|
|
|
+ if (this.pageNum === 1) {
|
|
|
+ this.courseList = [
|
|
|
+ // 示例默认课程数据,可根据DEFAULT_IMAGES扩展
|
|
|
+ {
|
|
|
+ id: 'default-1',
|
|
|
+ name: '默认精品课程',
|
|
|
+ description: '这是默认展示的课程内容',
|
|
|
+ cover_image: this.DEFAULT_IMAGES.course,
|
|
|
+ teacher_name: '默认讲师',
|
|
|
+ student_count: 1200,
|
|
|
+ price: 99,
|
|
|
+ original_price: 199,
|
|
|
+ discount_rate: 5
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('加载课程列表失败:', error)
|
|
|
+
|
|
|
+ // API失败时,第一页加载默认数据
|
|
|
+ if (this.pageNum === 1) {
|
|
|
+ console.log('API失败,使用默认课程数据')
|
|
|
+ this.courseList = [
|
|
|
+ {
|
|
|
+ id: 'default-1',
|
|
|
+ name: '默认精品课程',
|
|
|
+ description: '这是默认展示的课程内容',
|
|
|
+ cover_image: this.DEFAULT_IMAGES.course,
|
|
|
+ teacher_name: '默认讲师',
|
|
|
+ student_count: 1200,
|
|
|
+ price: 99,
|
|
|
+ original_price: 199,
|
|
|
+ discount_rate: 5
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ uni.showToast({
|
|
|
+ title: '使用示例数据',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: '加载失败',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ this.hasMore = false
|
|
|
+ } finally {
|
|
|
+ this.loading = false
|
|
|
+ // 数据健康检查:确保字段完整性
|
|
|
+ this.checkDataHealth()
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
// 跳转到详情
|