修正多处问题,添加骨架屏
This commit is contained in:
@@ -75,6 +75,8 @@ import { ref, onMounted } from 'vue'
|
||||
import { onShow } from '@dcloudio/uni-app'
|
||||
import { getActiveRecommendCourses } from '@/api/groupCourse.js'
|
||||
|
||||
import { getCourseCoverUrl } from '@/utils/request.js'
|
||||
|
||||
console.log('[RecommendCourses] 组件脚本已加载')
|
||||
|
||||
// 推荐课程数据列表
|
||||
@@ -99,12 +101,8 @@ const getCourseLevel = (course) => {
|
||||
return '初级'
|
||||
}
|
||||
|
||||
// 处理图片URL
|
||||
const getImageUrl = (coverImage) => {
|
||||
if (!coverImage) return 'https://images.unsplash.com/photo-1534438327276-14e5300c3a48?w=400&q=80'
|
||||
if (coverImage.startsWith('http')) return coverImage
|
||||
return `https://your-domain.com${coverImage}`
|
||||
}
|
||||
// 处理图片URL - 已由 getOssUrl 工具函数处理
|
||||
// 使用 @/utils/request.js 中的 getOssUrl 替代
|
||||
|
||||
// 获取推荐课程
|
||||
const fetchRecommendCourses = async () => {
|
||||
@@ -112,6 +110,10 @@ const fetchRecommendCourses = async () => {
|
||||
try {
|
||||
const res = await getActiveRecommendCourses()
|
||||
console.log('[RecommendCourses] API 返回:', JSON.stringify(res).substring(0, 200))
|
||||
if (res && Array.isArray(res) && res.length > 0) {
|
||||
console.log('[RecommendCourses] 第一项 groupCourse.coverImage:', JSON.stringify(res[0]?.groupCourse?.coverImage))
|
||||
console.log('[RecommendCourses] 第一项完整 groupCourse:', JSON.stringify(res[0]?.groupCourse))
|
||||
}
|
||||
if (res && Array.isArray(res)) {
|
||||
// 提取推荐中的 groupCourse,只排除已满员的课程(已结束的仍展示,点击时拦截)
|
||||
const filteredCourses = res.filter(recommend => {
|
||||
@@ -125,9 +127,17 @@ const fetchRecommendCourses = async () => {
|
||||
// 只取前3个符合条件的推荐课程
|
||||
courses.value = filteredCourses.slice(0, 3).map(recommend => {
|
||||
const course = recommend.groupCourse
|
||||
const rawCover = course.coverImage
|
||||
const finalImage = getCourseCoverUrl(rawCover) || 'https://images.unsplash.com/photo-1534438327276-14e5300c3a48?w=400&q=80'
|
||||
console.log('[RecommendCourses] 封面URL映射:', {
|
||||
'courseName': course.courseName,
|
||||
'原始coverImage': rawCover,
|
||||
'转换后URL': finalImage,
|
||||
'是否为完整URL': finalImage.startsWith('http')
|
||||
})
|
||||
return {
|
||||
id: course.id,
|
||||
image: getImageUrl(course.coverImage),
|
||||
image: finalImage,
|
||||
name: course.courseName || '未知课程',
|
||||
duration: calculateDuration(course.startTime, course.endTime),
|
||||
level: getCourseLevel(course),
|
||||
|
||||
Reference in New Issue
Block a user