feat(课程): 添加课程banner接口和轮播组件
实现课程页面的banner轮播功能,从接口动态获取banner数据
Showing
2 changed files
with
35 additions
and
9 deletions
| 1 | /* | 1 | /* |
| 2 | * @Date: 2025-04-15 09:32:07 | 2 | * @Date: 2025-04-15 09:32:07 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-04-18 17:15:52 | 4 | + * @LastEditTime: 2025-06-16 11:34:00 |
| 5 | * @FilePath: /mlaj/src/api/course.js | 5 | * @FilePath: /mlaj/src/api/course.js |
| 6 | * @Description: 课程模块相关接口 | 6 | * @Description: 课程模块相关接口 |
| 7 | */ | 7 | */ |
| ... | @@ -17,6 +17,7 @@ const Api = { | ... | @@ -17,6 +17,7 @@ const Api = { |
| 17 | GROUP_COMMENT_DEL: '/srv/?a=group_comment_del', | 17 | GROUP_COMMENT_DEL: '/srv/?a=group_comment_del', |
| 18 | GROUP_COMMENT_LIKE: '/srv/?a=group_comment_like', | 18 | GROUP_COMMENT_LIKE: '/srv/?a=group_comment_like', |
| 19 | GROUP_COMMENT_DISLIKE: '/srv/?a=group_comment_dislike', | 19 | GROUP_COMMENT_DISLIKE: '/srv/?a=group_comment_dislike', |
| 20 | + GET_COURSE_BANNER: '/srv/?a=get_article_list&sn=BEHALOBANNER', | ||
| 20 | } | 21 | } |
| 21 | 22 | ||
| 22 | /** | 23 | /** |
| ... | @@ -92,3 +93,11 @@ export const addGroupCommentLikeAPI = (params) => fn(fetch.post(Api.GROUP_COMMEN | ... | @@ -92,3 +93,11 @@ export const addGroupCommentLikeAPI = (params) => fn(fetch.post(Api.GROUP_COMMEN |
| 92 | * @return: data: '' | 93 | * @return: data: '' |
| 93 | */ | 94 | */ |
| 94 | export const delGroupCommentLikeAPI = (params) => fn(fetch.post(Api.GROUP_COMMENT_DISLIKE, params)) | 95 | export const delGroupCommentLikeAPI = (params) => fn(fetch.post(Api.GROUP_COMMENT_DISLIKE, params)) |
| 96 | + | ||
| 97 | + | ||
| 98 | +/** | ||
| 99 | + * @description: 获取课程banner | ||
| 100 | + * @param {*} params | ||
| 101 | + * @returns | ||
| 102 | + */ | ||
| 103 | +export const getCourseBannerAPI = (params) => fn(fetch.get(Api.GET_COURSE_BANNER, params)) | ... | ... |
| ... | @@ -8,19 +8,31 @@ | ... | @@ -8,19 +8,31 @@ |
| 8 | 8 | ||
| 9 | <!-- Featured Course Banner --> | 9 | <!-- Featured Course Banner --> |
| 10 | <div class="px-4 mb-5"> | 10 | <div class="px-4 mb-5"> |
| 11 | - <div class="relative rounded-xl overflow-hidden shadow-lg h-40"> | 11 | + <van-swipe |
| 12 | + class="rounded-xl overflow-hidden shadow-lg h-40" | ||
| 13 | + :autoplay="3000" | ||
| 14 | + :show-indicators="true" | ||
| 15 | + indicator-color="rgba(255, 255, 255, 0.5)" | ||
| 16 | + indicator-active-color="#fbbf24" | ||
| 17 | + > | ||
| 18 | + <van-swipe-item | ||
| 19 | + v-for="(banner, index) in bannerList" | ||
| 20 | + :key="index" | ||
| 21 | + class="relative" | ||
| 22 | + > | ||
| 12 | <img | 23 | <img |
| 13 | - src="https://cdn.ipadbiz.cn/mlaj/images/featured-course.jpg" | 24 | + :src="banner.banner || 'https://cdn.ipadbiz.cn/mlaj/images/featured-course.jpg'" |
| 14 | - alt="传承之道" | 25 | + :alt="banner.title || '课程横幅'" |
| 15 | class="w-full h-full object-cover" | 26 | class="w-full h-full object-cover" |
| 16 | /> | 27 | /> |
| 17 | <div | 28 | <div |
| 18 | class="absolute inset-0 bg-gradient-to-b from-transparent to-black/50 flex flex-col justify-end p-4" | 29 | class="absolute inset-0 bg-gradient-to-b from-transparent to-black/50 flex flex-col justify-end p-4" |
| 19 | > | 30 | > |
| 20 | - <h2 class="text-3xl font-bold text-amber-400 drop-shadow-md">传承之道</h2> | 31 | + <h2 class="text-3xl font-bold text-amber-400 drop-shadow-md">{{ banner.post_title }}</h2> |
| 21 | - <p class="text-xl text-white font-semibold drop-shadow-sm">大理鸡足山游学</p> | 32 | + <p class="text-xl text-white font-semibold drop-shadow-sm">{{ banner.post_excerpt }}</p> |
| 22 | - </div> | ||
| 23 | </div> | 33 | </div> |
| 34 | + </van-swipe-item> | ||
| 35 | + </van-swipe> | ||
| 24 | </div> | 36 | </div> |
| 25 | 37 | ||
| 26 | <!-- Today's Live --> | 38 | <!-- Today's Live --> |
| ... | @@ -92,15 +104,20 @@ import { featuredCourse, liveStreams } from "@/utils/mockData"; | ... | @@ -92,15 +104,20 @@ import { featuredCourse, liveStreams } from "@/utils/mockData"; |
| 92 | import { useTitle } from '@vueuse/core'; | 104 | import { useTitle } from '@vueuse/core'; |
| 93 | 105 | ||
| 94 | // 导入接口 | 106 | // 导入接口 |
| 95 | -import { getCourseListAPI } from "@/api/course"; | 107 | +import { getCourseListAPI, getCourseBannerAPI } from "@/api/course"; |
| 96 | 108 | ||
| 97 | -const courses = ref([]) | 109 | +const courses = ref([]); |
| 110 | +const bannerList = ref([]); | ||
| 98 | 111 | ||
| 99 | onMounted(async () => { | 112 | onMounted(async () => { |
| 100 | const res = await getCourseListAPI({ limit: 4 }); | 113 | const res = await getCourseListAPI({ limit: 4 }); |
| 101 | if (res.code) { | 114 | if (res.code) { |
| 102 | courses.value = res.data; | 115 | courses.value = res.data; |
| 103 | } | 116 | } |
| 117 | + const bannerRes = await getCourseBannerAPI(); | ||
| 118 | + if (bannerRes.code) { | ||
| 119 | + bannerList.value = bannerRes.list; | ||
| 120 | + } | ||
| 104 | }) | 121 | }) |
| 105 | 122 | ||
| 106 | const $route = useRoute(); | 123 | const $route = useRoute(); | ... | ... |
-
Please register or login to post a comment