Просмотр исходного кода

课程标题渲染分组以及视频渲染

丸子 9 месяцев назад
Родитель
Сommit
908fbaeb45
1 измененных файлов с 50 добавлено и 68 удалено
  1. 50 68
      src/views/AIDevelop.vue

+ 50 - 68
src/views/AIDevelop.vue

@@ -272,25 +272,6 @@ const toggleDrawer = () => {
   drawerVisible.value = !drawerVisible.value
   drawerVisible.value = !drawerVisible.value
 }
 }
 
 
-// 定义映射
-// const videoMap = {
-//   '1-1': video1,
-//   '1-2': video2,
-//   '1-3': video3,
-//   '1-4': video4,
-//   '1-5': video5,
-//   '1-6': video6,
-//   '1-7': video7,
-//   '1-8': video8,
-//   '1-9': video9,
-//   '1-10': video10,
-//   '1-11': video11,
-//   '1-12': video12,
-//   '1-13': video13,
-//   '1-14': video14,
-//   '1-15': video15
-// }
-
 // 返回上一页
 // 返回上一页
 const goBack = () => {
 const goBack = () => {
   router.go(-1)
   router.go(-1)
@@ -306,17 +287,18 @@ const videoSrc = ref('')
 // 新增视频路径映射
 // 新增视频路径映射
 const videoPathMap = ref({})
 const videoPathMap = ref({})
 
 
+// 渲染 课程数据结构 以及 视频
 onMounted(async () => {
 onMounted(async () => {
   const typeId = router.currentRoute.value.query.typeId
   const typeId = router.currentRoute.value.query.typeId
   console.log(typeId, "----")
   console.log(typeId, "----")
   if (typeId) {
   if (typeId) {
     try {
     try {
-      // 取课程数据并添加错误处理
+      // 取课程数据
       const res = await ClassType(typeId)
       const res = await ClassType(typeId)
       courseList.value = res.data
       courseList.value = res.data
       console.log("课程数据:", courseList.value)
       console.log("课程数据:", courseList.value)
 
 
-       // 构建视频路径映射
+      // 构建视频路径映射
       videoPathMap.value = courseList.value.reduce((map, item, index) => {
       videoPathMap.value = courseList.value.reduce((map, item, index) => {
         const idx = `1-${index + 1}`
         const idx = `1-${index + 1}`
         if (item.courseVideoPath) {
         if (item.courseVideoPath) {
@@ -332,14 +314,49 @@ onMounted(async () => {
         smallTitle.value = courseList.value[0].courseName
         smallTitle.value = courseList.value[0].courseName
       }
       }
 
 
-      // 将接口数据中的 courseName 转换为菜单格式
-      menuItems.value = courseList.value.map((item, index) => {
-        const idx = `1-${index + 1}`
-        return {
-          index: idx,
-          title: item.courseName
+      // 按 courseLabel 分组
+      const groupedByLabel = {};
+      courseList.value.forEach(item => {
+        if (!groupedByLabel[item.courseLabel]) {
+          groupedByLabel[item.courseLabel] = [];
         }
         }
-      })
+        groupedByLabel[item.courseLabel].push(item);
+      });
+
+      // 对每个组按 courseOrder 排序
+      Object.keys(groupedByLabel).forEach(label => {
+        groupedByLabel[label].sort((a, b) => a.courseOrder - b.courseOrder);
+      });
+
+      // 构建新的 menuItems 结构
+      menuItems.value = [];
+      Object.keys(groupedByLabel).forEach((label, labelIndex) => {
+        const groupItems = groupedByLabel[label];
+        // 检查是否是知识分解组(图灵测试到大模型时代)
+        const isKnowledgeGroup = groupItems.some(item => 
+          ['图灵测试', '大模型时代'].includes(item.courseName)
+        );
+        if (isKnowledgeGroup) {
+          // 构建知识分解组的树型结构
+          menuItems.value.push({
+            index: `${labelIndex + 1}`,
+            title: '知识讲解',
+            children: groupItems.map((item, index) => ({
+              index: `${labelIndex + 1}-${index + 1}`,
+              title: item.courseName
+            }))
+          });
+        } else {
+          // 普通组直接添加菜单项
+          groupItems.forEach((item, index) => {
+            const idx = `${labelIndex + 1}-${index + 1}`;
+            menuItems.value.push({
+              index: idx,
+              title: item.courseName
+            });
+          });
+        }
+      });
     } catch (error) {
     } catch (error) {
       console.error("获取课程数据失败:", error)
       console.error("获取课程数据失败:", error)
     }
     }
@@ -354,38 +371,12 @@ onMounted(async () => {
 const handleOpen = () => {}
 const handleOpen = () => {}
 const handleClose = () => {}
 const handleClose = () => {}
 
 
-// 动态渲染树型结构
-// const menuItems = ref([
-//   { index: '1-1', title: '课前回顾' },
-//   { index: '1-2', title: '课程引入' },
-//   {
-//     index: '1',
-//     title: '知识讲解',
-//     children: [
-//       { index: '1-3', title: '图灵测试' },
-//       { index: '1-4', title: '课堂提问' },
-//       { index: '1-5', title: '达特茅斯会议' },
-//       { index: '1-6', title: '课堂选择' },
-//       { index: '1-7', title: '聊天机器人' },
-//       { index: '1-8', title: '专家系统' },
-//       { index: '1-9', title: '课堂互动' },
-//       { index: '1-10', title: '互联网快速发展' },
-//       { index: '1-11', title: '黄金时代' },
-//       { index: '1-12', title: '课堂提问' },
-//       { index: '1-13', title: '大模型时代' }
-//     ]
-//   },
-//   { index: '1-14', title: '趣味实操' },
-//   { index: '1-15', title: '课程总结' }
-// ])
-
 // 当前播放的索引
 // 当前播放的索引
 const currentIndex = ref('1-1')
 const currentIndex = ref('1-1')
 
 
 // 渲染课程标题到视频上方
 // 渲染课程标题到视频上方
 const smallTitle = ref('课前回顾')
 const smallTitle = ref('课前回顾')
 const handleSelect = index => {
 const handleSelect = index => {
-
   const findTitle = items => {
   const findTitle = items => {
     for (const item of items) {
     for (const item of items) {
       if (item.index === index) {
       if (item.index === index) {
@@ -409,7 +400,6 @@ const handleSelect = index => {
     videoSrc.value = videoPathMap.value[index]
     videoSrc.value = videoPathMap.value[index]
     currentIndex.value = index
     currentIndex.value = index
   }
   }
-
   //测试账号禁用视频
   //测试账号禁用视频
   if (disableVideo())return;
   if (disableVideo())return;
 }
 }
@@ -434,7 +424,6 @@ const flattenMenuItems = () => {
 const playNextVideo = () => {
 const playNextVideo = () => {
   //测试账号禁用视频
   //测试账号禁用视频
   if (disableVideo())return;
   if (disableVideo())return;
-
   const allIndices = flattenMenuItems()
   const allIndices = flattenMenuItems()
   const currentIndexInList = allIndices.indexOf(currentIndex.value)
   const currentIndexInList = allIndices.indexOf(currentIndex.value)
   if (currentIndexInList !== -1 && currentIndexInList < allIndices.length - 1) {
   if (currentIndexInList !== -1 && currentIndexInList < allIndices.length - 1) {
@@ -458,7 +447,6 @@ const playNextVideo = () => {
 const playPreviousVideo = () => {
 const playPreviousVideo = () => {
   //测试账号禁用视频
   //测试账号禁用视频
   if (disableVideo())return;
   if (disableVideo())return;
-
   const allIndices = flattenMenuItems()
   const allIndices = flattenMenuItems()
   const currentIndexInList = allIndices.indexOf(currentIndex.value)
   const currentIndexInList = allIndices.indexOf(currentIndex.value)
   if (currentIndexInList > 0) {
   if (currentIndexInList > 0) {
@@ -472,11 +460,11 @@ const playPreviousVideo = () => {
     }
     }
   }
   }
 }
 }
+
 // 尝试播放视频,处理浏览器自动播放限制
 // 尝试播放视频,处理浏览器自动播放限制
 const tryPlayVideo = () => {
 const tryPlayVideo = () => {
   //测试账号禁用视频
   //测试账号禁用视频
   if (disableVideo())return;
   if (disableVideo())return;
-
   const playPromise = videoRef.value.play()
   const playPromise = videoRef.value.play()
   if (playPromise !== undefined) {
   if (playPromise !== undefined) {
     playPromise.catch(error => {
     playPromise.catch(error => {
@@ -496,22 +484,17 @@ const checkVideoPermission = () => {
 //禁用视频
 //禁用视频
 const disableVideo = () => {
 const disableVideo = () => {
   let dis = ["1-6","1-7","1-8","1-9","1-10","1-11","1-12","1-13","1-14","1-15"]
   let dis = ["1-6","1-7","1-8","1-9","1-10","1-11","1-12","1-13","1-14","1-15"]
-
   if (localStorage.getItem('userName') === "aiTest" &&
   if (localStorage.getItem('userName') === "aiTest" &&
       dis.indexOf(currentIndex.value) !== -1) {
       dis.indexOf(currentIndex.value) !== -1) {
-
     if (videoRef.value) {
     if (videoRef.value) {
       videoRef.value.pause()
       videoRef.value.pause()
-
       // 禁用视频进度条拖拽功能
       // 禁用视频进度条拖拽功能
       const handleSeeking = () => {
       const handleSeeking = () => {
         videoRef.value.pause()
         videoRef.value.pause()
         Message().notifyWarning('您的账号并未开放此课程,禁止拖动进度条!', true)
         Message().notifyWarning('您的账号并未开放此课程,禁止拖动进度条!', true)
       }
       }
-
       // 添加 seeking 事件监听器
       // 添加 seeking 事件监听器
       videoRef.value.addEventListener('seeking', handleSeeking)
       videoRef.value.addEventListener('seeking', handleSeeking)
-
       // 当视频源改变时,移除事件监听器,避免影响其他视频
       // 当视频源改变时,移除事件监听器,避免影响其他视频
       const removeListener = () => {
       const removeListener = () => {
         videoRef.value.removeEventListener('seeking', handleSeeking)
         videoRef.value.removeEventListener('seeking', handleSeeking)
@@ -519,7 +502,6 @@ const disableVideo = () => {
       }
       }
       videoRef.value.addEventListener('loadedmetadata', removeListener)
       videoRef.value.addEventListener('loadedmetadata', removeListener)
     }
     }
-
     //提示禁用// 显示消息框
     //提示禁用// 显示消息框
     Message().notifyWarning('您的账号并未开放此课程!', true)
     Message().notifyWarning('您的账号并未开放此课程!', true)
     return true
     return true
@@ -702,6 +684,7 @@ const handleTimeUpdate = () => {
     })
     })
   }
   }
 }
 }
+
 // 关闭试题弹框
 // 关闭试题弹框
 const handleCloseQuestionDialog = () => {
 const handleCloseQuestionDialog = () => {
   questionDialogVisible.value = false
   questionDialogVisible.value = false
@@ -748,7 +731,6 @@ const handleAIClick = () => {
     sendMessage()
     sendMessage()
     userMessage.value = ''
     userMessage.value = ''
   }
   }
-
   showAIDialog.value = true
   showAIDialog.value = true
 }
 }
 
 
@@ -776,6 +758,7 @@ const simulateAIResponse = question => {
 const handleCloseAIDialog = () => {
 const handleCloseAIDialog = () => {
   showAIDialog.value = false
   showAIDialog.value = false
 }
 }
+
 </script>
 </script>
 
 
 <style scoped lang="scss">
 <style scoped lang="scss">
@@ -808,7 +791,6 @@ $text-color: #483d8b; // 文本颜色:靛蓝色
   height: 100%;
   height: 100%;
   position: relative;
   position: relative;
   background: linear-gradient(to bottom, #001169, #8a78d0);
   background: linear-gradient(to bottom, #001169, #8a78d0);
- 
 }
 }
 .content-box {
 .content-box {
   flex: 1;
   flex: 1;
@@ -892,7 +874,7 @@ $text-color: #483d8b; // 文本颜色:靛蓝色
   margin-left: rpx(5);
   margin-left: rpx(5);
 }
 }
 .el-menu-item {
 .el-menu-item {
-  width: rpx(105);
+  width: rpx(100);
   height: rpx(20);
   height: rpx(20);
   margin-bottom: rpx(5);
   margin-bottom: rpx(5);
   border-radius: rpx(6);
   border-radius: rpx(6);
@@ -902,7 +884,7 @@ $text-color: #483d8b; // 文本颜色:靛蓝色
 }
 }
 .el-menu ::v-deep(.el-sub-menu__title){
 .el-menu ::v-deep(.el-sub-menu__title){
   color: white;
   color: white;
-   width: rpx(115);
+   width: rpx(100);
   height: rpx(20);
   height: rpx(20);
   margin-bottom: rpx(5);
   margin-bottom: rpx(5);
   font-size: rpx(7);
   font-size: rpx(7);