Forráskód Böngészése

优化接口调用

谢杰标 2 éve
szülő
commit
ce61d0314f
1 módosított fájl, 22 hozzáadás és 126 törlés
  1. 22 126
      src/pages/course-detail/index.vue

+ 22 - 126
src/pages/course-detail/index.vue

@@ -3175,7 +3175,6 @@ export default {
       sectionExam: [], //节试卷集合
       compareFaceData: 0, // 拍照匹配相似度
       dialogPalyVisible: false,
-      allVideoList: [],
     };
   },
   computed: {
@@ -3246,9 +3245,6 @@ export default {
     this.gradeId = this.$route.query.gradeId;
     this.sectionItem = this.$route.query;
     let isOther = this.$route.query.isOther || "";
-    // setTimeout(() => {
-    //   this.playNextVideo();
-    // }, 2000);
 
     if (isOther) {
       const confirmText = [
@@ -3286,7 +3282,6 @@ export default {
     }
 
     await this.getGoodsDetail(); //商品详情
-    this.studyRecordMenuAllList();
     this.dictList();
     // this.userConfirmInfoDetail().then((res) => {
     this.getbaseprofiletplists().then(async (res) => {
@@ -3385,7 +3380,7 @@ export default {
     pauseVideo() {
       if (document.visibilityState === "hidden") {
         this.player && this.player.j2s_pauseVideo();
-      }else{
+      } else {
         this.player && this.player.j2s_resumeVideo();
       }
     },
@@ -5188,8 +5183,8 @@ export default {
             isRebuild ? (item.isRebuild = 1) : (item.menuType = 2);
           }
           menuItem.list = res.data;
-          if(isAuto){
-            return Promise.resolve(res.data)
+          if (isAuto) {
+            return Promise.resolve(res.data);
           }
           if (isRebuild) return;
           if (status) {
@@ -5208,100 +5203,41 @@ export default {
           }
         });
     },
-    async openChapter(chapter) {
+    openChapter(chapter) {
+      chapter.showList = !chapter.showList;
       //获取节试卷列表
+      let { chapterId, menuId, list, moduleId, id, isRebuild,courseId } = chapter;
       this.$request
         .reSectionExamList({
-          chapterId: chapter.chapterId || chapter.menuId,
+          chapterId: chapterId || menuId,
           courseId: this.courseId,
           gradeId: this.gradeId,
         })
         .then((res) => {
           this.sectionExam = [...this.sectionExam, ...res.data];
         });
-      chapter.showList = !chapter.showList;
-      if (!chapter.list.length) {
-        if (chapter.isRebuild) {
-          return await this.getReSectionList(
-            chapter.id,
-            chapter.courseId,
-            chapter.moduleId || 0,
-            chapter
-          );
-        } else {
-          return await this.getBuySectionList(
-            chapter.id,
-            chapter.courseId,
-            chapter.moduleId || 0,
-            chapter
-          );
-        }
+      if (list.length) {
+        return;
       }
-    },
-    getReSectionList(chapterId, courseId, moduleId, chapter) {
-      return this.$request
-        .reSectionList({
-          chapterId: chapterId,
-          gradeId: this.gradeId,
-          courseId: courseId,
-          rebuild: 1,
-          moduleId: moduleId,
-        })
-        .then((res) => {
-          let newArr = res.data.filter((item) => {
-            return item.type != 2;
-          });
-          chapter.canLearn = newArr.every((item) => {
-            if (item.learning == 1) {
-              return true;
-            } else {
-              return false;
-            }
-          });
-
-          res.data.forEach((section) => {
-            section.parent = chapter;
-          });
-          chapter.list = res.data;
-          return Promise.resolve(chapter.list);
-        });
-    },
-
-    getBuySectionList(chapterId, courseId, moduleId = 0, chapter) {
-      // /course/sectionList 查询章与节关系列表+章卷同级展示
       return this.$request
         .reSectionList({
-          chapterId: chapterId,
+          chapterId: id,
           gradeId: this.gradeId,
           courseId: courseId,
-          moduleId: moduleId,
+          rebuild: isRebuild ? 1 : undefined,
+          moduleId: moduleId || 0,
         })
         .then((res) => {
           let newArr = res.data.filter((item) => {
             return item.type != 2;
           });
-          chapter.canLearn = newArr.every((item) => {
-            if (item.learning == 1) {
-              return true;
-            } else {
-              return false;
-            }
-          });
-
+          chapter.canLearn = newArr.every(item =>item.learning == 1)
           res.data.forEach((section) => {
             section.parent = chapter;
           });
           chapter.list = res.data;
-
           if (this.needOpen) {
             this.needOpen = false;
-            if (
-              chapter.list &&
-              !this.sectionItem.recordingUrl &&
-              this.sectionItem.sectionType != 2
-            ) {
-              // this.getResource(chapter.list[0]);
-            }
           }
           return Promise.resolve(chapter.list);
         });
@@ -5549,7 +5485,7 @@ export default {
       }
 
       let list = await this.studyRecordMenuAllList();
-
+      console.log(list, "list");
       type = type == 1 && section.type == 2 ? 2 : type;
       if (type == 1) {
         let index = list.findIndex(
@@ -5867,7 +5803,6 @@ export default {
           });
       });
     },
-
     studyRecordMenuAllList() {
       return new Promise((resolve) => {
         this.$request
@@ -5877,7 +5812,6 @@ export default {
             goodsId: this.goodsId,
           })
           .then((res) => {
-            this.allVideoList = res.data;
             resolve(res.data);
           });
       });
@@ -6025,7 +5959,7 @@ export default {
         this.getResource(playChapter[playVideoIndex + 1], 1);
       } else if (playChapterIndex < chapterList.length - 1) {
         // 不是最后一杰
-        let nextChapter = chapterList[playChapterIndex + 1].list
+        let nextChapter = chapterList[playChapterIndex + 1].list;
         if (nextChapter.length) {
           this.getResource(nextChapter.list[0], 1);
         } else {
@@ -6035,7 +5969,7 @@ export default {
         }
       } else {
         // 章最后一个视频  跳去下一章
-        let nextChapterList = this.menuList[moduleIndex + 1].list
+        let nextChapterList = this.menuList[moduleIndex + 1].list;
         if (!nextChapterList.length) {
           this.needOpen = true;
           nextChapterList = await this.openModule(
@@ -6044,9 +5978,9 @@ export default {
             true
           );
         }
-        if(nextChapterList[0].list.length){
+        if (nextChapterList[0].list.length) {
           this.getResource(nextChapterList[0].list[0], 1);
-        }else{
+        } else {
           let data = await this.openChapter(nextChapterList[0]);
           this.getResource(data[0], 1);
         }
@@ -6568,13 +6502,7 @@ export default {
               return item.type != 2;
             });
             if (sectionItem.parent) {
-              sectionItem.parent.canLearn = newArr.every((item) => {
-                if (item.learning == 1) {
-                  return true;
-                } else {
-                  return false;
-                }
-              });
+              sectionItem.parent.canLearn = newArr.every(item =>item.learning == 1)
               res.data.forEach((section) => {
                 section.isRebuild = 1;
                 section.parent = sectionItem.parent;
@@ -6601,14 +6529,7 @@ export default {
                 return item.type != 2;
               });
               if (rebuildObj.parent) {
-                rebuildObj.parent.canLearn = newArr.every((item) => {
-                  if (item.learning == 1) {
-                    return true;
-                  } else {
-                    return false;
-                  }
-                });
-
+                rebuildObj.parent.canLearn = newArr.every(item =>item.learning == 1)
                 res.data.forEach((section) => {
                   section.parent = rebuildObj.parent;
                 });
@@ -6667,7 +6588,6 @@ export default {
         }
       } else {
         //第三层节有moduleid和chapterid都有
-        console.log("第三层第三层");
         this.$request
           .reSectionList({
             chapterId: sectionItem.chapterId,
@@ -6680,14 +6600,7 @@ export default {
               return item.type != 2;
             });
             if (sectionItem.parent) {
-              sectionItem.parent.canLearn = newArr.every((item) => {
-                if (item.learning == 1) {
-                  return true;
-                } else {
-                  return false;
-                }
-              });
-
+              sectionItem.parent.canLearn = newArr.every(item =>item.learning == 1)
               res.data.forEach((section) => {
                 section.parent = sectionItem.parent;
               });
@@ -6699,15 +6612,11 @@ export default {
                     chapter.moduleId == sectionItem.moduleId &&
                     chapter.chapterId == sectionItem.chapterId
                   ) {
-                    // chapter.learning = res.data[0].learning
-                    console.log(res.data, "res.data");
                     chapter.list = res.data;
-                    console.log(chapter.list, "chapter.list");
                   }
                 });
               }
             });
-            console.log("this.menuList", this.menuList);
           });
 
         if (this.menuTab.length > 1 && rebuildObj) {
@@ -6724,13 +6633,7 @@ export default {
                 return item.type != 2;
               });
               if (sectionItem.parent) {
-                rebuildObj.parent.canLearn = newArr.every((item) => {
-                  if (item.learning == 1) {
-                    return true;
-                  } else {
-                    return false;
-                  }
-                });
+                rebuildObj.parent.canLearn = newArr.every(item =>item.learning == 1)
 
                 res.data.forEach((section) => {
                   section.parent = rebuildObj.parent;
@@ -6811,7 +6714,6 @@ export default {
           moduleId: parseInt(self.moduleId),
         };
         self.$request.recordLast(data).then((res) => {
-          console.log(res.data, "res.datares.datares.datares.datares.data");
           resolve(res.data);
         });
       });
@@ -6878,7 +6780,6 @@ export default {
       this.$request
         .reMenuList({ courseId: this.courseId, gradeId: this.gradeId })
         .then(async (res) => {
-          console.log("--asfsdgshfduofhdug", res.rows, this.menuList);
           for (let i = 0; i < res.rows.length; i++) {
             let item = res.rows[i];
             item.id = item.menuId;
@@ -6889,11 +6790,6 @@ export default {
             item.parent = this.menuList;
           }
           self.menuList = res.rows;
-          console.log(
-            "==============self.menuList===",
-            res.rows,
-            self.menuList
-          );
           if (
             (this.sectionItem.recordingUrl || this.sectionItem.liveUrl) &&
             this.needOpenNew