index.tsx 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  1. import { closeToast, Icon, Popup, showDialog, showToast } from 'vant';
  2. import {
  3. defineComponent,
  4. onMounted,
  5. reactive,
  6. nextTick,
  7. onUnmounted,
  8. ref,
  9. watch,
  10. Transition,
  11. computed
  12. } from 'vue';
  13. import iconBack from './image/back.svg';
  14. import styles from './index.module.less';
  15. import 'plyr/dist/plyr.css';
  16. import { useRoute, useRouter } from 'vue-router';
  17. import {
  18. listenerMessage,
  19. postMessage,
  20. promisefiyPostMessage,
  21. removeListenerMessage
  22. } from '@/helpers/native-message';
  23. import MusicScore from './component/musicScore';
  24. import iconMenu from './image/icon-menu.svg';
  25. import iconChange from './image/icon-change.svg';
  26. import iconDian from './image/icon-dian.svg';
  27. import iconPoint from './image/icon-point.svg';
  28. import iconUp from './image/icon-up.svg';
  29. import iconDown from './image/icon-down.svg';
  30. import Points from './component/points';
  31. import { browser, getSecondRPM } from '@/helpers/utils';
  32. import { Vue3Lottie } from 'vue3-lottie';
  33. import playLoadData from './datas/data.json';
  34. import { usePageVisibility } from '@vant/use';
  35. import AudioItem from './component/audio-item';
  36. import {
  37. api_classLessonCoursewareQuery,
  38. api_lessonCoursewareKnowledgeDetailDetail
  39. } from './api';
  40. import VideoItem from './component/video-item';
  41. import Chapter from './component/chapter';
  42. import {
  43. api_classLessonCoursewareDetail,
  44. api_lessonCoursewareDetail
  45. } from '../courseware-list/api';
  46. import detail from '../information/help-center/detail';
  47. import { state } from '@/state';
  48. export default defineComponent({
  49. name: 'CoursewarePlay',
  50. setup() {
  51. const pageVisibility = usePageVisibility();
  52. const lastTimeKey = 'lastTime' + (state?.user?.data?.phone ?? '');
  53. /** 设置播放容器 16:9 */
  54. const parentContainer = reactive({
  55. width: '100vw'
  56. });
  57. const setContainer = () => {
  58. let min = Math.min(screen.width, screen.height);
  59. let max = Math.max(screen.width, screen.height);
  60. let width = min * (16 / 9);
  61. if (width > max) {
  62. parentContainer.width = '100vw';
  63. return;
  64. } else {
  65. parentContainer.width = width + 'px';
  66. }
  67. };
  68. const handleInit = (type = 0) => {
  69. //设置容器16:9
  70. setContainer();
  71. // 横屏
  72. // postMessage(
  73. // {
  74. // api: 'setRequestedOrientation',
  75. // content: {
  76. // orientation: type
  77. // }
  78. // },
  79. // () => {
  80. // console.log(234);
  81. // }
  82. // );
  83. // 头,包括返回箭头
  84. // postMessage({
  85. // api: 'setTitleBarVisibility',
  86. // content: {
  87. // status: type
  88. // }
  89. // })
  90. // 安卓的状态栏
  91. postMessage({
  92. api: 'setStatusBarVisibility',
  93. content: {
  94. isVisibility: type
  95. }
  96. });
  97. // 进入页面设置常量
  98. postMessage({
  99. api: 'keepScreenLongLight',
  100. content: {
  101. isOpenLight: type ? true : false
  102. }
  103. });
  104. };
  105. handleInit();
  106. onUnmounted(() => {
  107. handleInit(1);
  108. window.removeEventListener('message', iframeHandle);
  109. });
  110. const getCourseDetail = async () => {
  111. try {
  112. if (route.query.tab == 'course') {
  113. const res = await api_classLessonCoursewareDetail({
  114. id: activeData.courseId as any,
  115. subjectId: activeData.subjectId
  116. });
  117. if (res?.code == 200 && Array.isArray(res?.data?.lessonList)) {
  118. data.courseDetails = res.data.lessonList || [];
  119. console.log('🚀 ~ data.details course:', data.courseDetails);
  120. }
  121. } else {
  122. const res = await api_lessonCoursewareDetail({
  123. id: route.query.lessonCoursewareId as any,
  124. subjectId: activeData.subjectId
  125. });
  126. if (res?.code == 200 && Array.isArray(res?.data?.lessonList)) {
  127. data.courseDetails = res.data.lessonList || [];
  128. }
  129. }
  130. console.log(data.courseDetails, 'data.courseDetails');
  131. } catch {
  132. //
  133. }
  134. };
  135. const route = useRoute();
  136. const headeRef = ref();
  137. const loadingClass = ref(false); // 重新加载课件
  138. const data = reactive({
  139. knowledgePointList: [] as any,
  140. courseDetails: [] as any,
  141. itemList: [] as any,
  142. videoRefs: {} as any[],
  143. videoState: 'init' as 'init' | 'play',
  144. videoItemRef: null as any,
  145. animationState: 'start' as 'start' | 'end'
  146. });
  147. const activeData = reactive({
  148. isAutoPlay: true, // 是否自动播放
  149. subjectId: route.query.subjectId,
  150. lessonCoursewareId: route.query.lessonCoursewareId,
  151. lessonCoursewareDetailId: route.query.lessonCoursewareDetailId,
  152. coursewareDetailKnowledgeId: route.query.id,
  153. courseId: route.query.courseId, // 我的课程专用编号
  154. nowTime: 0,
  155. model: true, // 遮罩
  156. isAnimation: true, // 是否动画
  157. videoBtns: true, // 视频
  158. currentTime: 0,
  159. duration: 0,
  160. timer: null as any,
  161. item: null as any
  162. });
  163. const getDetail = async () => {
  164. let courseList: any[] = [];
  165. if (route.query.tab == 'course') {
  166. const res = await api_classLessonCoursewareQuery({
  167. coursewareDetailKnowledgeId: activeData.coursewareDetailKnowledgeId,
  168. subjectId: activeData.subjectId,
  169. page: 1,
  170. rows: -1
  171. });
  172. if (res?.code === 200 && Array.isArray(res.data.rows)) {
  173. const tempRows = res.data.rows || [];
  174. tempRows.forEach((item: any) => {
  175. courseList.push({
  176. content: item.content,
  177. coverImg: item.coverImg,
  178. id: item.id,
  179. materialId: item.materialId,
  180. name: item.materialName,
  181. relOrder: 0,
  182. sourceFrom: item.source,
  183. type: item.materialType
  184. });
  185. });
  186. }
  187. } else {
  188. const res = await api_lessonCoursewareKnowledgeDetailDetail({
  189. lessonCoursewareKnowledgeDetailId:
  190. activeData.coursewareDetailKnowledgeId,
  191. subjectId: activeData.subjectId
  192. });
  193. if (res?.code === 200 && Array.isArray(res.data)) {
  194. courseList = res.data || [];
  195. }
  196. }
  197. // 课程
  198. if (courseList.length > 0) {
  199. data.knowledgePointList = courseList.map((item: any) => {
  200. return {
  201. ...item,
  202. url:
  203. item.type === 'SONG'
  204. ? 'https://gyt.ks3-cn-beijing.ksyuncs.com/courseware/1687916228530.png'
  205. : item.coverImg
  206. };
  207. });
  208. }
  209. data.itemList = data.knowledgePointList.map((m: any, index: number) => {
  210. if (!popupData.itemActive) {
  211. popupData.itemActive = m.id;
  212. popupData.itemName = m.name;
  213. }
  214. return {
  215. ...m,
  216. iframeRef: null,
  217. videoEle: null,
  218. autoPlay: false, //加载完成是否自动播放
  219. isprepare: false, // 视频是否加载完成
  220. isRender: false // 是否渲染了
  221. };
  222. });
  223. setTimeout(() => {
  224. data.animationState = 'end'
  225. }, 500)
  226. };
  227. // ifram事件处理
  228. const iframeHandle = (ev: MessageEvent) => {
  229. if (ev.data?.api === 'headerTogge') {
  230. activeData.model =
  231. ev.data.show || (ev.data.playState == 'play' ? false : true);
  232. }
  233. if (ev.data?.api === 'api_fingerPreView') {
  234. clearInterval(activeData.timer);
  235. activeData.model = !ev.data.state;
  236. }
  237. };
  238. onMounted(() => {
  239. postMessage({
  240. api: 'courseLoading',
  241. content: {
  242. show: false,
  243. type: 'fullscreen'
  244. }
  245. });
  246. getDetail();
  247. getCourseDetail();
  248. window.addEventListener('message', iframeHandle);
  249. });
  250. const playRef = ref();
  251. // 返回
  252. const goback = () => {
  253. try {
  254. playRef.value?.handleOut();
  255. } catch (error) {}
  256. postMessage({ api: 'goBack' });
  257. // router.back()
  258. };
  259. const popupData = reactive({
  260. open: false,
  261. activeIndex: 0,
  262. itemActive: '',
  263. itemName: '',
  264. itemPointName: route.query.name as any,
  265. chapterOpen: false
  266. });
  267. // 切换素材
  268. const toggleMaterial = (itemActive: any) => {
  269. const index = data.itemList.findIndex((n: any) => n.id == itemActive);
  270. if (index > -1) {
  271. handleSwipeChange(index);
  272. }
  273. };
  274. /** 延迟收起模态框 */
  275. const setModelOpen = () => {
  276. clearTimeout(activeData.timer);
  277. closeToast();
  278. activeData.model = !activeData.model;
  279. activeData.timer = setTimeout(() => {
  280. activeData.model = false;
  281. }, 4000);
  282. };
  283. // 双击
  284. const handleDbClick = (item: any) => {
  285. if (item && ['VIDEO'].includes(item.type)) {
  286. console.log('双击');
  287. }
  288. };
  289. const effectIndex = ref(3);
  290. const effects = [
  291. {
  292. prev: {
  293. transform: 'translate3d(0, 0, -800px) rotateX(180deg)'
  294. },
  295. next: {
  296. transform: 'translate3d(0, 0, -800px) rotateX(-180deg)'
  297. }
  298. },
  299. {
  300. prev: {
  301. transform: 'translate3d(-100%, 0, -800px)'
  302. },
  303. next: {
  304. transform: 'translate3d(100%, 0, -800px)'
  305. }
  306. },
  307. {
  308. prev: {
  309. transform: 'translate3d(-50%, 0, -800px) rotateY(80deg)'
  310. },
  311. next: {
  312. transform: 'translate3d(50%, 0, -800px) rotateY(-80deg)'
  313. }
  314. },
  315. {
  316. prev: {
  317. transform: 'translate3d(-100%, 0, -800px) rotateY(-120deg)',
  318. opacity: 0
  319. },
  320. next: {
  321. transform: 'translate3d(100%, 0, -800px) rotateY(120deg)',
  322. opacity: 0
  323. }
  324. },
  325. // 风车4
  326. {
  327. prev: {
  328. transform: 'translate3d(-50%, 50%, -800px) rotateZ(-14deg)',
  329. opacity: 0
  330. },
  331. next: {
  332. transform: 'translate3d(50%, 50%, -800px) rotateZ(14deg)',
  333. opacity: 0
  334. }
  335. },
  336. // 翻页5
  337. {
  338. prev: {
  339. transform: 'translateZ(-800px) rotate3d(0, -1, 0, 90deg)',
  340. opacity: 0
  341. },
  342. next: {
  343. transform: 'translateZ(-800px) rotate3d(0, 1, 0, 90deg)',
  344. opacity: 0
  345. },
  346. current: { transitionDelay: '700ms' }
  347. }
  348. ];
  349. const handleStop = () => {
  350. data.videoItemRef.pause();
  351. }
  352. const acitveTimer = ref();
  353. // 轮播切换
  354. const handleSwipeChange = (index: number) => {
  355. // 如果是当前正在播放 或者是视频最后一个
  356. if (popupData.activeIndex == index) return;
  357. data.animationState = 'start'
  358. data.videoState = 'init'
  359. handleStop();
  360. clearTimeout(acitveTimer.value);
  361. activeData.model = true;
  362. const item = data.itemList[index];
  363. popupData.activeIndex = index;
  364. popupData.itemActive = item.id;
  365. popupData.itemName = item.name;
  366. if (item.type == 'MUSIC') {
  367. activeData.model = true;
  368. } else if (item.type == 'VIDEO') {
  369. if (item.error) {
  370. data.videoRefs[index]?.onPlay();
  371. }
  372. setTimeout(() => {
  373. data.animationState = 'end'
  374. }, 800)
  375. }
  376. };
  377. // 上一个知识点, 下一个知识点
  378. const handlePreAndNext = async (type: string) => {
  379. if (type === 'up') {
  380. // 判断上面是否还有章节
  381. if (popupData.activeIndex > 0) {
  382. handleSwipeChange(popupData.activeIndex - 1);
  383. return;
  384. }
  385. // 获取当前是哪个章节
  386. let detailIndex = data.courseDetails.findIndex(
  387. (item: any) => item.id == activeData.lessonCoursewareDetailId
  388. );
  389. const detailItem = data.courseDetails[detailIndex]?.knowledgeList || [];
  390. let lessonIndex = detailItem.findIndex(
  391. (item: any) => item.id == activeData.coursewareDetailKnowledgeId
  392. );
  393. let lessonStatus = false; // 当前章节上面是否有内容
  394. let lessonCoursewareDetailId = '';
  395. let coursewareDetailKnowledgeId = '';
  396. let coursewareDetailKnowledgeName = '';
  397. while (lessonIndex >= 0) {
  398. lessonIndex--;
  399. if (lessonIndex >= 0) {
  400. if (detailItem[lessonIndex].containMaterial) {
  401. lessonStatus = true;
  402. lessonCoursewareDetailId =
  403. detailItem[lessonIndex].lessonCoursewareDetailId;
  404. coursewareDetailKnowledgeId = detailItem[lessonIndex].id;
  405. coursewareDetailKnowledgeName = detailItem[lessonIndex].name;
  406. }
  407. }
  408. if (lessonStatus) {
  409. break;
  410. }
  411. }
  412. // 判断当前章节下面课程是否有内容,否则往上一个章节走
  413. if (lessonStatus) {
  414. loadingClass.value = true;
  415. activeData.coursewareDetailKnowledgeId = coursewareDetailKnowledgeId;
  416. activeData.lessonCoursewareDetailId = lessonCoursewareDetailId;
  417. await getDetail();
  418. popupData.activeIndex = data.itemList.length - 1 || 0;
  419. popupData.itemActive =
  420. data.knowledgePointList[data.itemList.length - 1]?.id ||
  421. data.knowledgePointList[0]?.id;
  422. popupData.itemPointName = coursewareDetailKnowledgeName;
  423. popupData.itemName =
  424. data.knowledgePointList[data.itemList.length - 1]?.name ||
  425. data.knowledgePointList[0]?.name;
  426. localStorage.setItem(lastTimeKey, coursewareDetailKnowledgeId);
  427. popupData.chapterOpen = false;
  428. loadingClass.value = false;
  429. return;
  430. }
  431. let prevLessonStatus = false;
  432. while (detailIndex >= 0) {
  433. detailIndex--;
  434. const tempDetail =
  435. data.courseDetails[detailIndex]?.knowledgeList || [];
  436. let tempLessonLength = tempDetail.length;
  437. while (tempLessonLength > 0) {
  438. if (tempDetail[tempLessonLength - 1].containMaterial) {
  439. prevLessonStatus = true;
  440. lessonCoursewareDetailId =
  441. tempDetail[tempLessonLength - 1].lessonCoursewareDetailId;
  442. coursewareDetailKnowledgeId = tempDetail[tempLessonLength - 1].id;
  443. coursewareDetailKnowledgeName =
  444. tempDetail[tempLessonLength - 1].name;
  445. }
  446. tempLessonLength--;
  447. if (prevLessonStatus) {
  448. break;
  449. }
  450. }
  451. if (prevLessonStatus) {
  452. break;
  453. }
  454. }
  455. // 判断当前章节下面课程是否有内容,否则往上一个章节走
  456. if (prevLessonStatus) {
  457. loadingClass.value = true;
  458. activeData.coursewareDetailKnowledgeId = coursewareDetailKnowledgeId;
  459. activeData.lessonCoursewareDetailId = lessonCoursewareDetailId;
  460. await getDetail();
  461. popupData.activeIndex = data.itemList.length - 1 || 0;
  462. popupData.itemActive =
  463. data.knowledgePointList[data.itemList.length - 1]?.id ||
  464. data.knowledgePointList[0]?.id;
  465. localStorage.setItem(lastTimeKey, coursewareDetailKnowledgeId);
  466. popupData.itemPointName = coursewareDetailKnowledgeName;
  467. popupData.itemName =
  468. data.knowledgePointList[data.itemList.length - 1]?.name ||
  469. data.knowledgePointList[0]?.name;
  470. popupData.chapterOpen = false;
  471. loadingClass.value = false;
  472. return;
  473. }
  474. } else {
  475. if (popupData.activeIndex < data.itemList.length - 1) {
  476. handleSwipeChange(popupData.activeIndex + 1);
  477. return;
  478. }
  479. // 获取当前是哪个章节
  480. let detailIndex = data.courseDetails.findIndex(
  481. (item: any) => item.id == activeData.lessonCoursewareDetailId
  482. );
  483. const detailItem = data.courseDetails[detailIndex]?.knowledgeList || [];
  484. let lessonIndex = detailItem.findIndex(
  485. (item: any) => item.id == activeData.coursewareDetailKnowledgeId
  486. );
  487. let lessonStatus = false; // 当前章节下面是否有内容
  488. let lessonCoursewareDetailId = '';
  489. let coursewareDetailKnowledgeId = '';
  490. let coursewareDetailKnowledgeName = '';
  491. while (lessonIndex < detailItem.length - 1) {
  492. lessonIndex++;
  493. if (lessonIndex >= 0) {
  494. if (detailItem[lessonIndex].containMaterial) {
  495. lessonStatus = true;
  496. lessonCoursewareDetailId =
  497. detailItem[lessonIndex].lessonCoursewareDetailId;
  498. coursewareDetailKnowledgeId = detailItem[lessonIndex].id;
  499. coursewareDetailKnowledgeName = detailItem[lessonIndex].name;
  500. }
  501. }
  502. if (lessonStatus) {
  503. break;
  504. }
  505. }
  506. // 判断当前章节下面课程是否有内容,否则往下一个章节走
  507. if (lessonStatus) {
  508. loadingClass.value = true;
  509. activeData.coursewareDetailKnowledgeId = coursewareDetailKnowledgeId;
  510. activeData.lessonCoursewareDetailId = lessonCoursewareDetailId;
  511. await getDetail();
  512. popupData.activeIndex = 0;
  513. popupData.itemActive = data.knowledgePointList[0].id;
  514. popupData.itemName = data.knowledgePointList[0].name;
  515. localStorage.setItem(lastTimeKey, coursewareDetailKnowledgeId);
  516. popupData.itemPointName = coursewareDetailKnowledgeName;
  517. popupData.chapterOpen = false;
  518. loadingClass.value = false;
  519. return;
  520. }
  521. let nextLessonStatus = false;
  522. while (detailIndex <= data.courseDetails.length - 1) {
  523. detailIndex++;
  524. const tempDetail =
  525. data.courseDetails[detailIndex]?.knowledgeList || [];
  526. let tempLessonLength = 0;
  527. while (tempLessonLength <= tempDetail.length - 1) {
  528. if (tempDetail[tempLessonLength].containMaterial) {
  529. nextLessonStatus = true;
  530. lessonCoursewareDetailId =
  531. tempDetail[tempLessonLength].lessonCoursewareDetailId;
  532. coursewareDetailKnowledgeId = tempDetail[tempLessonLength].id;
  533. coursewareDetailKnowledgeName = tempDetail[tempLessonLength].name;
  534. }
  535. tempLessonLength++;
  536. if (nextLessonStatus) {
  537. break;
  538. }
  539. }
  540. if (nextLessonStatus) {
  541. break;
  542. }
  543. }
  544. // 判断当前章节下面课程是否有内容,否则往上一个章节走
  545. if (nextLessonStatus) {
  546. loadingClass.value = true;
  547. activeData.coursewareDetailKnowledgeId = coursewareDetailKnowledgeId;
  548. activeData.lessonCoursewareDetailId = lessonCoursewareDetailId;
  549. await getDetail();
  550. popupData.activeIndex = 0;
  551. popupData.itemActive = data.knowledgePointList[0].id;
  552. localStorage.setItem(lastTimeKey, coursewareDetailKnowledgeId);
  553. popupData.itemName = data.knowledgePointList[0].name;
  554. popupData.itemPointName = coursewareDetailKnowledgeName;
  555. popupData.chapterOpen = false;
  556. loadingClass.value = false;
  557. return;
  558. }
  559. }
  560. };
  561. /** 弹窗关闭 */
  562. const handleClosePopup = () => {
  563. // setModelOpen();
  564. };
  565. // popupData.activeIndex == 0 && styles.btnsDisabled
  566. // popupData.activeIndex == data.itemList.length - 1
  567. // 是否允许上一页
  568. const isUpArrow = computed(() => {
  569. /**
  570. * 1,判断当前课程中是否处在第一个资源;
  571. * 2,判断当前课程是否在当前章节的第一个;
  572. * 3,判断当前章节,当前课程上面还没有其它课程,是否有资源;
  573. * 4,判断当前章节上面还没有其它章节;
  574. * 5,判断上面章节里面课程是否有资源;
  575. */
  576. if (popupData.activeIndex > 0) {
  577. return true;
  578. }
  579. // 获取当前是哪个章节
  580. let detailIndex = data.courseDetails.findIndex(
  581. (item: any) => item.id == activeData.lessonCoursewareDetailId
  582. );
  583. const detailItem = data.courseDetails[detailIndex]?.knowledgeList || [];
  584. let lessonIndex = detailItem.findIndex(
  585. (item: any) => item.id == activeData.coursewareDetailKnowledgeId
  586. );
  587. // 说明已经是第一单元,第一课
  588. if (detailIndex <= 0 && lessonIndex <= 0) {
  589. return false;
  590. }
  591. let lessonStatus = false; // 当前章节上面是否有内容
  592. while (lessonIndex >= 0) {
  593. lessonIndex--;
  594. if (lessonIndex >= 0) {
  595. if (detailItem[lessonIndex].containMaterial) {
  596. lessonStatus = true;
  597. }
  598. }
  599. }
  600. // 判断当前章节下面课程是否有内容,否则往上一个章节走
  601. if (lessonStatus) {
  602. return true;
  603. }
  604. // 已经是第一个章节了
  605. if (detailIndex <= 0) {
  606. return false;
  607. }
  608. let prevLessonStatus = false;
  609. while (detailIndex >= 0) {
  610. detailIndex--;
  611. const tempDetail = data.courseDetails[detailIndex]?.knowledgeList || [];
  612. let tempLessonLength = tempDetail.length;
  613. while (tempLessonLength > 0) {
  614. if (tempDetail[tempLessonLength - 1].containMaterial) {
  615. prevLessonStatus = true;
  616. }
  617. tempLessonLength--;
  618. }
  619. if (prevLessonStatus) {
  620. return true;
  621. }
  622. }
  623. return false;
  624. });
  625. // 是否允许下一页
  626. const isDownArrow = computed(() => {
  627. if (popupData.activeIndex < data.itemList.length - 1) {
  628. return true;
  629. }
  630. // 获取当前是哪个章节
  631. let detailIndex = data.courseDetails.findIndex(
  632. (item: any) => item.id == activeData.lessonCoursewareDetailId
  633. );
  634. const detailItem = data.courseDetails[detailIndex]?.knowledgeList || [];
  635. let lessonIndex = detailItem.findIndex(
  636. (item: any) => item.id == activeData.coursewareDetailKnowledgeId
  637. );
  638. // 说明已经是最后-单元,最后一课
  639. if (
  640. detailIndex >= data.courseDetails.length - 1 &&
  641. lessonIndex >= detailItem.length - 1
  642. ) {
  643. return false;
  644. }
  645. let lessonStatus = false; // 当前章节下面是否有内容
  646. while (lessonIndex < detailItem.length - 1) {
  647. lessonIndex++;
  648. if (lessonIndex >= 0) {
  649. if (detailItem[lessonIndex].containMaterial) {
  650. lessonStatus = true;
  651. }
  652. }
  653. }
  654. // 判断当前章节下面课程是否有内容,否则往下一个章节走
  655. if (lessonStatus) {
  656. return true;
  657. }
  658. // 已经是最后一个章节了
  659. if (detailIndex >= data.courseDetails.length - 1) {
  660. return false;
  661. }
  662. let nextLessonStatus = false;
  663. while (detailIndex < data.courseDetails.length - 1) {
  664. detailIndex++;
  665. const tempDetail = data.courseDetails[detailIndex]?.knowledgeList || [];
  666. let tempLessonLength = 0;
  667. while (tempLessonLength <= tempDetail.length - 1) {
  668. if (tempDetail[tempLessonLength].containMaterial) {
  669. nextLessonStatus = true;
  670. }
  671. tempLessonLength++;
  672. }
  673. if (nextLessonStatus) {
  674. return true;
  675. }
  676. }
  677. return false;
  678. });
  679. const activeVideoItem = computed(() => {
  680. const item = data.itemList[popupData.activeIndex]
  681. if (item && item.type && item.type.toLocaleUpperCase() === 'VIDEO') {
  682. return item
  683. }
  684. return {}
  685. })
  686. return () => (
  687. <div id="playContent" class={styles.playContent}>
  688. <div
  689. class={styles.coursewarePlay}
  690. style={{ width: parentContainer.width }}
  691. onClick={() => setModelOpen()}>
  692. {!loadingClass.value && (
  693. <div class={styles.wraps}>
  694. <div
  695. style={
  696. activeVideoItem.value.type &&
  697. data.animationState === 'end' &&
  698. data.videoState === 'play'
  699. ? {
  700. zIndex: 15,
  701. opacity: 1
  702. }
  703. : { opacity: 0, zIndex: -1 }
  704. }
  705. class={styles.itemDiv}
  706. >
  707. <VideoItem
  708. ref={(el: any) => data.videoItemRef = el}
  709. item={activeVideoItem.value}
  710. showModel={activeData.model}
  711. onClose={setModelOpen}
  712. onCanplay={() => {
  713. data.videoState = 'play'
  714. }}
  715. onPause={() => {
  716. clearTimeout(activeData.timer)
  717. activeData.model = true
  718. }}
  719. onEnded={() => {
  720. const _index = popupData.activeIndex + 1
  721. if (_index < data.itemList.length) {
  722. handleSwipeChange(_index);
  723. }
  724. }}
  725. />
  726. </div>
  727. {data.itemList.map((m: any, mIndex: number) => {
  728. const isRender =
  729. m.isRender || Math.abs(popupData.activeIndex - mIndex) < 2;
  730. const isEmtry = Math.abs(popupData.activeIndex - mIndex) > 4;
  731. if (isRender) {
  732. m.isRender = true;
  733. }
  734. return isRender ? (
  735. <div
  736. key={'index' + mIndex}
  737. class={[
  738. styles.itemDiv,
  739. popupData.activeIndex === mIndex && styles.itemActive,
  740. activeData.isAnimation && styles.acitveAnimation,
  741. Math.abs(popupData.activeIndex - mIndex) < 2
  742. ? styles.show
  743. : styles.hide
  744. ]}
  745. style={
  746. mIndex < popupData.activeIndex
  747. ? effects[effectIndex.value].prev
  748. : mIndex > popupData.activeIndex
  749. ? effects[effectIndex.value].next
  750. : {}
  751. }
  752. onClick={(e: Event) => {
  753. if (Date.now() - activeData.nowTime < 300) {
  754. handleDbClick(m);
  755. return;
  756. }
  757. activeData.nowTime = Date.now();
  758. }}>
  759. {m.type === 'IMG' && <img src={m.content} />}
  760. {m.type === 'VIDEO' && <img src={m.coverImg} onLoad={() => {
  761. m.isprepare = true;
  762. }} />}
  763. {/* {m.type === 'VIDEO' && (
  764. <VideoItem
  765. ref={(v: any) => (data.videoRefs[mIndex] = v)}
  766. item={m}
  767. show={popupData.activeIndex === mIndex}
  768. pageVisibility={pageVisibility.value}
  769. showModel={activeData.model}
  770. isEmtry={isEmtry}
  771. onLoadedmetadata={() => {
  772. m.isprepare = true;
  773. m.error = false;
  774. }}
  775. onEnded={() => {
  776. const _index = popupData.activeIndex + 1;
  777. if (_index < data.itemList.length) {
  778. handleSwipeChange(_index);
  779. }
  780. }}
  781. onReset={() => {
  782. m.error = false;
  783. }}
  784. onError={() => {
  785. m.isprepare = true;
  786. m.error = true;
  787. }}
  788. />
  789. )} */}
  790. {m.type === 'SONG' && (
  791. <AudioItem
  792. item={m}
  793. show={popupData.activeIndex === mIndex}
  794. pageVisibility={pageVisibility.value}
  795. showModel={activeData.model}
  796. isEmtry={isEmtry}
  797. onEnded={() => {
  798. const _index = popupData.activeIndex + 1;
  799. if (_index < data.itemList.length) {
  800. handleSwipeChange(_index);
  801. }
  802. }}
  803. onClose={() => {
  804. clearTimeout(activeData.timer);
  805. activeData.timer = setTimeout(() => {
  806. activeData.model = false;
  807. }, 4000);
  808. }}
  809. />
  810. )}
  811. {m.type === 'MUSIC' && (
  812. <MusicScore
  813. pageVisibility={pageVisibility.value}
  814. show={popupData.activeIndex === mIndex}
  815. activeModel={activeData.model}
  816. data-vid={m.id}
  817. music={m}
  818. />
  819. )}
  820. {m.type === 'VIDEO' && (
  821. <Transition name="van-fade">
  822. {/* {!m.isprepare && (
  823. <div class={styles.loadWrap}>
  824. <Vue3Lottie
  825. style={{ width: '100%', height: '100%' }}
  826. animationData={playLoadData}></Vue3Lottie>
  827. </div>
  828. )} */}
  829. {data.videoState !== 'play' && (
  830. <div class={styles.loadWrap}>
  831. <Vue3Lottie
  832. style={{ width: '100%', height: '100%' }}
  833. animationData={playLoadData}></Vue3Lottie>
  834. </div>
  835. )}
  836. </Transition>
  837. )}
  838. </div>
  839. ) : (
  840. <div
  841. key={'index' + mIndex}
  842. class={[
  843. styles.itemDiv,
  844. popupData.activeIndex === mIndex && styles.itemActive,
  845. activeData.isAnimation && styles.acitveAnimation,
  846. Math.abs(popupData.activeIndex - mIndex) < 2
  847. ? styles.show
  848. : styles.hide
  849. ]}
  850. style={
  851. mIndex < popupData.activeIndex
  852. ? effects[effectIndex.value].prev
  853. : mIndex > popupData.activeIndex
  854. ? effects[effectIndex.value].next
  855. : {}
  856. }></div>
  857. );
  858. })}
  859. </div>
  860. )}
  861. <Transition name="right">
  862. {activeData.model && (
  863. <div
  864. class={styles.rightFixedBtns}
  865. onClick={(e: Event) => {
  866. e.stopPropagation();
  867. clearTimeout(activeData.timer);
  868. }}>
  869. <div
  870. class={[styles.fullBtn, styles.point]}
  871. onClick={() => (popupData.chapterOpen = true)}>
  872. <img src={iconChange} />
  873. <span>切换</span>
  874. </div>
  875. <div
  876. class={[styles.fullBtn, styles.point]}
  877. onClick={() => (popupData.open = true)}>
  878. <img src={iconMenu} />
  879. <span>课件</span>
  880. </div>
  881. <div
  882. class={[
  883. styles.fullBtn,
  884. // popupData.activeIndex == 0 && styles.btnsDisabled
  885. !isUpArrow.value && styles.btnsDisabled
  886. ]}
  887. onClick={() => handlePreAndNext('up')}>
  888. <img src={iconUp} />
  889. <span style={{ textAlign: 'center' }}>上一个</span>
  890. </div>
  891. <div
  892. class={[
  893. styles.fullBtn,
  894. !isDownArrow.value && styles.btnsDisabled
  895. ]}
  896. onClick={() => handlePreAndNext('down')}>
  897. <span style={{ textAlign: 'center' }}>下一个</span>
  898. <img src={iconDown} />
  899. </div>
  900. </div>
  901. )}
  902. </Transition>
  903. </div>
  904. <div
  905. style={{ transform: activeData.model ? '' : 'translateY(-100%)' }}
  906. class={styles.headerContainer}
  907. ref={headeRef}>
  908. <div class={styles.backBtn} onClick={() => goback()}>
  909. <Icon name={iconBack} />
  910. 返回
  911. </div>
  912. <div class={styles.menu}>{popupData.itemName}</div>
  913. </div>
  914. {/* 课件列表 */}
  915. <Popup
  916. class={styles.popup}
  917. style={{ background: 'rgba(0,0,0, 0.75)' }}
  918. overlayClass={styles.overlayClass}
  919. position="right"
  920. round
  921. v-model:show={popupData.open}
  922. onClose={handleClosePopup}>
  923. <Points
  924. data={data.knowledgePointList}
  925. itemActive={popupData.itemActive}
  926. itemName={popupData.itemPointName}
  927. onHandleSelect={(res: any) => {
  928. popupData.open = false;
  929. toggleMaterial(res.itemActive);
  930. }}
  931. />
  932. </Popup>
  933. {/* 知识点列表 */}
  934. <Popup
  935. class={styles.popup}
  936. style={{ background: 'rgba(0,0,0, 0.75)' }}
  937. overlayClass={styles.overlayClass}
  938. position="right"
  939. round
  940. v-model:show={popupData.chapterOpen}
  941. onClose={handleClosePopup}>
  942. <Chapter
  943. detail={data.courseDetails}
  944. itemActive={activeData.coursewareDetailKnowledgeId as any}
  945. active={activeData.lessonCoursewareDetailId as any}
  946. onHandleSelect={async (item: any) => {
  947. loadingClass.value = true;
  948. activeData.coursewareDetailKnowledgeId = item.itemActive;
  949. activeData.lessonCoursewareDetailId = item.tabActive;
  950. await getDetail();
  951. popupData.activeIndex = 0;
  952. popupData.itemActive = data.knowledgePointList[0].id;
  953. popupData.itemName = data.knowledgePointList[0].name;
  954. popupData.itemPointName = item.itemName;
  955. popupData.chapterOpen = false;
  956. loadingClass.value = false;
  957. }}
  958. />
  959. </Popup>
  960. </div>
  961. );
  962. }
  963. });