Browse Source

Merge branch 'iteration-loadingFix' into jenkins

lex-xin 1 month ago
parent
commit
9b0a70989d

+ 6 - 3
src/views/coursewarePlay/component/points-search.tsx

@@ -59,7 +59,7 @@ export default defineComponent({
         pointData.liftChildActive = props.tabActive[2] || '';
       }
     );
-    
+
     watch(() => props.open, () => {
       pointData.search = props.search
     })
@@ -86,7 +86,7 @@ export default defineComponent({
       <div class={styles.container}>
         <div class={styles.pointHeadSearch}>
           <OSearch placeholder='请输入素材关键词' modelValue={pointData.search} background='transparent' inputBackground='rgba(255, 255, 255, 0.15)' onSearch={(val: any) => {
-            // 
+            //
             if(props.loading) return
             pointData.isSearch = true
             pointData.search = val
@@ -99,7 +99,7 @@ export default defineComponent({
         {props.loading && <div class={styles.lading}>
             <Loading size={24} color='rgba(255, 255, 255, 0.8)' /> <span class={styles.loadingText}>加载中...</span>
           </div>}
-          
+
           {/* {props.loading && <OLoading />} */}
           {!props.loading && !props.data.length && <OEmpty tips="暂无搜索结果" />}
           {props.data.length > 0 ? <Collapse
@@ -135,6 +135,7 @@ export default defineComponent({
                                   emit('handleSelect', {
                                     isSearch: pointData.isSearch,
                                     itemActive: n.id,
+                                    materialId: n.materialId,
                                     tabActive: item.id,
                                     tabName: item.name
                                   });
@@ -196,6 +197,7 @@ export default defineComponent({
                                                   emit('handleSelect', {
                                                     isSearch: pointData.isSearch,
                                                     itemActive: n.id,
+                                                    materialId: n.materialId,
                                                     tabActive: child.id,
                                                     tabName: child.name
                                                   });
@@ -257,6 +259,7 @@ export default defineComponent({
                                                                     emit('handleSelect', {
                                                                       isSearch: pointData.isSearch,
                                                                       itemActive: n.id,
+                                                                      materialId: n.materialId,
                                                                       tabActive: liftChild.id,
                                                                       tabName: liftChild.name
                                                                     });

+ 1 - 1
src/views/coursewarePlay/index.module.less

@@ -210,7 +210,7 @@
 .fullBtn {
   width: 24px;
   height: 24px;
-  padding: 10px 9px;
+  padding: 8px 9px;
   display: flex;
   flex-direction: column;
   align-items: center;

+ 124 - 128
src/views/coursewarePlay/index.tsx

@@ -1,4 +1,4 @@
-import { closeToast, Icon, Popup, showDialog, showToast, Tab } from 'vant';
+import { closeToast, Icon, Popup, showDialog, showToast } from 'vant';
 import {
   defineComponent,
   onMounted,
@@ -16,7 +16,7 @@ import styles from './index.module.less';
 import 'plyr/dist/plyr.css';
 import request from '@/helpers/request';
 import { handleShowVip, state } from '@/state';
-import { useRoute } from 'vue-router';
+import { useRoute, useRouter } from 'vue-router';
 import {
   listenerMessage,
   postMessage,
@@ -48,6 +48,7 @@ import PointsSearch from './component/points-search';
 export default defineComponent({
   name: 'CoursewarePlay',
   setup() {
+    const router = useRouter();
     const browserInfo = browser()
     const { isOnline } = useNetwork()
     const pageVisibility = usePageVisibility();
@@ -76,20 +77,7 @@ export default defineComponent({
     const parentContainer = reactive({
       width: '100vw'
     });
-    // const setContainer = () => {
-    //   const min = Math.min(screen.width, screen.height);
-    //   const max = Math.max(screen.width, screen.height);
-    //   const width = min * (16 / 9);
-    //   if (width > max) {
-    //     parentContainer.width = '100vw';
-    //     return;
-    //   } else {
-    //     parentContainer.width = width + 'px';
-    //   }
-    // };
     const handleInit = (type = 0) => {
-      //设置容器16:9
-      // setContainer();
       // 横屏
       postMessage(
         {
@@ -102,13 +90,6 @@ export default defineComponent({
           // console.log(234);
         }
       );
-      // 头,包括返回箭头
-      // postMessage({
-      //   api: 'setTitleBarVisibility',
-      //   content: {
-      //     status: type
-      //   }
-      // })
       // 安卓的状态栏
       postMessage({
         api: 'setStatusBarVisibility',
@@ -136,10 +117,12 @@ export default defineComponent({
     const detailList = shallowRef<any[]>()// 搜索来的所有数据
     const data = reactive({
       source: route.query.source as any, // 来源 search  搜索
+      isSearch: route.query.source === "search" ? true : false, // 是否搜索
       searchLoading: false, // 搜索加载状态
-      search: route.query.search as any, // 默认的搜索条件 - 
-      searchTemp: route.query.search as any, // 默认的搜索条件 - 
+      search: route.query.search as any, // 默认的搜索条件 -
+      searchTemp: route.query.search as any, // 默认的搜索条件 -
       currentId: route.query.id as any || route.query.lessonId as any,
+      lessonId: null as any, // 课程id
       lessonCoursewareId: "",
       // detailList: [], // 搜索来的所有数据
       detail: null as any,
@@ -250,7 +233,7 @@ export default defineComponent({
         );
         _firstIndex = _firstIndex > -1 ? _firstIndex : 0;
         const item = list[_firstIndex];
-  
+
         // console.log(_firstIndex, '_firstIndex', route.query.kId, 'route.query.kId', item)
         // 是否自动播放
         if (activeData.isAutoPlay) {
@@ -312,6 +295,7 @@ export default defineComponent({
         const result = res.data || {}
         result.lessonTargetDesc = result.lessonTargetDesc ? result.lessonTargetDesc.replace(/\n/g, "<br />") : ""
         data.detail = result;
+        data.lessonId = result.lessonCoursewareId
         data.lessonCoursewareId = result.lessonCoursewareId
         if (res?.data?.lockFlag) {
           postMessage({
@@ -512,6 +496,21 @@ export default defineComponent({
             allList.push(...itemResult.list)
           }
         }
+
+        // 单独处理不是从搜索来的
+        if(data.source !== 'search') {
+          if(params.type === "pointSearch") {
+            detailTempSearchList.value = result
+            popupData.tempTabActive = allList.length > 0 ? allList[0].knowledgePointId : []
+            popupData.tempItemActive = "-1"
+            data.searchTemp = params.search
+            return
+          }
+          detailList.value = result
+          detailTempSearchList.value = result
+          return
+        }
+
         if(params.type === 'pointSearch') {
           detailTempSearchList.value = result
 
@@ -569,7 +568,7 @@ export default defineComponent({
           }, 500);
         });
 
-        
+
         return true
       } catch (error) {
         console.log(error);
@@ -686,12 +685,12 @@ export default defineComponent({
         data.refLevelList = res.data || []
         return true
       } catch {
-        // 
+        //
       }
     }
 
     onMounted(async () => {
-      // 键盘唤起  0是顶起 1是覆盖 
+      // 键盘唤起  0是顶起 1是覆盖
       postMessage({
         api: 'setSoftInputMode',
         content: {
@@ -706,6 +705,7 @@ export default defineComponent({
       } else {
         await getRefLevel()
         await getDetail();
+        data.lessonId && await getSearchDetail({search: data.search, id: data.lessonId})
       }
       isHidden.value = false;
       // getCourseSchedule();
@@ -731,18 +731,12 @@ export default defineComponent({
     // const playRef = ref();
     // 返回
     const goBack = () => {
-      // console.log('back -----');
-      // try {
-      //   playRef.value?.handleOut();
-      // } catch (error) {
-      //   console.log(error);
-      // }
       postMessage({ api: 'back' });
     };
 
     const popupData = reactive({
       pointOpen: false,
-      pointContent: "", 
+      pointContent: "",
       pointTitle: "",
       coursewareOpen: false,
       open: false,
@@ -999,45 +993,6 @@ export default defineComponent({
     // 播放视频总时长
     const videoIntervalRef = useInterval(1000, { controls: true });
     videoIntervalRef.pause();
-    /**
-     * 格式化视屏播放有效时间 - 合并区间
-     * @param intervals [[], []]
-     * @example [[4, 8],[0, 4],[10, 30]]
-     * @returns [[0, 8], [10, 30]]
-     */
-    // const formatEffectiveTime = (intervals: any[]) => {
-    //   const res: any = [];
-    //   intervals.sort((a, b) => a[0] - b[0]);
-    //   let prev = intervals[0];
-    //   for (let i = 1; i < intervals.length; i++) {
-    //     const cur = intervals[i];
-    //     if (prev[1] >= cur[0]) {
-    //       // 有重合
-    //       prev[1] = Math.max(cur[1], prev[1]);
-    //     } else {
-    //       // 不重合,prev推入res数组
-    //       res.push(prev);
-    //       prev = cur; // 更新 prev
-    //     }
-    //   }
-    //   res.push(prev);
-    //   // console.log(res, 'formatEffectiveTime')
-
-    //   return res;
-    // };
-    /**
-     * 获取数据有效期
-     * @param intervals [[], []]
-     * @returns 0s
-     */
-    // const formatTimer = (intervals: any[]) => {
-    //   const afterIntervals = formatEffectiveTime(intervals);
-    //   let time = 0;
-    //   afterIntervals.forEach((t: any) => {
-    //     time += t[1] - t[0];
-    //   });
-    //   return time;
-    // };
 
     // 保存零时时间
     // const moreTime: any = ref([]) // 多个观看时间段 已经放到列表里面了
@@ -1188,7 +1143,7 @@ export default defineComponent({
                   data.animationState = 'end';
                   if(whitePenShow.value || penShow.value || popupData.coursewareOpen || popupData.open || popupData.guideOpen || popupData.pointOpen) {
                     handleStop()
-                  } 
+                  }
                 }}
                 onLoadedmetadata={(videoItem: any) => {
                   data.videoState = 'play';
@@ -1255,7 +1210,7 @@ export default defineComponent({
                       ? effects[effectIndex.value].next
                       : {}
                   }>
-                  
+
                   <Transition name="van-fade">
                     {m.typeCode === 'VIDEO' &&
                       data.animationState !== 'end' &&
@@ -1321,50 +1276,51 @@ export default defineComponent({
             {activeData.model && (
               <div class={styles.leftFixedBtns} onClick={(e: Event) => e.stopPropagation()}>
                 <div class={[styles.btnsWrap, styles.prePoint]}>
-                  {data.source === 'search' ? 
-                    <div class={styles.fullBtn} onClick={() => {
-                      handleStop()
-                      detailTempSearchList.value = detailList.value
-                      popupData.tempItemActive = ""
-                      popupData.tempTabActive = ""
-                      data.searchTemp = ""
-                      // data.searchTemp = JSON.parse(JSON.stringify(data.search))
-                      popupData.open = true
-                    }}>
-                      <img src={iconSearch} />
-                    </div> : <>
-                    <div class={styles.fullBtn} onClick={() => {
-                      handleStop()
-                      popupData.coursewareOpen = true
-                    }}>
-                      <img src={iconCourseType} />
-                    </div>
-                    <div class={styles.fullBtn} onClick={() => {
-                      handleStop()
-                      popupData.open = true
-                    }}>
-                      <img src={iconMenu} />
-                    </div>
-                  </>}
-
-                    <div
-                      class={[styles.fullBtn, !(popupData.activeIndex != 0) && styles.disabled]}
-                      onClick={() => {
-                        if(popupData.activeIndex != 0) handlePreAndNext('up')
-                      }}
-                    >
-                      <img src={iconUp} />
-                      {/* <span style={{ textAlign: 'center' }}>上一个</span> */}
-                    </div>
-                    <div
-                      class={[styles.fullBtn, !(popupData.activeIndex != data.itemList.length - 1) && styles.disabled]}
-                      onClick={() => {
-                        if(popupData.activeIndex != data.itemList.length - 1) handlePreAndNext('down')
-                      }}
-                    >
-                      {/* <span style={{ textAlign: 'center' }}>下一个</span> */}
-                      <img src={iconDown} />
-                    </div>
+                  {data.source !== 'search' && <div class={styles.fullBtn} onClick={() => {
+                    handleStop()
+                    popupData.coursewareOpen = true
+                  }}>
+                    <img src={iconCourseType} />
+                  </div>}
+
+                  <div class={styles.fullBtn} onClick={() => {
+                    handleStop()
+                    data.isSearch = true
+                    detailTempSearchList.value = detailList.value
+                    popupData.tempItemActive = ""
+                    popupData.tempTabActive = ""
+                    data.searchTemp = ""
+                    // data.searchTemp = JSON.parse(JSON.stringify(data.search))
+                    popupData.open = true
+                  }}>
+                    <img src={iconSearch} />
+                  </div>
+                  {data.source !== 'search' && <div class={styles.fullBtn} onClick={() => {
+                    handleStop()
+                    data.isSearch = false
+                    popupData.open = true
+                  }}>
+                    <img src={iconMenu} />
+                  </div>}
+
+                  <div
+                    class={[styles.fullBtn, !(popupData.activeIndex != 0) && styles.disabled]}
+                    onClick={() => {
+                      if(popupData.activeIndex != 0) handlePreAndNext('up')
+                    }}
+                  >
+                    <img src={iconUp} />
+                    {/* <span style={{ textAlign: 'center' }}>上一个</span> */}
+                  </div>
+                  <div
+                    class={[styles.fullBtn, !(popupData.activeIndex != data.itemList.length - 1) && styles.disabled]}
+                    onClick={() => {
+                      if(popupData.activeIndex != data.itemList.length - 1) handlePreAndNext('down')
+                    }}
+                  >
+                    {/* <span style={{ textAlign: 'center' }}>下一个</span> */}
+                    <img src={iconDown} />
+                  </div>
                  </div>
               </div>
             )}
@@ -1414,7 +1370,7 @@ export default defineComponent({
           round
           v-model:show={popupData.open}
           onClose={handleClosePopup}>
-            {data.source === 'search' ? 
+            {data.isSearch ?
               <PointsSearch
                 data={detailTempSearchList.value}
                 search={data.searchTemp || data.search}
@@ -1423,6 +1379,37 @@ export default defineComponent({
                 itemActive={popupData.tempItemActive || popupData.itemActive}
                 open={popupData.open}
                 onHandleSelect={(res: any) => {
+                  if(data.source !== "search") {
+                    if (browser().isApp) {
+                      postMessage({
+                        api: 'openWebView',
+                        content: {
+                          url: `${location.origin}${location.pathname}#/coursewarePlay?lessonId=${data.lessonId}&source=search&kId=${res.materialId}&search=${encodeURIComponent(data.searchTemp ? JSON.parse(JSON.stringify(data.searchTemp)) : '')}`,
+                          orientation: 0,
+                          isHideTitle: true,
+                          statusBarTextColor: false,
+                          isOpenLight: true,
+                          showLoadingAnim: true
+                        }
+                      });
+                      return
+                    } else {
+                      router.push({
+                        path: '/coursewarePlay',
+                        query: {
+                          lessonId: data.lessonId,
+                          kId: res.materialId,
+                          search: data.searchTemp ? JSON.parse(JSON.stringify(data.searchTemp)) : '',
+                          source: 'search'
+                        }
+                      }).then(() => {
+                        window.location.reload()
+                      });
+                      // showToast('请使用App打开')
+                      return
+                    }
+                  }
+
                   popupData.open = false;
                   if(res.isSearch) {
                     detailList.value = detailTempSearchList.value
@@ -1440,13 +1427,21 @@ export default defineComponent({
                 onHandleSearch={async (val: any) => {
                   data.searchLoading = true
                   detailTempSearchList.value = []
-                  await getSearchDetail({
-                    type: 'pointSearch',
-                    search: val.search
-                  })
+                  if(data.source === 'search') {
+                    await getSearchDetail({
+                      type: 'pointSearch',
+                      search: val.search
+                    })
+                  } else {
+                    await getSearchDetail({
+                      type: 'pointSearch',
+                      search: val.search,
+                      id: data.lessonId
+                    })
+                  }
                   data.searchTemp = val.search;
                   data.searchLoading = false
-                }} /> : 
+                }} /> :
               <Points
                 data={data.knowledgePointList}
                 tabActive={popupData.tabActive}
@@ -1456,7 +1451,7 @@ export default defineComponent({
                   toggleMaterial(res.itemActive);
                 }}
               />}
-          
+
         </Popup>
 
         <Popup
@@ -1481,7 +1476,7 @@ export default defineComponent({
 
               const n = await getDetail("", item.id);
               const s = await getRefLevel(item.id);
-
+              data.isSearch = false
               if(n && s) {
                 data.currentId = item.id;
                 popupData.coursewareOpen = false;
@@ -1495,6 +1490,7 @@ export default defineComponent({
                   showToast('网络异常')
                 }
               }
+              data.lessonId && await getSearchDetail({search: data.search, id: data.lessonId})
             }} />
         </Popup>
 

+ 3 - 3
src/views/lessonCourseware/component/CourseItem/index.tsx

@@ -1,8 +1,8 @@
 import { defineComponent, PropType } from 'vue';
 import styles from './index.module.less';
-import iconTop from './image/icon-top.png';
-import iconLock from './image/icon-lock.png';
-import { Image, Loading } from 'vant';
+// import iconTop from './image/icon-top.png';
+// import iconLock from './image/icon-lock.png';
+// import { Image, Loading } from 'vant';
 
 export default defineComponent({
   name: 'CourseItem',