hookehuyr

fix(课程页面): 修复课程目录滚动容器引用错误并优化代码格式

修复StudyDetailPage中滚动容器引用未定义的问题,添加正确的ref引用
移除CourseDetailPage中多余的空行,保持代码整洁
...@@ -269,7 +269,7 @@ const toggleFavorite = async () => { ...@@ -269,7 +269,7 @@ const toggleFavorite = async () => {
269 // Curriculum items 269 // Curriculum items
270 const curriculumItems = computed(() => { 270 const curriculumItems = computed(() => {
271 if (!course.value) return []; 271 if (!course.value) return [];
272 - 272 +
273 return [ 273 return [
274 { title: '课程特色', active: activeTab.value === '课程特色', show: !!course.value.feature }, 274 { title: '课程特色', active: activeTab.value === '课程特色', show: !!course.value.feature },
275 { title: '课程大纲', active: activeTab.value === '课程大纲', show: !!(course.value.schedule && course.value.schedule.length > 0) }, 275 { title: '课程大纲', active: activeTab.value === '课程大纲', show: !!(course.value.schedule && course.value.schedule.length > 0) },
...@@ -368,13 +368,13 @@ onMounted(async () => { ...@@ -368,13 +368,13 @@ onMounted(async () => {
368 isFavorite.value = foundCourse.is_favorite; 368 isFavorite.value = foundCourse.is_favorite;
369 isPurchased.value = foundCourse.is_buy; 369 isPurchased.value = foundCourse.is_buy;
370 isReviewed.value = foundCourse.is_comment; 370 isReviewed.value = foundCourse.is_comment;
371 - 371 +
372 // 设置默认选中的 tab,确保选中的 tab 有内容 372 // 设置默认选中的 tab,确保选中的 tab 有内容
373 const availableTabs = curriculumItems.value; 373 const availableTabs = curriculumItems.value;
374 if (availableTabs.length > 0 && !availableTabs.some(item => item.title === activeTab.value)) { 374 if (availableTabs.length > 0 && !availableTabs.some(item => item.title === activeTab.value)) {
375 activeTab.value = availableTabs[0].title; 375 activeTab.value = availableTabs[0].title;
376 } 376 }
377 - 377 +
378 // 获取评论列表 378 // 获取评论列表
379 await fetchCommentList() 379 await fetchCommentList()
380 } else { 380 } else {
......
...@@ -215,7 +215,7 @@ ...@@ -215,7 +215,7 @@
215 </div> 215 </div>
216 216
217 <!-- 可滚动的目录列表 --> 217 <!-- 可滚动的目录列表 -->
218 - <div class="flex-1 overflow-y-auto px-4 py-2"> 218 + <div ref="scrollContainer" class="flex-1 overflow-y-auto px-4 py-2" style="overflow-y: scroll;">
219 <div v-if="course_lessons.length" class="space-y-4"> 219 <div v-if="course_lessons.length" class="space-y-4">
220 <div v-for="(lesson, index) in course_lessons" :key="index" @click="handleLessonClick(lesson)" 220 <div v-for="(lesson, index) in course_lessons" :key="index" @click="handleLessonClick(lesson)"
221 class="bg-white p-4 cursor-pointer hover:bg-gray-50 transition-colors border-b border-gray-200 relative"> 221 class="bg-white p-4 cursor-pointer hover:bg-gray-50 transition-colors border-b border-gray-200 relative">
...@@ -252,7 +252,7 @@ import dayjs from 'dayjs'; ...@@ -252,7 +252,7 @@ import dayjs from 'dayjs';
252 import { formatDate } from '@/utils/tools' 252 import { formatDate } from '@/utils/tools'
253 import axios from 'axios'; 253 import axios from 'axios';
254 import { v4 as uuidv4 } from "uuid"; 254 import { v4 as uuidv4 } from "uuid";
255 - 255 +import { useIntersectionObserver } from '@vueuse/core';
256 import PdfPreview from '@/components/ui/PdfPreview.vue'; 256 import PdfPreview from '@/components/ui/PdfPreview.vue';
257 257
258 // 导入接口 258 // 导入接口
...@@ -272,6 +272,8 @@ const audioPlayerRef = ref(null); ...@@ -272,6 +272,8 @@ const audioPlayerRef = ref(null);
272 const showCommentPopup = ref(false); 272 const showCommentPopup = ref(false);
273 const popupComment = ref(''); 273 const popupComment = ref('');
274 274
275 +const scrollContainer = ref(null);
276 +
275 // 课程目录相关 277 // 课程目录相关
276 const course_lessons = ref([]); 278 const course_lessons = ref([]);
277 const course_type_maps = ref({ 279 const course_type_maps = ref({
...@@ -870,7 +872,7 @@ watch(showCatalog, (newVal) => { ...@@ -870,7 +872,7 @@ watch(showCatalog, (newVal) => {
870 const lessonTop = selectedLesson.offsetTop; 872 const lessonTop = selectedLesson.offsetTop;
871 const lessonHeight = selectedLesson.clientHeight; 873 const lessonHeight = selectedLesson.clientHeight;
872 const scrollTop = lessonTop - (containerHeight / 2) + (lessonHeight / 2); 874 const scrollTop = lessonTop - (containerHeight / 2) + (lessonHeight / 2);
873 - 875 +
874 // 平滑滚动到指定位置 876 // 平滑滚动到指定位置
875 scrollContainer.scrollTo({ 877 scrollContainer.scrollTo({
876 top: scrollTop, 878 top: scrollTop,
......