hookehuyr

feat(首页): 添加推荐内容随机显示功能

在首页的推荐内容部分,增加随机显示功能,用户点击“换一批”按钮时,会随机显示不同的推荐内容,提升用户体验
...@@ -17,7 +17,11 @@ export const userRecommendations = [ ...@@ -17,7 +17,11 @@ export const userRecommendations = [
17 { title: "亲子阅读技巧入门", duration: "15分钟", image: "https://cdn.ipadbiz.cn/mlaj/images/zMRLZh40kms.jpg" }, 17 { title: "亲子阅读技巧入门", duration: "15分钟", image: "https://cdn.ipadbiz.cn/mlaj/images/zMRLZh40kms.jpg" },
18 { title: "3-6岁孩子的情绪管理", duration: "20分钟", image: "https://cdn.ipadbiz.cn/mlaj/images/27kCu7bXGEI.jpg" }, 18 { title: "3-6岁孩子的情绪管理", duration: "20分钟", image: "https://cdn.ipadbiz.cn/mlaj/images/27kCu7bXGEI.jpg" },
19 { title: "趣味数学启蒙课", duration: "12分钟", image: "https://cdn.ipadbiz.cn/mlaj/images/jbwr0qZvpD4.jpg" }, 19 { title: "趣味数学启蒙课", duration: "12分钟", image: "https://cdn.ipadbiz.cn/mlaj/images/jbwr0qZvpD4.jpg" },
20 - { title: "儿童英语绘本故事", duration: "18分钟", image: "https://cdn.ipadbiz.cn/mlaj/images/GGCP6vshpPY.jpg" } 20 + { title: "儿童英语绘本故事", duration: "18分钟", image: "https://cdn.ipadbiz.cn/mlaj/images/GGCP6vshpPY.jpg" },
21 + { title: "*亲子阅读技巧入门", duration: "15分钟", image: "https://cdn.ipadbiz.cn/mlaj/images/zMRLZh40kms.jpg" },
22 + { title: "*3-6岁孩子的情绪管理", duration: "20分钟", image: "https://cdn.ipadbiz.cn/mlaj/images/27kCu7bXGEI.jpg" },
23 + { title: "*趣味数学启蒙课", duration: "12分钟", image: "https://cdn.ipadbiz.cn/mlaj/images/jbwr0qZvpD4.jpg" },
24 + { title: "*儿童英语绘本故事", duration: "18分钟", image: "https://cdn.ipadbiz.cn/mlaj/images/GGCP6vshpPY.jpg" },
21 ]; 25 ];
22 26
23 // Live streaming sessions 27 // Live streaming sessions
......
1 <!-- 1 <!--
2 * @Date: 2025-03-20 19:55:21 2 * @Date: 2025-03-20 19:55:21
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-03-24 18:10:32 4 + * @LastEditTime: 2025-03-25 15:57:15
5 * @FilePath: /mlaj/src/views/HomePage.vue 5 * @FilePath: /mlaj/src/views/HomePage.vue
6 * @Description: 亲子学院首页组件 6 * @Description: 亲子学院首页组件
7 * 7 *
...@@ -287,7 +287,10 @@ ...@@ -287,7 +287,10 @@
287 <section class="mb-7"> 287 <section class="mb-7">
288 <div class="flex justify-between items-center mb-3"> 288 <div class="flex justify-between items-center mb-3">
289 <h3 class="font-medium">为您推荐</h3> 289 <h3 class="font-medium">为您推荐</h3>
290 - <button class="text-xs text-gray-500 flex items-center"> 290 + <button
291 + class="text-xs text-gray-500 flex items-center"
292 + @click="displayedRecommendations = getRecommendations(true)"
293 + >
291 换一批 294 换一批
292 <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3 ml-1" fill="none" viewBox="0 0 24 24" stroke="currentColor"> 295 <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3 ml-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
293 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" /> 296 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
...@@ -296,7 +299,7 @@ ...@@ -296,7 +299,7 @@
296 </div> 299 </div>
297 <div class="grid grid-cols-2 gap-4"> 300 <div class="grid grid-cols-2 gap-4">
298 <FrostedGlass 301 <FrostedGlass
299 - v-for="(item, index) in userRecommendations" 302 + v-for="(item, index) in displayedRecommendations"
300 :key="index" 303 :key="index"
301 class="p-3 rounded-xl" 304 class="p-3 rounded-xl"
302 > 305 >
...@@ -553,6 +556,21 @@ const checkInContent = ref('') // 打卡内容 ...@@ -553,6 +556,21 @@ const checkInContent = ref('') // 打卡内容
553 const currentSlide = ref(0) // 当前轮播图索引 556 const currentSlide = ref(0) // 当前轮播图索引
554 const isCheckingIn = ref(false) // 打卡提交状态 557 const isCheckingIn = ref(false) // 打卡提交状态
555 const checkInSuccess = ref(false) // 打卡成功状态 558 const checkInSuccess = ref(false) // 打卡成功状态
559 +const displayedRecommendations = ref([]) // 当前显示的推荐内容
560 +
561 +// 获取推荐内容
562 +const getRecommendations = (random = false) => {
563 + if (random) {
564 + const shuffled = [...userRecommendations].sort(() => 0.5 - Math.random())
565 + return shuffled.slice(0, 4)
566 + }
567 + return userRecommendations.slice(0, 4)
568 +}
569 +
570 +// 初始化显示推荐内容
571 +onMounted(() => {
572 + displayedRecommendations.value = getRecommendations()
573 +})
556 const carouselRef = ref(null) // 轮播图容器引用 574 const carouselRef = ref(null) // 轮播图容器引用
557 575
558 // 右侧导航组件:搜索和消息通知 576 // 右侧导航组件:搜索和消息通知
......