Преглед на файлове

自动播放和初始化播放

谢杰标 преди 2 години
родител
ревизия
dbfcdb85ff
променени са 2 файла, в които са добавени 31 реда и са изтрити 52 реда
  1. 31 48
      src/components/courseTree/CourseTree.vue
  2. 0 4
      src/pages/course-detail/index.vue

+ 31 - 48
src/components/courseTree/CourseTree.vue

@@ -570,28 +570,13 @@ export default {
     async init() {
       this.nowTime = Number(new Date().getTime() / 1000).toFixed(0);
       this.treeList = await this.getDoubleTeacherList();
-      let index = this.treeList.findIndex(
-        (e) => e.courseId == this.activeCourseId
+      let sectionItem = await this.backNextItem(
+        this.treeList.find((e) => e.courseId == this.activeCourseId),
+        0,
+        false
       );
-      let list = await this.getMenuList(this.treeList[index]);
-      // 判断已选中的视频的父级
-      let { moduleId, chapterId, sectionId, sectionType } = this.query;
-      if (moduleId * 1) {
-        list = await this.openModule(list.find((e) => e.menuId == moduleId));
-      }
-      if (chapterId * 1) {
-        list = await this.openChapter(
-          list.find(
-            (e) => e[moduleId * 1 ? "chapterId" : "menuId"] == chapterId
-          )
-        );
-      }
-      let sectionItem = list.find(
-        (e) =>
-          e[moduleId * 1 || chapterId * 1 ? "sectionId" : "id"] == sectionId
-      );
-      if (sectionType == 1) {
-        this.$emit("getResource", sectionItem);
+      if (this.query.sectionType == 1) {
+        this.toPlay(sectionItem);
       }
     },
     activeFunc(courseId, index) {
@@ -754,41 +739,38 @@ export default {
       let nextItem = {};
       if (list.length - 1 > index) {
         nextItem = list[index + 1];
-        // 切换课程
-        if (projectId) {
-          list = nextItem.list.length
-            ? nextItem.list
-            : await this.getMenuList(nextItem);
-          nextItem = list[0];
-        }
-        // 模块
-        if (nextItem.menuType == 1) {
-          list = nextItem.list.length
-            ? nextItem.list
-            : await this.openModule(nextItem);
-          nextItem = list[0];
-        }
-        // 章
-        if (nextItem.menuType < 3) {
-          list = nextItem.list.length
-            ? nextItem.list
-            : await this.openChapter(nextItem);
-          nextItem = list.find((e) => e.type == 1);
-        }
-        this.toPlay(nextItem);
+        this.toPlay(
+          await this.backNextItem(nextItem, projectId ? 0 : nextItem.menuType)
+        );
       } else {
         this.playNextVideo(parent);
       }
     },
-    async backNextItem(nextItem, type) {
-      console.log(nextItem, type);
-      if (type == undefined) return nextItem;
+    // 获取模块/章/节
+    async backNextItem(nextItem, type, isNext = true) {
+      if (type == undefined || type == 3) return nextItem;
       let key = ["getMenuList", "openModule", "openChapter"][type];
       let list = nextItem.list.length
         ? nextItem.list
         : await this[key](nextItem);
-      nextItem = type == 2 ? list.find((e) => e.type == 1) : list[0];
-      return this.backNextItem(nextItem, nextItem.menuType);
+      if (isNext) {
+        nextItem = type == 2 ? list.find((e) => e.type == 1) : list[0];
+      } else {
+        // 初始化 获取播放位置
+        let { moduleId, chapterId, sectionId } = this.query;
+        nextItem = list.find((e) => {
+          if (moduleId * 1 && type == 0) {
+            return e.menuId == moduleId;
+          }
+          if (chapterId * 1 && type < 2) {
+            return e[moduleId * 1 ? "chapterId" : "menuId"] == chapterId;
+          }
+          return (
+            e[moduleId * 1 || chapterId * 1 ? "sectionId" : "id"] == sectionId
+          );
+        });
+      }
+      return this.backNextItem(nextItem, nextItem.menuType, isNext);
     },
     async getResource(section, type, courseIndex) {
       if (section.type != 2 && this.isActive(section)) {
@@ -985,6 +967,7 @@ export default {
       rows.forEach((e) => {
         e.list = [];
         e.showList = false;
+        e.id = e.courseId;
       });
       return this.$request
         .courseTeacherList({

+ 0 - 4
src/pages/course-detail/index.vue

@@ -5580,13 +5580,9 @@ export default {
         }
         this.loadPlayerScript(this.loadPlayer);
         setTimeout(() => {
-          this.dialogPalyVisible = !false;
           this.clickLock = false;
         }, 3000);
         this.studyLog(this.moduleId, this.chapterId, this.playSectionId);
-        // uni.$emit("levelId", this.levelId);
-        // uni.$emit("getSection", this.menuItem);
-        // uni.$emit("isRebuild", this.isRebuild);
       }
       if (option.sectionType == 2) {
         //直播