Browse Source

迁移模块树

谢杰标 2 years ago
parent
commit
7c9d8f3a51
3 changed files with 234 additions and 135 deletions
  1. 3 2
      components/course/courseModule.vue
  2. 195 0
      components/course/courseTree.vue
  3. 36 133
      pages3/polyv/detail.vue

+ 3 - 2
components/course/courseModule.vue

@@ -177,6 +177,7 @@ export default {
     },
     openModule(item) {
       this.down = !this.down;
+      console.log(this.down, 789);
       if (!this.down && this.list.length == 0) {
         if (this.isBuy) {
           if (this.isRebuild) {
@@ -351,10 +352,10 @@ export default {
       handler(val) {
         console.log(
           "🚀 ~ file: courseModule.vue:346 ~ handler ~ val:",
-          val,
+          this.sectionItem,
           this.menuItem
         );
-        if (this.needOpen) {
+        if (this.sectionItem.moduleId == this.menuItem.menuId) {
           this.down = true;
           this.list = [];
           this.openModule(this.menuItem);

+ 195 - 0
components/course/courseTree.vue

@@ -0,0 +1,195 @@
+<template>
+  <view class="menuBox">
+    <template>
+      <view v-for="(item, index) in menuList" :key="index">
+        <!--模块 -->
+        <view v-if="item.type == 1">
+          <courseModule
+            :orderGoodsId="orderGoodsId"
+            :sectionMaxNum="sectionMaxNum"
+            :needOpen="sectionItem.moduleId == item.menuId"
+            :courseId="courseId"
+            :preItem="menuList[index - 1]"
+            :learningOrder="learningOrder"
+            :goodsId="goodsId"
+            :gradeId="gradeId"
+            :isBuy="true"
+            :menuItem="item"
+            :levelId="item.menuId"
+            :goodsType="1"
+            :menuAllList="menuAllList"
+            :sectionItem="sectionItem"
+          ></courseModule
+        ></view>
+        <!--章 -->
+        <view v-if="item.type == 2">
+          <courseChapter
+            :orderGoodsId="orderGoodsId"
+            :sectionMaxNum="sectionMaxNum"
+            :needOpen="
+              !sectionItem.moduleId && sectionItem.chapterId == item.menuId
+            "
+            :courseId="courseId"
+            :preItem="menuList[index - 1]"
+            @playEnd="sectionPlayEnd($event, index)"
+            :learningOrder="learningOrder"
+            :goodsId="goodsId"
+            :gradeId="gradeId"
+            :isBuy="true"
+            :menuItem="item"
+            :levelId="'0-' + item.menuId"
+            :goodsType="1"
+            :menuAllList="menuAllList"
+            :sectionItem="sectionItem"
+          ></courseChapter
+        ></view>
+        <!--节 -->
+        <view v-if="item.type == 3">
+          <courseSection
+            ref="MoudleSection"
+            :orderGoodsId="orderGoodsId"
+            :sectionMaxNum="sectionMaxNum"
+            @playEnd="sectionPlayEnd($event, index)"
+            :courseId="courseId"
+            :preItem="menuList[index - 1]"
+            :learningOrder="learningOrder"
+            :goodsId="goodsId"
+            :gradeId="gradeId"
+            :isBuy="true"
+            :menuItem="item"
+            :levelId="'0-0-' + item.menuId"
+            :goodsType="1"
+            :testType="3"
+            :menuAllList="menuAllList"
+          ></courseSection
+        ></view>
+      </view>
+    </template>
+  </view>
+</template>
+
+<script>
+import courseModule from "@/components/course/courseModule.vue";
+import courseChapter from "@/components/course/courseChapter.vue";
+import courseSection from "@/components/course/courseSection.vue";
+export default {
+  name: "SaasMiniprogramCourseTree",
+  props: {
+    isLive: false,
+    orderGoodsId: {
+      default: 0,
+    },
+    preItem: {
+      default: undefined,
+    },
+    learningOrder: {
+      //是否设置学习顺序 1 章节顺序 0不设置 2从头学到尾顺序
+      type: Number,
+      defaule: 0,
+    },
+    needOpen: {
+      //是否默认展开
+      type: Boolean,
+      default: false,
+    },
+    goodsId: {
+      type: Number,
+      default: 0,
+    },
+    courseId: {
+      type: [Number, String],
+      default: 0,
+    },
+    isBuy: {
+      //是否是已购买商品
+      type: Boolean,
+      default: false,
+    },
+    levelId: {
+      type: [Number, String],
+      default: "",
+    },
+    isRebuild: {
+      //是否重修目录
+      type: Boolean,
+      default: false,
+    },
+    gradeId: {
+      //重修需要班级ID
+      type: [Number, String],
+    },
+    sectionMaxNum: {
+      default: undefined,
+    },
+    // 商品类型 1视频2题库 3补考 4前培 5虚拟赠送题库 6直播
+    goodsType: {
+      type: [Number, String],
+      default: 0,
+    },
+    menuAllList: {
+      // 课程所有子目录结构列表
+      type: Array,
+      default: () => [],
+    },
+    sectionItem: {
+      // 用户最后一次看的录播的信息
+      type: Object,
+      default: () => {},
+    },
+  },
+  data() {
+    return {
+      menuList: [],
+    };
+  },
+
+  mounted() {},
+
+  methods: {
+    getMenuList() {
+      this.$api
+        .reMenuList({
+          courseId: this.courseId,
+          gradeId: this.gradeId,
+          orderGoodsId: this.orderGoodsId,
+        })
+        .then((res) => {
+          if (res.data.code == 200) {
+            for (let i = 0; i < res.data.rows.length; i++) {
+              let item = res.data.rows[i];
+              item.down = true;
+              item.id = item.menuId;
+              item.name = item.menuName;
+              item.menuType = item.type;
+            }
+            this.menuList = res.data.rows;
+          }
+        });
+    },
+  },
+  watch: {
+    courseId: {
+      handler(val) {
+        this.menuList = [];
+        this.getMenuList();
+      },
+      immediate: true,
+    },
+  },
+  components: {
+    courseModule,
+    courseChapter,
+    courseSection,
+  },
+};
+</script>
+
+<style lang="scss" scoped>
+.menuBox {
+  width: 100%;
+  background: #ffffff;
+  border-radius: 16rpx;
+  padding: 0rpx 20rpx;
+  margin-bottom: 20rpx;
+}
+</style>

+ 36 - 133
pages3/polyv/detail.vue

@@ -88,94 +88,20 @@
             <view class="note">正在直播中</view>
             <view class="title">{{ livingItem.sectionName }}</view>
           </view>
-          <!-- <view
-            v-if="teacherList && teacherList.length > 0"
-            class="teacher_names"
-          >
-            <view
-              v-for="(tea, index) in teacherList"
-              :key="index"
-              class="names"
-              :class="{ nactive: teacherIndex == index }"
-              @click="activeFunc(tea, index)"
-            >
-              {{ tea.aliasName }}
-            </view>
-          </view> -->
-          <view
-            class="menuBox onessss"
-            v-for="(item, index) in menuList"
-            :key="index"
-          >
-            <template v-if="!$method.isEmptyObject(sectionItem)">
-              <!--模块 -->
-              <view v-if="item.type == 1"
-                ><courseModule
-                  v-if="reStart"
-                  :orderGoodsId="orderGoodsId"
-                  :sectionMaxNum="goodsData.sectionMaxNum"
-                  :needOpen="sectionItem.moduleId == item.menuId"
-                  :courseId="courseId"
-                  :preItem="menuList[index - 1]"
-                  :learningOrder="orderNum"
-                  :goodsId="goodsId"
-                  :gradeId="gradeId"
-                  :isBuy="true"
-                  :menuItem="item"
-                  :levelId="item.menuId"
-                  :goodsType="1"
-                  :menuAllList="menuAllList"
-                  :sectionItem="sectionItem"
-                ></courseModule
-              ></view>
-              <!--章 -->
-              <view v-if="item.type == 2"
-                ><courseChapter
-                  v-if="reStart"
-                  :orderGoodsId="orderGoodsId"
-                  :sectionMaxNum="goodsData.sectionMaxNum"
-                  :needOpen="
-                    !sectionItem.moduleId &&
-                    sectionItem.chapterId == item.menuId
-                  "
-                  :courseId="courseId"
-                  :preItem="menuList[index - 1]"
-                  @playEnd="sectionPlayEnd($event, index)"
-                  :learningOrder="orderNum"
-                  :goodsId="goodsId"
-                  :gradeId="gradeId"
-                  :isBuy="true"
-                  :menuItem="item"
-                  :levelId="'0-' + item.menuId"
-                  :goodsType="1"
-                  :menuAllList="menuAllList"
-                  :sectionItem="sectionItem"
-                ></courseChapter
-              ></view>
-              <!--节 -->
-              <view v-if="item.type == 3"
-                ><courseSection
-                  ref="MoudleSection"
-                  v-if="reStart"
-                  :orderGoodsId="orderGoodsId"
-                  :sectionMaxNum="goodsData.sectionMaxNum"
-                  @playEnd="sectionPlayEnd($event, index)"
-                  :courseId="courseId"
-                  :preItem="menuList[index - 1]"
-                  :learningOrder="orderNum"
-                  :goodsId="goodsId"
-                  :gradeId="gradeId"
-                  :isBuy="true"
-                  :menuItem="item"
-                  :levelId="'0-0-' + item.menuId"
-                  :goodsType="1"
-                  :testType="3"
-                  :menuAllList="menuAllList"
-                ></courseSection
-              ></view>
-            </template>
-            <!-- @togoBack="togoBack($event)" -->
-          </view>
+          <course-tree
+            v-if="sectionItem.id || sectionItem.sectionId"
+            :orderGoodsId="orderGoodsId"
+            :sectionMaxNum="goodsData.sectionMaxNum"
+            :courseId="courseId"
+            :learningOrder="orderNum"
+            :goodsId="goodsId"
+            :gradeId="gradeId"
+            :isRebuild="false"
+            :isBuy="true"
+            :goodsType="1"
+            :menuAllList="menuAllList"
+            :sectionItem="sectionItem"
+          ></course-tree>
         </view>
         <!--讲义 -->
         <view v-show="current == 1">
@@ -575,11 +501,12 @@ import courseModule from "@/components/course/courseModule.vue";
 import courseChapter from "@/components/course/courseChapter.vue";
 import courseSection from "@/components/course/courseSection.vue";
 import handoutsBox from "@/components/course/handoutsBox.vue";
+import courseTree from "@/components/course/courseTree.vue";
 import PopupPhoto from "@/components/popup/index.vue";
 import myCompressImage from "@/common/compressPhoto.js";
-import myPlayer from "../../components/myPlayer/polyvPlayer.vue";
-import noteBox from "../../components/course/noteBox.vue";
-import answerBox from "../../components/course/answerBox.vue";
+import myPlayer from "@/components/myPlayer/polyvPlayer.vue";
+import noteBox from "@/components/course/noteBox.vue";
+import answerBox from "@/components/course/answerBox.vue";
 import { mapGetters, mapMutations } from "vuex";
 import { lockAction } from "../../utils/lock";
 export default {
@@ -592,6 +519,7 @@ export default {
     myPlayer,
     noteBox,
     answerBox,
+    courseTree,
   },
   data() {
     return {
@@ -650,7 +578,6 @@ export default {
       option: null,
       toggleCourseShow: false, // 切换课程弹窗
       courseList: [], // 课程列表
-      reStart: false, // 是否显示模块/章/节
       subList: [],
       subIndex: 0,
       goodsTeacher: [],
@@ -721,7 +648,7 @@ export default {
       };
     },
     detail() {
-      if (!this.courseId) {
+      if (!this.courseId || !this.courseList.length) {
         return {};
       }
       return this.courseList.find((e) => e.courseId == this.courseId);
@@ -833,7 +760,6 @@ export default {
         .then((res) => {
           if (res.data.code == 200) {
             this.courseList = res.data.rows;
-            console.log(this.courseList, "课程列表");
             // 科目
             let allItem = [{ subjectId: 0, subjectName: "所有" }];
             let ids = [];
@@ -988,7 +914,6 @@ export default {
     },
     // 原来onshow里面的内容
     async originOnShow() {
-      this.getMenuList();
       this.getReMenuList();
       await this.studyRecordMenuAllList();
       // 消息过来 定位某个节
@@ -1136,15 +1061,18 @@ export default {
         this.toggleCourseShow = false;
         return;
       }
-      if (this.orderNum == 2&&index!=0){
-         let prevItem = this.courseList[index - 1]; 
-         if (prevItem.stuAllNum + prevItem.recordNum < prevItem.secAllNum + prevItem.examNum) {
-           uni.showToast({
-              icon: "none",
-              title: "请按顺序学完上一课再学习这一课",
-            });
-            return
-         }
+      if (this.orderNum == 2 && index != 0) {
+        let prevItem = this.courseList[index - 1];
+        if (
+          prevItem.stuAllNum + prevItem.recordNum <
+          prevItem.secAllNum + prevItem.examNum
+        ) {
+          uni.showToast({
+            icon: "none",
+            title: "请按顺序学完上一课再学习这一课",
+          });
+          return;
+        }
       }
       if (type) {
         this.teacherIndex = 0;
@@ -1154,17 +1082,15 @@ export default {
           }
         });
       }
+      this.sectionItem = {};
       this.toggleCourseShow = false;
-      this.courseId = item.courseId
-      this.originOnShow()
+      this.courseId = item.courseId;
+      this.originOnShow();
     },
     async nextCourses(item, type) {
       this.vid = "";
       this.hasStart = true;
       await this.originUnload();
-
-      
-      this.reStart = false;
       this.courseId = item.courseId;
       this.gradeId = item.gradeId;
       this.toggleCourseShow = false;
@@ -1808,6 +1734,7 @@ export default {
     //正常播放视频
     async playVideo(item) {
       this.sectionItem = item;
+      console.log(this.sectionItem, "this.sectionItem");
       if (this.timer) {
         clearInterval(this.timer);
       }
@@ -2278,8 +2205,6 @@ export default {
               let playNextId = `moduleId${data.moduleId}chapterId${data.chapterId}sectionId${data.sectionId}`;
               this.$store.commit("updatePlayNextId", playNextId);
               this.updateChapterOpen(true);
-              this.reStart = false;
-              this.getMenuList();
             }
           },
         });
@@ -2636,28 +2561,6 @@ export default {
           }
         });
     },
-    getMenuList() {
-      this.$api
-        .reMenuList({
-          courseId: this.courseId,
-          gradeId: this.gradeId,
-          orderGoodsId: this.orderGoodsId,
-        })
-        .then((res) => {
-          if (res.data.code == 200) {
-            for (let i = 0; i < res.data.rows.length; i++) {
-              let item = res.data.rows[i];
-              item.down = true;
-              item.id = item.menuId;
-              item.name = item.menuName;
-              item.menuType = item.type;
-            }
-            this.menuList = res.data.rows;
-            console.log(this.menuList,789)
-            this.reStart = true;
-          }
-        });
-    },
     courseDetail() {
       this.$api.courseDetail(this.courseId).then((res) => {
         if (res.data.code == 200) {