xiejiebiao пре 3 година
родитељ
комит
581d1fb91b
2 измењених фајлова са 312 додато и 225 уклоњено
  1. 290 44
      src/components/courseTree/CourseTree.vue
  2. 22 181
      src/pages/course-detail/index.vue

+ 290 - 44
src/components/courseTree/CourseTree.vue

@@ -1,20 +1,21 @@
 <template>
     <div class="course_tree">
-        <div v-for="(courseItem, courseIndex) in courseList" :key="courseIndex">
+        <div v-for="(courseItem, courseIndex) in treeList" :key="courseIndex">
             <div v-if="courseItem.courseList" class="teacherList_name">
-                <div v-for="(tea, index) in courseItem.courseList" :key="index" class="names"
-                    :class="{ nactive: teaIndex == index }" @click="activeFunc(tea.courseId, index)">
+                <div v-for="tea in courseItem.courseList" :key="tea.courseId" class="names"
+                    :class="{ nactive: tea.courseId == courseItem.courseId }"
+                    @click="activeFunc(tea.courseId, courseIndex)">
                     {{ tea.aliasName }}
                 </div>
             </div>
-            <div class="item__title" @click="getMenuList(courseItem)">
+            <div class="item__title" @click="getMenuList(courseItem)" v-if="treeList.length != 1">
                 <i :class="{
                     'el-icon-caret-right': !courseItem.showList,
                     'el-icon-caret-bottom': courseItem.showList,
                 }"></i>
                 {{ courseItem.courseName }}
             </div>
-            <div v-if="courseItem.showList" style="padding-left:12px">
+            <div v-if="courseItem.showList" :style="{ paddingLeft: (treeList.length != 1 ? '12px' : '0') }">
                 <div class="item" v-for="(menu, index) in courseItem.list" :key="index">
                     <template v-if="menu.type == 1">
                         <div class="item__title" @click="openModule(menu)">
@@ -45,7 +46,8 @@
                                             active: isActive(section),
                                         }" v-for="(
                                               section, sectionIndex
-                                            ) in chapter.list" :key="sectionIndex" @click="getResource(section, 1)">
+                                            ) in chapter.list" :key="sectionIndex"
+                                            @click="getResource(section, 1, courseIndex)">
                                             <template v-if="section.type != 2">
                                                 <template>
                                                     <div class="note note--blue" v-if="
@@ -192,7 +194,7 @@
                                         </div>
                                     </div>
                                     <div v-if="chapter.type == 2" class="bank-section__item"
-                                        @click="getResource(chapter, 3)">
+                                        @click="getResource(chapter, 3, courseIndex)">
                                         <template>
                                             <template>
                                                 <div class="test-btn" v-if="chapter.doType == 1">
@@ -238,7 +240,8 @@
                                             active: isActive(section),
                                         }" v-for="(
                                               section, sectionIndex
-                                            ) in menu.list" :key="sectionIndex" @click="getResource(section, 1)">
+                                            ) in menu.list" :key="sectionIndex"
+                                            @click="getResource(section, 1, courseIndex)">
                                             <template v-if="section.type != 2">
                                                 <template>
                                                     <div class="note note--blue" v-if="
@@ -389,7 +392,7 @@
                             <div class="bank-section">
                                 <div class="bank-section__item" :class="{
                                     active: isActive(menu),
-                                }" @click="getResource(menu, 1)">
+                                }" @click="getResource(menu, 1, courseIndex)">
                                     <template>
                                         <div class="note note--blue" v-if="menu.sectionType == 1">
                                             视频
@@ -489,28 +492,77 @@ export default {
             default: () => {
                 return []
             }
+        },
+        goodsLearningOrder: {
+            type: Number
+        },
+        sectionMaxNum: {
+            type: Number
         }
     },
     data() {
         return {
             teaIndex: 0,
             nowTime: 0,
+            treeList: [],
+            query: this.$route.query,
+            sectionItem: {}
         }
     },
+    created() {
+        this.init()
+    },
     mounted() {
-        this.nowTime = Number(new Date().getTime() / 1000).toFixed(0);
+
     },
     methods: {
-        activeFunc() {
+        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 list = await this.getMenuList(this.treeList[index])
+
+            // 判断已选中的视频的父级 
+            let { moduleId, chapterId, sectionId } = this.query
+            if (moduleId) {
+                list = await this.openModule(list.find(e => e.menuId == moduleId), true);
+            }
+            if (chapterId) {
+                list = await this.openChapter(list.find(e => e.chapterId == chapterId))
+            }
+            this.sectionItem = list.find(e => e.id == sectionId)
+            
         },
-        async getMenuList(course) {
+        activeFunc(courseId, index) {
+            let { courseId: nowCourseId, courseList } = this.treeList[index]
+            if (courseId == nowCourseId) {
+                return
+            }
+            if (index) {
+                let { stuAllNum, secAllNum } = this.treeList[index - 1];
+                if (stuAllNum != secAllNum) {
+                    return this.$message({
+                        type: "warning",
+                        message: "需按课程顺序学习",
+                    });
+                }
+            }
+            let course = this.courseList.find(e => e.courseId == courseId)
+            if (course) {
+                course.courseList = courseList
+                course.list = []
+                course.showList = false
+            }
+            this.treeList.splice(index, 1, JSON.parse(JSON.stringify(course)))
+            this.getMenuList(this.treeList[index])
+        },
+        getMenuList(course) {
             let { showList, courseId, list } = course
             course.showList = !showList
             if (list.length) return;
-            this.$request
+            return this.$request
                 .reMenuList({ courseId, gradeId: this.gradeId })
-                .then(async (res) => {
+                .then((res) => {
                     for (let i = 0; i < res.rows.length; i++) {
                         let item = res.rows[i];
                         item.id = item.menuId;
@@ -521,12 +573,13 @@ export default {
                         item.parent = this.menuList;
                     }
                     course.list = res.rows
+                    return Promise.resolve(res.rows)
                 })
         },
         openModule(module, status = false, isAuto = false) {
+            console.log(module)
             let { list, isRebuild, id, courseId, showList } = module;
             module.showList = !showList;
-            console.log(module.showList)
             if (list.length) return;
             return this.$request
                 .reChapterList({
@@ -545,24 +598,7 @@ export default {
                         isRebuild ? (item.isRebuild = 1) : (item.menuType = 2);
                     }
                     module.list = res.data;
-                    if (isAuto) {
-                        return Promise.resolve(res.data);
-                    }
-                    if (isRebuild) return;
-                    if (status) {
-                        const FindIndexs = module.list.findIndex((item) => {
-                            return item.chapterId == this.sectionItem.chapterId;
-                        });
-                        if (FindIndexs != -1) {
-                            this.openChapter(module.list[FindIndexs]);
-                        } else {
-                            this.$message.warning("章列表定位失败");
-                        }
-                    } else {
-                        if (this.needOpen) {
-                            this.openChapter(module.list[0]);
-                        }
-                    }
+                    return Promise.resolve(res.data);
                 });
         },
         openChapter(chapter) {
@@ -589,13 +625,9 @@ export default {
                     moduleId: moduleId || 0,
                 })
                 .then((res) => {
-                    chapter.canLearn = res.data.filter(item =>  item.type != 2).every(item => item.learning == 1)
+                    chapter.canLearn = res.data.filter(item => item.type != 2).every(item => item.learning == 1)
                     res.data.forEach((section) => {
                         section.parent = chapter;
-                        // let { sectionId, moduleId, chapterId } = this.sectionItem
-                        // if (section.sectionId == sectionId && section.moduleId == moduleId && section.chapterId == chapterId) {
-                        //     this.sectionItem = section
-                        // }
                     });
                     chapter.list = res.data;
                     if (this.needOpen) {
@@ -604,19 +636,233 @@ export default {
                     return Promise.resolve(chapter.list);
                 });
         },
-        isActive() { },
-        getResource() { },
-        checkSection() { }
+        isActive(section) {
+            let moduleId = section.moduleId || 0;
+            let chapterId = section.chapterId || 0;
+            let sectionId = section.sectionId || section.menuId;
+            if (
+                moduleId == this.moduleId &&
+                chapterId == this.chapterId &&
+                sectionId == this.playSectionId
+            ) {
+                return true;
+            } else {
+                return false;
+            }
+        },
+        async getResource(section, type, courseIndex) {
+            if (!(await this.orderTopTobottom(section, type, courseIndex))) {
+                this.clickLock = false;
+                this.$message({
+                    type: "warning",
+                    message:
+                        section.type == 2
+                            ? "请学完视频课程再进行练习和测试"
+                            : "请按顺序学习视频课程",
+                });
+                return false;
+            }
+            if (
+                section.sectionType === 2 &&
+                section.liveStartTime &&
+                section.liveEndTime
+            ) {
+                if (section.liveStartTime > this.nowTime) {
+                    this.$message.warning("直播待开播");
+                    return;
+                }
+                if (section.liveEndTime < this.nowTime) {
+                    this.$message.warning("直播已结束");
+                    return;
+                }
+            }
+            section.type == 2 ? this.toCourseExam(section) : this.toPlay()
+        },
+        async toCourseExam(section, type) {
+            //试卷
+            // 学习次数
+            if (!(await this.exceedLearnNum(section))) {
+                return false;
+            }
+            let num =
+                this.goodsLearningOrder != 2 || section.rebuild
+                    ? await this.bankRecordDoNum(section.typeId)
+                    : section.doNum;
+            if (section.answerNum - num > 0 && section.answerNum > 0 || section.answerNum == 0) {
+                this.$router.push({
+                    path: "/course-exam/" + this.goodsId,
+                    query: {
+                        courseId: this.courseId,
+                        gradeId: this.gradeId,
+                        moduleId: section.moduleId || 0,
+                        sectionId: section.sectionId || 0,
+                        examId: section.typeId,
+                        learning: section.learning,
+                        type: type,
+                        chapterId: section.chapterId || 0,
+                        orderGoodsId: this.orderGoodsId,
+                    },
+                });
+            } else {
+                this.$message({
+                    type: "warning",
+                    message: "该试卷只能答题" + section.answerNum + "次",
+                });
+                return;
+            }
+        },
+        async exceedLearnNum(section) {
+            let learnNum = await this.goodsTodayStudySectionNum();
+            let hasLearn = await this.gradeCheckGoodsStudy(section.typeId);
+            if (this.sectionMaxNum > 0) {
+                if (learnNum >= this.sectionMaxNum && !hasLearn) {
+                    this.$message({
+                        type: "warning",
+                        message: `每天最多学习${this.sectionMaxNum}节`,
+                    });
+                    return false;
+                }
+            }
+            return true;
+        },
+        goodsTodayStudySectionNum(option) {
+            return new Promise((resolve) => {
+                this.$request
+                    .goodsTodayStudySectionNum({
+                        goodsId: this.goodsId,
+                        gradeId: this.gradeId,
+                    })
+                    .then((res) => {
+                        resolve(res.data);
+                    });
+            });
+        },
+        gradeCheckGoodsStudy(option) {
+            return new Promise((resolve) => {
+                this.$request
+                    .gradeCheckGoodsStudy({
+                        goodsId: this.goodsId,
+                        gradeId: this.gradeId,
+                        moduleId: option.moduleId || 0,
+                        chapterId: option.chapterId || 0,
+                        sectionId: option.sectionId || option.menuId,
+                    })
+                    .then((res) => {
+                        resolve(res.data);
+                    });
+            });
+        },
+        bankRecordDoNum(section) {
+            return new Promise((resolve) => {
+                this.$request
+                    .bankRecordDoNum({
+                        goodsId: this.goodsId,
+                        gradeId: this.gradeId,
+                        chapterId: section.chapterId,
+                        courseId: this.courseId,
+                        moduleId: 0,
+                        examId: section.typeId,
+                    })
+                    .then((res) => {
+                        resolve(res.data);
+                    });
+            });
+        },
+        toPlay() {
+            // this.$emit('getResource', section, type)
+        },
+        checkSection() { },
+        //获取商品双师资模板
+        getDoubleTeacherList() {
+            let rows = JSON.parse(JSON.stringify(this.courseList))
+            rows.forEach(e => {
+                e.list = []
+                e.showList = false
+            })
+            return this.$request
+                .courseTeacherList({
+                    goodsId: this.$route.params.goodsId,
+                })
+                .then(({ data }) => {
+                    data.forEach(ele => {
+                        rows.forEach((e, i) => {
+                            let actvieIndex = ele.courseIds.indexOf(this.activeCourseId)
+                            let index = ele.courseIds.indexOf(e.courseId)
+                            if (actvieIndex != -1 && index != -1) {
+                                if (e.courseId == this.activeCourseId) {
+                                    e.courseList = ele.courseList
+                                } else {
+                                    delete rows[i]
+                                }
+                            } else {
+                                if (index == 0) {
+                                    e.courseList = ele.courseList
+                                }
+                                if (index > 0) {
+                                    delete rows[i]
+                                }
+                            }
+
+                        })
+                    })
+                    return Promise.resolve(rows.filter(e => e))
+                });
+        },
+        async orderTopTobottom(section, type, courseIndex) {
+            let { rebuild, moduleId, chapterId } = section;
+            if (this.goodsLearningOrder != 2 || rebuild) {
+                return true;
+            }
+            if (this.treeList.length > 1 && courseIndex > 0) {
+                let isAllLear = this.treeList.filter((e, i) => i < courseIndex).every(ele => ele.stuAllNum == ele.secAllNum)
+                if (!isAllLear) return false
+            }
+            let list = await this.studyRecordMenuAllList(this.treeList[courseIndex].courseId);
+            type = type == 1 && section.type == 2 ? 2 : type;
+            if (type == 1) {
+                let index = list.findIndex(
+                    (e) =>
+                        e.moduleId == moduleId &&
+                        e.chapterId == chapterId &&
+                        e.id == section.sectionId
+                );
+                list = list.slice(0, index);
+            } else if (type != 3) {
+                list = list.filter(
+                    (e) => e.moduleId == moduleId && e.chapterId == chapterId
+                );
+            }
+            return list.every((item) => item.studyStatus == 1);
+        },
+        studyRecordMenuAllList(courseId) {
+            return new Promise((resolve) => {
+                this.$request
+                    .studyRecordMenuAllList({
+                        courseId,
+                        gradeId: this.gradeId,
+                        goodsId: this.goodsId,
+                    })
+                    .then((res) => {
+                        resolve(res.data);
+                    });
+            });
+        },
     },
     computed: {
         gradeId() {
-            return this.$route.query.gradeId
+            return this.query.gradeId
+        },
+        activeCourseId() {
+            return this.query.courseId
+        },
+        goodsId() {
+            return this.$route.params.goodsId;
         }
     },
     watch: {
         courseList: {
-            handler(newVal, oldVal) {
-                // console.log(newVal, 'newVal')
+            async handler(newVal, oldVal) {
+
             },
             deep: true,
             immediate: true

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

@@ -47,7 +47,10 @@
                           </div>
                           <!-- 章节目录 -->
                           <template v-if="tab.name == '1'">
-                            <Course-tree :courseList.sync="courseList" @getMenuList="getMenuList"></Course-tree>
+                            <Course-tree :courseList="courseList" :goodsLearningOrder="businessData.goodsLearningOrder"
+                              :sectionMaxNum="goodsData.sectionMaxNum" @getMenuList="getMenuList"
+                              @getResource="getResource">
+                            </Course-tree>
                             <!-- <div class="right-box__body">
                               <div v-for="(courseItem, courseIndex) in courseList" :key="courseIndex">
                                 <div v-if="courseItem.courseList" class="teacherList_name">
@@ -2583,8 +2586,6 @@ export default {
       needOpen: true, //是否需要展开第一章节
       menuIndex: [],
       clickLock: false,
-      goodsTeacher: [],
-      teacherList: [],
       liveLast: null,
       apply_post_disabled: false,
       disName: false, // 姓名是否禁止输入
@@ -2595,7 +2596,7 @@ export default {
       sectionExam: [], //节试卷集合
       compareFaceData: 0, // 拍照匹配相似度
       dialogPalyVisible: false,
-
+      allCourseList: []
     };
   },
   computed: {
@@ -4443,17 +4444,10 @@ export default {
         this.vidzb = "";
         this.historyChatMsgList = [];
         this.nowTime = Number(new Date().getTime() / 1000).toFixed(0);
-        this.courseDetail(); //课程详情
         this.getAnswerList(); //答疑列表
         // this.getMenuList(this.courseId); //学习目录
         this.getReMenuList(); //获取重修目录
         this.getNoteList(); //获取节笔记
-        //更新老师信息
-        // this.goodsTeacher.forEach((item) => {
-        //   if (item.courseList.some((x) => x.courseId == this.courseId)) {
-        //     this.teacherList = item.teaList;
-        //   }
-        // });
         resolve();
       });
     },
@@ -4466,29 +4460,6 @@ export default {
         .then((res) => {
           this.historyChatMsgList = res.data;
         });
-    },
-    courseDetail() {
-      let self = this;
-      this.$request.courseDetail(this.courseId).then((res) => {
-        // if (res.data.educationName == "继续教育") {
-        //   this.$request
-        //     .lockLockAction({
-        //       action: "jxjy",
-        //     })
-        //     .then((res) => {});
-        //   this.lockTimer = setInterval(() => {
-        //     this.$request
-        //       .lockLockAction({
-        //         action: "jxjy",
-        //       })
-        //       .then((res) => {});
-        //   }, 10000);
-        // }
-        self.detail = res.data;
-      });
-    },
-    openCourse() {
-
     },
     openModule(menuItem, status = false, isAuto = false) {
       menuItem.showList = !menuItem.showList;
@@ -4705,135 +4676,25 @@ export default {
      * 点击节
      */
     async getResource(section, type) {
-      if (!(await this.orderTopTobottom(section, type))) {
-        this.clickLock = false;
-        this.$message({
-          type: "warning",
-          message:
-            section.type == 2
-              ? "请学完视频课程再进行练习和测试"
-              : "请按顺序学习视频课程",
-        });
-        return false;
-      }
       this.clickSectionItem = section;
-      //逻辑
+      if (this.clickLock) {
+        return;
+      }
+      this.clickLock = true;
       if (
-        section.sectionType === 2 &&
-        section.liveStartTime &&
-        section.liveEndTime
+        this.sectionItem.sectionType === 1 &&
+        this.playSectionId &&
+        (this.playSectionId == section.sectionId ||
+          this.playSectionId == section.menuId) &&
+        this.moduleId == (section.moduleId || 0) &&
+        this.chapterId == (section.chapterId || 0)
       ) {
-        if (section.liveStartTime > this.nowTime) {
-          this.$message.warning("直播待开播");
-          return;
-        }
-        if (section.liveEndTime < this.nowTime) {
-          this.$message.warning("直播已结束");
-          return;
-        }
-      }
-
-      if (section.type == 2) {
-        //试卷
-        // 学习次数
-        if (!(await this.exceedLearnNum(section))) {
-          return false;
-        }
-
-        let num =
-          this.businessData.goodsLearningOrder != 2 || section.rebuild
-            ? await this.bankRecordDoNum(section.typeId)
-            : section.doNum;
-        if (section.answerNum - num > 0 && section.answerNum > 0) {
-          this.$router.push({
-            path: "/course-exam/" + this.goodsId,
-            query: {
-              courseId: this.courseId,
-              gradeId: this.gradeId,
-              moduleId: section.moduleId || 0,
-              sectionId: section.sectionId || 0,
-              examId: section.typeId,
-              learning: section.learning,
-              type: type,
-              chapterId: section.chapterId || 0,
-              orderGoodsId: this.orderGoodsId,
-            },
-          });
-          //没有答题次数限制
-        } else if (section.answerNum == 0) {
-          this.$router.push({
-            path: "/course-exam/" + this.goodsId,
-            query: {
-              courseId: this.courseId,
-              gradeId: this.gradeId,
-              moduleId: section.moduleId || 0,
-              sectionId: section.sectionId || 0,
-              examId: section.typeId,
-              learning: section.learning,
-              type: type,
-              chapterId: section.chapterId || 0,
-              orderGoodsId: this.orderGoodsId,
-            },
-          });
-        } else {
-          this.$message({
-            type: "warning",
-            message: "该试卷只能答题" + section.answerNum + "次",
-          });
-
-          return;
-        }
-        this.studyLog(
-          (section.moduleId = 0),
-          (section.chapterId = 0),
-          section.typeId
-        );
+        //切换为同一频道不作为
+        this.clickLock = false;
         return;
       }
-      if (section.type != 2) {
-        if (this.clickLock) {
-          return;
-        }
-        this.clickLock = true;
-        if (
-          this.sectionItem.sectionType === 1 &&
-          this.playSectionId &&
-          (this.playSectionId == section.sectionId ||
-            this.playSectionId == section.menuId) &&
-          this.moduleId == (section.moduleId || 0) &&
-          this.chapterId == (section.chapterId || 0)
-        ) {
-          //切换为同一频道不作为
-          this.clickLock = false;
-          return;
-        }
-        this.initVideo(section);
-      }
-    },
-    async orderTopTobottom(section, type) {
-      let { rebuild, moduleId, chapterId } = section;
+      this.initVideo(section);
 
-      if (this.businessData.goodsLearningOrder != 2 || rebuild) {
-        return true;
-      }
-
-      let list = await this.studyRecordMenuAllList();
-      console.log(list, "list");
-      type = type == 1 && section.type == 2 ? 2 : type;
-      if (type == 1) {
-        let index = list.findIndex(
-          (e) =>
-            e.moduleId == moduleId &&
-            e.chapterId == chapterId &&
-            e.id == section.sectionId
-        );
-        list = list.slice(0, index);
-      } else if (type != 3) {
-        list = list.filter(
-          (e) => e.moduleId == moduleId && e.chapterId == chapterId
-        );
-      }
-      return list.every((item) => item.studyStatus == 1);
     },
     bankRecordDoNum(section) {
       return new Promise((resolve) => {
@@ -6117,7 +5978,6 @@ export default {
      * 展开列表
      */
     getMenuList(courseId) {
-      console.log(courseId, 66)
       let self = this;
       let index = this.courseList.findIndex(e => e.courseId == courseId)
       let course = this.courseList[index]
@@ -6136,7 +5996,7 @@ export default {
           }
           course.list = res.rows
           this.$set(this.courseList, index, course)
-          return
+          // return
           self.menuList = res.rows;
           if (
             (this.sectionItem.recordingUrl || this.sectionItem.liveUrl) &&
@@ -6455,6 +6315,7 @@ export default {
     },
     //获取商品双师资模板
     getDoubleTeacherList(rows) {
+      rows = JSON.parse(JSON.stringify(rows))
       rows.forEach(e => {
         e.list = []
         e.showList = false
@@ -6482,7 +6343,8 @@ export default {
     courseCourseList() {
       return new Promise((resolve) => {
         this.$request.courseCourseList({ goodsId: this.goodsId, gradeId: this.gradeId }).then(async (res) => {
-          this.courseList = await this.getDoubleTeacherList(res.rows)
+          this.courseList = res.rows
+          // this.courseList = await this.getDoubleTeacherList(res.rows)
           if (!this.courseId) {
             this.courseId = this.courseList[0].courseId;
           }
@@ -8092,25 +7954,4 @@ export default {
     overflow: auto;
   }
 }
-
-
-.teacherList_name {
-  display: flex;
-  margin-left: 20px;
-  margin-top: 10px;
-
-  .names {
-    font-size: 13px;
-    color: #383838;
-    margin-right: 8px;
-    cursor: pointer;
-    background: #818181;
-    border-radius: 4px;
-    padding: 3px 6px;
-
-    &.nactive {
-      background: #cccccc;
-    }
-  }
-}
 </style>