lex 1 gadu atpakaļ
vecāks
revīzija
d2f827a536

+ 398 - 71
src/views/attend-class/index.tsx

@@ -139,7 +139,8 @@ export default defineComponent({
       type: 'class' as '' | 'preview' | 'class', // 预览类型
       subjectId: '' as any, // 声部编号
       lessonCourseId: '' as any, // 教材编号
-      detailId: '' as any, // 编号 - 章节编号
+      lessonCoursewareDetailId: '' as any, // 章节
+      detailId: '' as any, // 编号 - 课程编号
       classGroupId: '' as any, // 上课时需要 班级编号
       classId: '' as any, // 上课编号
       // detail: null,
@@ -548,10 +549,28 @@ export default defineComponent({
       activeIndex: 0,
       toolOpen: false, // 工具弹窗控制
       chapterOpen: false, // 切换章节
-      chapterDetails: {} as any,
+      chapterDetails: [] as any,
       chapterLoading: false // 加载数据
     });
 
+    const formatParentId = (id: any, list: any, ids = [] as any) => {
+      for (const item of list) {
+        if (item.knowledgeList && item.knowledgeList.length > 0) {
+          const cIds: any = formatParentId(id, item.knowledgeList, [
+            ...ids,
+            item.id
+          ]);
+          if (cIds.includes(id)) {
+            return cIds;
+          }
+        }
+        if (item.id === id) {
+          return [...ids, id];
+        }
+      }
+      return ids;
+    };
+
     /** 获取章节 */
     const getLessonCoursewareDetail = async () => {
       try {
@@ -561,6 +580,9 @@ export default defineComponent({
         });
 
         popupData.chapterDetails = res.data.lessonList || [];
+
+        const ids = formatParentId(data.detailId, popupData.chapterDetails);
+        data.lessonCoursewareDetailId = ids[0];
       } catch {
         //
       }
@@ -809,11 +831,186 @@ export default defineComponent({
     };
 
     // 上一个知识点, 下一个知识点
-    const handlePreAndNext = (type: string) => {
+    const handlePreAndNext = async (type: string) => {
+      // if (type === 'up') {
+      //   handleSwipeChange(popupData.activeIndex - 1);
+      // } else {
+      //   handleSwipeChange(popupData.activeIndex + 1);
+      // }
       if (type === 'up') {
-        handleSwipeChange(popupData.activeIndex - 1);
+        // 判断上面是否还有章节
+        if (popupData.activeIndex > 0) {
+          handleSwipeChange(popupData.activeIndex - 1);
+          return;
+        }
+
+        // 获取当前是哪个章节
+        let detailIndex = popupData.chapterDetails.findIndex(
+          (item: any) => item.id == data.lessonCoursewareDetailId
+        );
+        const detailItem =
+          popupData.chapterDetails[detailIndex]?.knowledgeList || [];
+        let lessonIndex = detailItem.findIndex(
+          (item: any) => item.id == data.detailId
+        );
+
+        let lessonStatus = false; // 当前章节上面是否有内容
+        let lessonCoursewareDetailId = '';
+        let coursewareDetailKnowledgeId = '';
+        while (lessonIndex >= 0) {
+          lessonIndex--;
+
+          if (lessonIndex >= 0) {
+            if (detailItem[lessonIndex].containMaterial) {
+              lessonStatus = true;
+              lessonCoursewareDetailId =
+                detailItem[lessonIndex].lessonCoursewareDetailId;
+              coursewareDetailKnowledgeId = detailItem[lessonIndex].id;
+            }
+          }
+
+          if (lessonStatus) {
+            break;
+          }
+        }
+        // 判断当前章节下面课程是否有内容,否则往上一个章节走
+        if (lessonStatus) {
+          popupData.chapterLoading = true;
+          data.detailId = coursewareDetailKnowledgeId;
+          data.lessonCoursewareDetailId = lessonCoursewareDetailId;
+          // 更新上课记录 上课的时候才更新
+          if (data.type !== 'preview') {
+            await classCourseScheduleUpdate();
+          }
+          await getDetail();
+          popupData.activeIndex = data.itemList.length - 1 || 0;
+          popupData.chapterOpen = false;
+          popupData.chapterLoading = false;
+          return;
+        }
+
+        let prevLessonStatus = false;
+        while (detailIndex >= 0) {
+          detailIndex--;
+          const tempDetail =
+            popupData.chapterDetails[detailIndex]?.knowledgeList || [];
+          let tempLessonLength = tempDetail.length;
+          while (tempLessonLength > 0) {
+            if (tempDetail[tempLessonLength - 1].containMaterial) {
+              prevLessonStatus = true;
+              lessonCoursewareDetailId =
+                tempDetail[tempLessonLength - 1].lessonCoursewareDetailId;
+              coursewareDetailKnowledgeId = tempDetail[tempLessonLength - 1].id;
+            }
+            tempLessonLength--;
+            if (prevLessonStatus) {
+              break;
+            }
+          }
+
+          if (prevLessonStatus) {
+            break;
+          }
+        }
+
+        // 判断当前章节下面课程是否有内容,否则往上一个章节走
+        if (prevLessonStatus) {
+          popupData.chapterLoading = true;
+          data.detailId = coursewareDetailKnowledgeId;
+          data.lessonCoursewareDetailId = lessonCoursewareDetailId;
+          await getDetail();
+          popupData.activeIndex = data.itemList.length - 1 || 0;
+          popupData.chapterLoading = false;
+          return;
+        }
       } else {
-        handleSwipeChange(popupData.activeIndex + 1);
+        if (popupData.activeIndex < data.itemList.length - 1) {
+          handleSwipeChange(popupData.activeIndex + 1);
+          return;
+        }
+
+        // 获取当前是哪个章节
+        let detailIndex = popupData.chapterDetails.findIndex(
+          (item: any) => item.id == data.lessonCoursewareDetailId
+        );
+        const detailItem =
+          popupData.chapterDetails[detailIndex]?.knowledgeList || [];
+        let lessonIndex = detailItem.findIndex(
+          (item: any) => item.id == data.detailId
+        );
+
+        let lessonStatus = false; // 当前章节下面是否有内容
+        let lessonCoursewareDetailId = '';
+        let coursewareDetailKnowledgeId = '';
+        while (lessonIndex < detailItem.length - 1) {
+          lessonIndex++;
+          if (lessonIndex >= 0) {
+            if (detailItem[lessonIndex].containMaterial) {
+              lessonStatus = true;
+              lessonCoursewareDetailId =
+                detailItem[lessonIndex].lessonCoursewareDetailId;
+              coursewareDetailKnowledgeId = detailItem[lessonIndex].id;
+            }
+          }
+          if (lessonStatus) {
+            break;
+          }
+        }
+        // 判断当前章节下面课程是否有内容,否则往下一个章节走
+        if (lessonStatus) {
+          popupData.chapterLoading = true;
+          data.detailId = coursewareDetailKnowledgeId;
+          data.lessonCoursewareDetailId = lessonCoursewareDetailId;
+          // 更新上课记录 上课的时候才更新
+          if (data.type !== 'preview') {
+            await classCourseScheduleUpdate();
+          }
+          await getDetail();
+          popupData.activeIndex = 0;
+          popupData.chapterOpen = false;
+          popupData.chapterLoading = false;
+          return;
+        }
+
+        let nextLessonStatus = false;
+        while (detailIndex <= popupData.chapterDetails.length - 1) {
+          detailIndex++;
+          const tempDetail =
+            popupData.chapterDetails[detailIndex]?.knowledgeList || [];
+          let tempLessonLength = 0;
+          while (tempLessonLength <= tempDetail.length - 1) {
+            if (tempDetail[tempLessonLength].containMaterial) {
+              nextLessonStatus = true;
+              lessonCoursewareDetailId =
+                tempDetail[tempLessonLength].lessonCoursewareDetailId;
+              coursewareDetailKnowledgeId = tempDetail[tempLessonLength].id;
+            }
+            tempLessonLength++;
+            if (nextLessonStatus) {
+              break;
+            }
+          }
+
+          if (nextLessonStatus) {
+            break;
+          }
+        }
+
+        // 判断当前章节下面课程是否有内容,否则往上一个章节走
+        if (nextLessonStatus) {
+          popupData.chapterLoading = true;
+          data.detailId = coursewareDetailKnowledgeId;
+          data.lessonCoursewareDetailId = lessonCoursewareDetailId;
+          // 更新上课记录 上课的时候才更新
+          if (data.type !== 'preview') {
+            await classCourseScheduleUpdate();
+          }
+          await getDetail();
+          popupData.activeIndex = 0;
+          popupData.chapterOpen = false;
+          popupData.chapterLoading = false;
+          return;
+        }
       }
     };
 
@@ -839,9 +1036,6 @@ export default defineComponent({
         if (popupData.activeIndex === data.itemList.length - 1) return;
         handlePreAndNext('down');
       }
-      //  else if (e.code === 'Space') {
-      //   handleStop();
-      // }
     });
 
     /** 教学数据 */
@@ -898,27 +1092,161 @@ export default defineComponent({
       }
     };
 
+    // 是否允许上一页
+    const isUpArrow = computed(() => {
+      /**
+       * 1,判断当前课程中是否处在第一个资源;
+       * 2,判断当前课程是否在当前章节的第一个;
+       * 3,判断当前章节,当前课程上面还没有其它课程,是否有资源;
+       * 4,判断当前章节上面还没有其它章节;
+       * 5,判断上面章节里面课程是否有资源;
+       */
+
+      if (popupData.activeIndex > 0) {
+        return true;
+      }
+
+      // 获取当前是哪个章节
+      let detailIndex = popupData.chapterDetails.findIndex(
+        (item: any) => item.id == data.lessonCoursewareDetailId
+      );
+      const detailItem =
+        popupData.chapterDetails[detailIndex]?.knowledgeList || [];
+      let lessonIndex = detailItem.findIndex(
+        (item: any) => item.id == data.detailId
+      );
+
+      // 说明已经是第一单元,第一课
+      if (detailIndex <= 0 && lessonIndex <= 0) {
+        return false;
+      }
+
+      let lessonStatus = false; // 当前章节上面是否有内容
+      while (lessonIndex >= 0) {
+        lessonIndex--;
+
+        if (lessonIndex >= 0) {
+          if (detailItem[lessonIndex].containMaterial) {
+            lessonStatus = true;
+          }
+        }
+      }
+      // 判断当前章节下面课程是否有内容,否则往上一个章节走
+      if (lessonStatus) {
+        return true;
+      }
+
+      // 已经是第一个章节了
+      if (detailIndex <= 0) {
+        return false;
+      }
+
+      let prevLessonStatus = false;
+      while (detailIndex >= 0) {
+        detailIndex--;
+        const tempDetail =
+          popupData.chapterDetails[detailIndex]?.knowledgeList || [];
+        let tempLessonLength = tempDetail.length;
+        while (tempLessonLength > 0) {
+          if (tempDetail[tempLessonLength - 1].containMaterial) {
+            prevLessonStatus = true;
+          }
+          tempLessonLength--;
+        }
+
+        if (prevLessonStatus) {
+          return true;
+        }
+      }
+
+      return false;
+    });
+
+    // 是否允许下一页
+    const isDownArrow = computed(() => {
+      if (popupData.activeIndex < data.itemList.length - 1) {
+        return true;
+      }
+
+      // 获取当前是哪个章节
+      let detailIndex = popupData.chapterDetails.findIndex(
+        (item: any) => item.id == data.lessonCoursewareDetailId
+      );
+      const detailItem =
+        popupData.chapterDetails[detailIndex]?.knowledgeList || [];
+      let lessonIndex = detailItem.findIndex(
+        (item: any) => item.id == data.detailId
+      );
+
+      // 说明已经是最后-单元,最后一课
+      if (
+        detailIndex >= popupData.chapterDetails.length - 1 &&
+        lessonIndex >= detailItem.length - 1
+      ) {
+        return false;
+      }
+
+      let lessonStatus = false; // 当前章节下面是否有内容
+      while (lessonIndex < detailItem.length - 1) {
+        lessonIndex++;
+        if (lessonIndex >= 0) {
+          if (detailItem[lessonIndex].containMaterial) {
+            lessonStatus = true;
+          }
+        }
+      }
+      // 判断当前章节下面课程是否有内容,否则往下一个章节走
+      if (lessonStatus) {
+        return true;
+      }
+
+      // 已经是最后一个章节了
+      if (detailIndex >= popupData.chapterDetails.length - 1) {
+        return false;
+      }
+
+      let nextLessonStatus = false;
+      while (detailIndex < popupData.chapterDetails.length - 1) {
+        detailIndex++;
+        const tempDetail =
+          popupData.chapterDetails[detailIndex]?.knowledgeList || [];
+        let tempLessonLength = 0;
+        while (tempLessonLength <= tempDetail.length - 1) {
+          if (tempDetail[tempLessonLength].containMaterial) {
+            nextLessonStatus = true;
+          }
+          tempLessonLength++;
+        }
+
+        if (nextLessonStatus) {
+          return true;
+        }
+      }
+
+      return false;
+    });
+
     return () => (
       <div id="playContent" class={[styles.playContent, 'wrap']}>
-        {!popupData.chapterLoading ? (
+        <div
+          onClick={() => {
+            clearTimeout(activeData.timer);
+            activeData.model = !activeData.model;
+            Object.values(data.videoRefs).map((n: any) =>
+              n.toggleHideControl(activeData.model)
+            );
+            Object.values(data.audioRefs).map((n: any) =>
+              n.toggleHideControl(activeData.model)
+            );
+          }}>
           <div
-            onClick={() => {
-              clearTimeout(activeData.timer);
-              activeData.model = !activeData.model;
-              Object.values(data.videoRefs).map((n: any) =>
-                n.toggleHideControl(activeData.model)
-              );
-              Object.values(data.audioRefs).map((n: any) =>
-                n.toggleHideControl(activeData.model)
-              );
+            class={styles.coursewarePlay}
+            style={{ width: parentContainer.width }}
+            onClick={(e: Event) => {
+              e.stopPropagation();
+              setModelOpen();
             }}>
-            <div
-              class={styles.coursewarePlay}
-              style={{ width: parentContainer.width }}
-              onClick={(e: Event) => {
-                e.stopPropagation();
-                setModelOpen();
-              }}>
+            {!popupData.chapterLoading ? (
               <div class={styles.wraps}>
                 {data.itemList.map((m: any, mIndex: number) => {
                   const isRender =
@@ -1047,65 +1375,59 @@ export default defineComponent({
                   ) : null;
                 })}
               </div>
-              <Transition name="right">
-                {activeData.model && (
+            ) : (
+              ''
+            )}
+            <Transition name="right">
+              {activeData.model && (
+                <div
+                  class={styles.rightFixedBtns}
+                  onClick={(e: Event) => {
+                    e.stopPropagation();
+                    clearTimeout(activeData.timer);
+                  }}>
                   <div
-                    class={styles.rightFixedBtns}
-                    onClick={(e: Event) => {
-                      e.stopPropagation();
-                      clearTimeout(activeData.timer);
+                    class={[styles.fullBtn]}
+                    onClick={() => (popupData.chapterOpen = true)}>
+                    <img src={iconChange} />
+                  </div>
+                  <div
+                    class={[
+                      styles.fullBtn,
+                      styles.iconUp,
+                      !isUpArrow.value ? styles.btnsDisabled : ''
+                    ]}
+                    onClick={() => {
+                      if (!isUpArrow.value) return;
+                      handlePreAndNext('up');
                     }}>
+                    <img src={iconUp} />
+                  </div>
+                  <div id="attent-0">
                     <div
-                      class={[styles.fullBtn]}
-                      onClick={() => (popupData.chapterOpen = true)}>
-                      <img src={iconChange} />
+                      class={[styles.fullBtn, styles.point]}
+                      onClick={() => (popupData.open = true)}>
+                      <img src={iconMenu} />
                     </div>
+
                     <div
                       class={[
                         styles.fullBtn,
-                        styles.iconUp,
-                        popupData.activeIndex === 0 ? styles.btnsDisabled : ''
+                        styles.iconDown,
+                        !isDownArrow.value ? styles.btnsDisabled : ''
                       ]}
                       onClick={() => {
-                        if (popupData.activeIndex === 0) return;
-                        handlePreAndNext('up');
+                        if (!isDownArrow.value) return;
+                        handlePreAndNext('down');
                       }}>
-                      <img src={iconUp} />
-                    </div>
-                    <div id="attent-0">
-                      <div
-                        class={[styles.fullBtn, styles.point]}
-                        onClick={() => (popupData.open = true)}>
-                        <img src={iconMenu} />
-                      </div>
-
-                      <div
-                        class={[
-                          styles.fullBtn,
-                          styles.iconDown,
-                          popupData.activeIndex === data.itemList.length - 1
-                            ? styles.btnsDisabled
-                            : ''
-                        ]}
-                        onClick={() => {
-                          if (
-                            popupData.activeIndex ===
-                            data.itemList.length - 1
-                          )
-                            return;
-                          handlePreAndNext('down');
-                        }}>
-                        <img src={iconDown} />
-                      </div>
+                      <img src={iconDown} />
                     </div>
                   </div>
-                )}
-              </Transition>
-            </div>
+                </div>
+              )}
+            </Transition>
           </div>
-        ) : (
-          ''
-        )}
+        </div>
 
         <div
           style={{ transform: activeData.model ? '' : 'translateY(-100%)' }}
@@ -1256,6 +1578,11 @@ export default defineComponent({
 
                 try {
                   data.detailId = val.itemActive;
+                  const ids = formatParentId(
+                    val.itemActive,
+                    popupData.chapterDetails
+                  );
+                  data.lessonCoursewareDetailId = ids[0];
                   // 更新上课记录 上课的时候才更新
                   if (data.type !== 'preview') {
                     await classCourseScheduleUpdate();

+ 7 - 3
src/views/xiaoku-ai/index.tsx

@@ -224,15 +224,19 @@ export default defineComponent({
                     <div
                       class={styles.item}
                       key={`item-${index}`}
-                      onClick={() =>
+                      onClick={() => {
+                        sessionStorage.setItem(
+                          'musicSubjectList',
+                          JSON.stringify(item.subjects)
+                        );
                         router.push({
                           path: '/xiaoku-music',
                           query: {
                             id: item.id,
                             name: item.name
                           }
-                        })
-                      }>
+                        });
+                      }}>
                       <div class={styles.cover}>
                         <div class={styles.itemImg}>
                           <div class={styles.itemBg}></div>

+ 17 - 10
src/views/xiaoku-music/index.tsx

@@ -78,10 +78,13 @@ export default defineComponent({
     const userStore = useUserStore();
     let musicsrc = '';
     const getSubjects = async () => {
-      const res = await api_subjectList();
-      if (Array.isArray(res?.data)) {
-        data.tags = [{ name: '全部', id: 0 }, ...res.data];
-      }
+      // const res = await api_subjectList();
+      // if (Array.isArray(res?.data)) {
+      const subjectList = sessionStorage.getItem('musicSubjectList')
+        ? JSON.parse(sessionStorage.getItem('musicSubjectList') as any)
+        : [];
+      data.tags = [{ name: '全部', id: 0 }, ...subjectList];
+      // }
     };
     const getList = async () => {
       data.loading = true;
@@ -130,8 +133,8 @@ export default defineComponent({
 
     // ifram事件处理
     const iframeHandle = (ev: MessageEvent) => {
-      if (ev.data?.api === 'api_fingerPreView'){
-        data.showCloseBtn = !ev.data.state
+      if (ev.data?.api === 'api_fingerPreView') {
+        data.showCloseBtn = !ev.data.state;
       }
     };
 
@@ -150,7 +153,7 @@ export default defineComponent({
     });
     onUnmounted(() => {
       window.removeEventListener('message', iframeHandle);
-    })
+    });
     /** 查看收藏状态 */
     const getFavitor = async (item: any) => {
       const res = await api_materialFavoriteStatus({
@@ -415,8 +418,12 @@ export default defineComponent({
                       ? 'https://test.lexiaoya.cn'
                       : location.origin;
                     const src = `${origin}/instrument?platform=pc&showGuide=true&id=${activeItem.value.id}&Authorization=${user.getToken}`;
-                    if (window.matchMedia('(display-mode: standalone)').matches) {
-                      state.application = window.matchMedia('(display-mode: standalone)').matches
+                    if (
+                      window.matchMedia('(display-mode: standalone)').matches
+                    ) {
+                      state.application = window.matchMedia(
+                        '(display-mode: standalone)'
+                      ).matches;
                       data.previewModal = true;
                       data.previewUrl = src;
                       data.showPreivew = false;
@@ -477,7 +484,7 @@ export default defineComponent({
           displayDirective="show">
           <NSpin show={data.showPreivew} style="--n-opacity-spinning: 1;">
             <img
-              style={{display: data.showCloseBtn ? '' : 'none'}}
+              style={{ display: data.showCloseBtn ? '' : 'none' }}
               src={icon_close}
               class={styles.previewClose}
               onClick={() => {

+ 2 - 0
src/views/xiaoku-music/type.ts

@@ -1,3 +1,5 @@
+import { ref } from 'vue';
+
 /** 曲谱信息 */
 export interface IMusicItem {
   id: number | string;