ParentMobileCourseDetail.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. <template>
  2. <!-- ======================================== -->
  3. <!-- 手机端:完整布局 -->
  4. <!-- ======================================== -->
  5. <div class="mobile-container" :class="{ 'fullscreen-active': isFullscreen }">
  6. <!-- 手机端:顶部导航栏 - 悬浮在视频上方 -->
  7. <div class="mobile-header" :class="{ 'header-hidden': headerHidden }">
  8. <button class="mobile-back-btn" @click="goBack">
  9. <el-icon><ArrowLeftBold /></el-icon>
  10. </button>
  11. <span class="mobile-header-title">{{ courseInfo.title }}</span>
  12. <div class="mobile-header-placeholder"></div>
  13. </div>
  14. <!-- 手机端:视频播放区域 -->
  15. <div class="mobile-video-area">
  16. <!-- 手机端视频播放器 -->
  17. <VideoPlayer
  18. v-if="currentCourse && currentCourse.courseContentType === 'video'"
  19. :key="'mobile-' + (currentCourse?.id || currentChapterId)"
  20. :contentType="currentCourse.courseContentType"
  21. :videoPath="currentCourse.courseVideoPath"
  22. :courseId="currentCourse.id || ''"
  23. :typeId="typeId"
  24. :courseConfigList="currentCourse.courseConfigList || []"
  25. :allIndices="chapterIds"
  26. :currentIndex="currentChapterId"
  27. :isFullscreen="isFullscreen"
  28. @switchVideo="handleSelect"
  29. @saveProgress="handleSaveProgress"
  30. @videoPlay="onVideoPlay"
  31. @videoPause="onVideoPause"
  32. @fullscreenChange="handleFullscreenChange"
  33. />
  34. </div>
  35. <!-- 手机端:搜索框 -->
  36. <div class="mobile-search-container">
  37. <el-input
  38. v-model="searchKeyword"
  39. placeholder="搜索课程内容..."
  40. class="mobile-search-input"
  41. clearable
  42. @keyup.enter="handleSearchSubmit"
  43. >
  44. <template #prefix>
  45. <el-icon><Search /></el-icon>
  46. </template>
  47. </el-input>
  48. </div>
  49. <!-- 手机端:章节列表 -->
  50. <div class="mobile-chapter-list">
  51. <div
  52. v-for="(chapter, index) in filteredTitles"
  53. :key="chapter.id"
  54. class="mobile-chapter-item"
  55. :class="{ active: currentChapterId === chapter.id }"
  56. @click="playChapter(chapter)"
  57. >
  58. <div class="mobile-chapter-info">
  59. <div class="mobile-chapter-title-row">
  60. <span class="mobile-chapter-number">{{ String(index + 1).padStart(2, '0') }}.</span>
  61. <span class="mobile-chapter-title">{{ videoPathMap[chapter.id]?.courseName || '' }}</span>
  62. </div>
  63. <div class="mobile-chapter-meta">
  64. <span class="mobile-chapter-type">视频时长</span>
  65. <span class="mobile-chapter-divider">|</span>
  66. <span class="mobile-chapter-duration">{{ formatDuration(videoPathMap[chapter.id]?.courseTime || 0) }}</span>
  67. </div>
  68. </div>
  69. <div class="mobile-chapter-play-icon">
  70. <el-icon
  71. v-if="currentChapterId === chapter.id && isPlaying"
  72. class="playing-icon"
  73. >
  74. <div class="audio-wave">
  75. <div class="wave-bar"></div>
  76. <div class="wave-bar"></div>
  77. <div class="wave-bar"></div>
  78. </div>
  79. </el-icon>
  80. <el-icon
  81. v-else
  82. class="play-icon"
  83. >
  84. <CaretRight />
  85. </el-icon>
  86. </div>
  87. </div>
  88. </div>
  89. </div>
  90. </template>
  91. <script setup>
  92. import { ref, computed, onMounted, onUnmounted } from 'vue'
  93. import { useRouter, useRoute } from 'vue-router'
  94. import {
  95. Search,
  96. ArrowLeftBold,
  97. CaretRight
  98. } from '@element-plus/icons-vue'
  99. import VideoPlayer from '@/components/videopage/VideoPlayer.vue'
  100. import classImages from '@/assets/icon/class.png'
  101. import { ClassType } from '@/api/class.js'
  102. import { Message } from '@/utils/message/Message.js'
  103. import { saveRecord } from '@/api/personalized/index.js'
  104. import { globalState } from '@/utils/globalState.js'
  105. const router = useRouter()
  106. const route = useRoute()
  107. const searchKeyword = ref('')
  108. const currentChapterId = ref('')
  109. const isPlaying = ref(false)
  110. // 强制设为移动端,不再检测设备类型
  111. const isMobile = ref(true)
  112. const headerHidden = ref(false)
  113. const courseInfo = ref({
  114. title: '',
  115. subtitle: '',
  116. coverImage: '',
  117. progress: 0
  118. })
  119. // 跟踪是否处于全屏状态
  120. const isFullscreen = ref(false)
  121. const chapters = ref([])
  122. const videoPathMap = ref({})
  123. const gradeId = ref('')
  124. const typeId = ref('')
  125. const currentCourse = ref({})
  126. const chapterIds = computed(() => {
  127. return chapters.value.map(c => c.id)
  128. })
  129. const filteredTitles = computed(() => {
  130. if (!searchKeyword.value) {
  131. return chapters.value
  132. }
  133. return chapters.value.filter(chapter =>
  134. chapter.title.toLowerCase().includes(searchKeyword.value.toLowerCase())
  135. )
  136. })
  137. const querySearch = (queryString, cb) => {
  138. const results = queryString
  139. ? chapters.value.filter(item => item.title.toLowerCase().includes(queryString.toLowerCase()))
  140. : chapters.value
  141. cb(results)
  142. }
  143. const handleSaveProgress = async (type, progress) => {
  144. if (!progress) return
  145. const saveProgressData = {
  146. brpNjId: gradeId.value,
  147. brpType: type,
  148. brpProgress: progress,
  149. brpCtId: typeId.value,
  150. brpCourseId: currentCourse.value.id
  151. }
  152. try {
  153. await saveRecord(saveProgressData)
  154. } catch (error) {
  155. console.error('保存视频进度失败:', error)
  156. }
  157. }
  158. const goBack = () => {
  159. router.go(-1)
  160. }
  161. const handleSelect = (index) => {
  162. if (videoPathMap.value[index]) {
  163. currentCourse.value = videoPathMap.value[index]
  164. currentChapterId.value = index
  165. } else {
  166. Message().notifyWarning('视频不存在!', true)
  167. }
  168. }
  169. const handleSearchSelect = (item) => {
  170. handleSelect(item.id)
  171. searchKeyword.value = ''
  172. }
  173. const handleSearchSubmit = () => {
  174. if (searchKeyword.value.trim()) {
  175. // 可以在这里实现具体的搜索逻辑
  176. console.log('搜索关键词:', searchKeyword.value)
  177. // 例如:可以触发课程内容搜索、跳转到搜索结果页等
  178. Message().success(`搜索: ${searchKeyword.value}`, true)
  179. }
  180. }
  181. const playPreviousVideo = () => {
  182. const currentIndex = chapterIds.value.indexOf(currentChapterId.value)
  183. if (currentIndex > 0) {
  184. handleSelect(chapterIds.value[currentIndex - 1])
  185. }
  186. }
  187. const playNextVideo = () => {
  188. const currentIndex = chapterIds.value.indexOf(currentChapterId.value)
  189. if (currentIndex !== -1 && currentIndex < chapterIds.value.length - 1) {
  190. handleSelect(chapterIds.value[currentIndex + 1])
  191. }
  192. }
  193. const playChapter = (chapter) => {
  194. handleSelect(chapter.id)
  195. isPlaying.value = true
  196. }
  197. const togglePlay = () => {
  198. isPlaying.value = !isPlaying.value
  199. }
  200. const onVideoPlay = () => {
  201. isPlaying.value = true
  202. // 视频播放时隐藏头部导航栏
  203. headerHidden.value = true
  204. }
  205. const onVideoPause = () => {
  206. isPlaying.value = false
  207. // 视频暂停时显示头部导航栏
  208. headerHidden.value = false
  209. }
  210. const handlePageClick = () => {}
  211. const formatDuration = (seconds) => {
  212. const mins = Math.floor(seconds / 60)
  213. const secs = Math.floor(seconds % 60)
  214. return `${mins.toString().padStart(2, '0')}分${secs.toString().padStart(2, '0')}秒`
  215. }
  216. const handleFullscreenChange = (isFullscreenNow) => {
  217. isFullscreen.value = isFullscreenNow
  218. }
  219. // 监听设备方向变化
  220. const handleOrientationChange = () => {
  221. // 在全屏状态下,设备方向改变时强制重新调整视频容器尺寸
  222. if (isFullscreen.value) {
  223. // 使用setTimeout确保DOM更新完成后再执行
  224. setTimeout(() => {
  225. // 触发一次强制重绘
  226. const videoArea = document.querySelector('.mobile-video-area');
  227. if (videoArea) {
  228. videoArea.style.display = 'none';
  229. void videoArea.offsetWidth; // 强制重排
  230. videoArea.style.display = '';
  231. }
  232. }, 100);
  233. }
  234. };
  235. onMounted(async () => {
  236. // 监听设备方向变化事件
  237. window.addEventListener('orientationchange', handleOrientationChange);
  238. const typeIdParam = history.state?.typeId || router.currentRoute.value.query.typeId
  239. if (typeIdParam) {
  240. typeId.value = typeIdParam
  241. try {
  242. const res = await ClassType(typeIdParam)
  243. const processedData = res.data.map(course => {
  244. if (course.courseConfigList && Array.isArray(course.courseConfigList)) {
  245. const validConfigList = course.courseConfigList.filter(config =>
  246. config.ccTime !== undefined && config.ccTime !== null && config.ccTime > 0
  247. )
  248. return {
  249. ...course,
  250. courseConfigList: validConfigList
  251. }
  252. }
  253. return course
  254. })
  255. const videoCourses = processedData.filter(course => course.courseContentType === 'video')
  256. videoCourses.forEach((course, index) => {
  257. const menuIndex = String(index + 1).padStart(2, '0')
  258. course.key = menuIndex
  259. videoPathMap.value[menuIndex] = course
  260. const menuItem = {
  261. id: menuIndex,
  262. key: menuIndex,
  263. title: course.courseName
  264. }
  265. chapters.value.push(menuItem)
  266. if (index === 0) {
  267. currentCourse.value = course
  268. currentChapterId.value = menuIndex
  269. }
  270. })
  271. } catch (error) {
  272. console.error('获取课程数据失败:', error)
  273. }
  274. }
  275. const title = history.state?.typeName || router.currentRoute.value.query.typeName
  276. if (title) {
  277. courseInfo.value.title = String(title)
  278. }
  279. gradeId.value = globalState.initGradeId()
  280. })
  281. onUnmounted(() => {
  282. // 移除设备方向变化事件监听器
  283. window.removeEventListener('orientationchange', handleOrientationChange);
  284. });
  285. </script>
  286. <style scoped lang="scss">
  287. @use 'sass:math';
  288. @function rpx($px) {
  289. @return math.div($px, 750) * 100vw;
  290. }
  291. /* ======================================== */
  292. /* 手机端样式 */
  293. /* ======================================== */
  294. .mobile-container {
  295. display: flex;
  296. flex-direction: column;
  297. width: 100% !important;
  298. min-width: 100% !important;
  299. max-width: 100% !important;
  300. min-height: 100vh;
  301. background: #f5f5f5;
  302. padding: 0 !important;
  303. margin: 0 !important;
  304. box-sizing: border-box !important;
  305. position: fixed !important;
  306. top: 0 !important;
  307. left: 0 !important;
  308. right: 0 !important;
  309. bottom: 0 !important;
  310. overflow-y: auto !important;
  311. }
  312. .mobile-header {
  313. width: 100% !important;
  314. height: 44px;
  315. background: linear-gradient(135deg, #44449c80, #7F70C880); /* 半透明背景 */
  316. display: flex;
  317. align-items: center;
  318. justify-content: space-between;
  319. padding: 0 12px;
  320. box-sizing: border-box;
  321. position: fixed; /* 固定定位,悬浮在顶部 */
  322. top: 0;
  323. left: 0;
  324. right: 0;
  325. z-index: 1000; /* 提高层级确保在最顶层 */
  326. transition: transform 0.3s ease; /* 添加过渡动画 */
  327. }
  328. .mobile-header.header-hidden {
  329. transform: translateY(-100%); /* 向上隐藏 */
  330. }
  331. .mobile-back-btn {
  332. width: 32px;
  333. height: 32px;
  334. display: flex;
  335. align-items: center;
  336. justify-content: center;
  337. background: rgba(255, 255, 255, 0.2);
  338. border-radius: 50%;
  339. border: none;
  340. color: white;
  341. font-size: 16px;
  342. cursor: pointer;
  343. flex-shrink: 0;
  344. }
  345. .mobile-header-title {
  346. flex: 1;
  347. text-align: center;
  348. color: white;
  349. font-size: 16px;
  350. font-weight: 500;
  351. padding: 0 40px;
  352. overflow: hidden;
  353. text-overflow: ellipsis;
  354. white-space: nowrap;
  355. }
  356. .mobile-header-placeholder {
  357. width: 32px;
  358. flex-shrink: 0;
  359. }
  360. .mobile-video-area {
  361. width: 100% !important;
  362. min-width: 100% !important;
  363. max-width: 100% !important;
  364. height: auto !important;
  365. background: #000;
  366. margin-top: 44px; /* 为固定在顶部的导航栏预留空间 */
  367. position: relative;
  368. padding: 0 !important;
  369. margin: 0 !important;
  370. box-sizing: border-box !important;
  371. flex-shrink: 0;
  372. border-radius: 0 !important;
  373. overflow: hidden;
  374. }
  375. /* 修复全屏模式下的视频显示问题 */
  376. .mobile-container.fullscreen-active .mobile-video-area {
  377. position: fixed !important;
  378. top: 0 !important;
  379. left: 0 !important;
  380. right: 0 !important;
  381. bottom: 0 !important;
  382. z-index: 9999 !important;
  383. margin-top: 0 !important;
  384. /* 使用视口单位确保在设备方向改变时适应屏幕 */
  385. width: 100vw !important;
  386. height: 100vh !important;
  387. min-height: 100vh !important;
  388. max-height: 100vh !important;
  389. /* 确保视频容器占据全部可用空间 */
  390. display: flex !important;
  391. align-items: center !important;
  392. justify-content: center !important;
  393. }
  394. .mobile-container.fullscreen-active .mobile-header {
  395. z-index: 10000;
  396. }
  397. .mobile-container.fullscreen-active .mobile-search-container,
  398. .mobile-container.fullscreen-active .mobile-chapter-list {
  399. display: none;
  400. }
  401. /* 手机端搜索框容器 */
  402. .mobile-search-container {
  403. width: 100%;
  404. padding: rpx(16);
  405. background: #f5f5f5;
  406. box-sizing: border-box;
  407. display: flex;
  408. align-items: center;
  409. }
  410. .mobile-search-input {
  411. width: 100%;
  412. height: rpx(64);
  413. }
  414. .mobile-search-input :deep(.el-input__wrapper) {
  415. border-radius: rpx(32);
  416. width: 100%;
  417. height: 100%;
  418. background: #fff;
  419. border: none;
  420. box-shadow: none;
  421. }
  422. .mobile-search-input :deep(.el-input__inner) {
  423. height: 100%;
  424. line-height: rpx(64);
  425. font-size: rpx(28);
  426. color: #999;
  427. }
  428. /* 手机端视频播放器去圆角 */
  429. .mobile-video-area :deep(.d-player-wrap),
  430. .mobile-video-area :deep(.full-box-video),
  431. .mobile-video-area :deep(.ppt-container) {
  432. border-radius: 0 !important;
  433. width: 100% !important;
  434. height: 100% !important;
  435. max-width: 100% !important;
  436. max-height: 100% !important;
  437. }
  438. .mobile-video-area :deep(*) {
  439. width: 100% !important;
  440. height: 100% !important;
  441. max-width: 100% !important;
  442. max-height: 100% !important;
  443. object-fit: contain !important; /* 使用contain确保视频完全可见 */
  444. border-radius: 0 !important;
  445. }
  446. /* 特别处理全屏模式下的视频播放器 */
  447. .mobile-container.fullscreen-active .mobile-video-area :deep(.d-player-wrap),
  448. .mobile-container.fullscreen-active .mobile-video-area :deep(.full-box-video),
  449. .mobile-container.fullscreen-active .mobile-video-area :deep(.ppt-container) {
  450. width: 100% !important;
  451. height: 100% !important;
  452. max-width: 100% !important;
  453. max-height: 100% !important;
  454. position: relative !important;
  455. }
  456. .mobile-container.fullscreen-active .mobile-video-area :deep(video) {
  457. object-fit: contain !important;
  458. width: 100% !important;
  459. height: 100% !important;
  460. max-width: 100% !important;
  461. max-height: 100% !important;
  462. }
  463. .mobile-chapter-list {
  464. flex: 1;
  465. padding: 0;
  466. background: #fff;
  467. margin-top: rpx(10); /* 与视频信息区域分开 */
  468. }
  469. .mobile-chapter-item {
  470. display: flex;
  471. justify-content: space-between;
  472. align-items: center;
  473. padding: 16px;
  474. border-bottom: 1px solid #f0f0f0;
  475. cursor: pointer;
  476. transition: background-color 0.2s ease;
  477. background: #fff;
  478. }
  479. .mobile-chapter-item:last-child {
  480. border-bottom: none;
  481. }
  482. .mobile-chapter-item.active {
  483. background: #fff;
  484. }
  485. .mobile-chapter-item.locked {
  486. opacity: 0.6;
  487. }
  488. .mobile-chapter-info {
  489. flex: 1;
  490. display: flex;
  491. flex-direction: column;
  492. gap: 6px;
  493. }
  494. .mobile-chapter-title-row {
  495. display: flex;
  496. align-items: flex-start;
  497. gap: 6px;
  498. }
  499. .mobile-chapter-number {
  500. font-size: 15px;
  501. font-weight: 600;
  502. color: #333;
  503. flex-shrink: 0;
  504. }
  505. .mobile-chapter-title {
  506. font-size: 15px;
  507. font-weight: 500;
  508. color: #333;
  509. line-height: 1.4;
  510. }
  511. .mobile-chapter-meta {
  512. font-size: 12px;
  513. color: #999;
  514. display: flex;
  515. align-items: center;
  516. gap: 8px;
  517. padding-left: 28px;
  518. }
  519. .mobile-chapter-type {
  520. color: #999;
  521. }
  522. .mobile-chapter-divider {
  523. color: #ddd;
  524. }
  525. .mobile-chapter-duration {
  526. color: #999;
  527. }
  528. .mobile-chapter-play-icon {
  529. flex-shrink: 0;
  530. margin-left: 12px;
  531. width: 24px;
  532. height: 24px;
  533. display: flex;
  534. align-items: center;
  535. justify-content: center;
  536. }
  537. .mobile-chapter-play-icon .el-icon {
  538. font-size: 20px;
  539. color: #409EFF;
  540. }
  541. .mobile-chapter-play-icon .playing-icon {
  542. display: flex;
  543. align-items: center;
  544. justify-content: center;
  545. }
  546. .audio-wave {
  547. display: flex;
  548. align-items: center;
  549. justify-content: center;
  550. gap: 2px;
  551. height: 20px;
  552. }
  553. .wave-bar {
  554. width: 2px;
  555. height: 8px;
  556. background-color: #409EFF;
  557. border-radius: 1px;
  558. animation: wave-animation 1.2s ease-in-out infinite;
  559. }
  560. .wave-bar:nth-child(1) {
  561. animation-delay: 0s;
  562. }
  563. .wave-bar:nth-child(2) {
  564. animation-delay: 0.2s;
  565. }
  566. .wave-bar:nth-child(3) {
  567. animation-delay: 0.4s;
  568. }
  569. @keyframes wave-animation {
  570. 0%, 100% {
  571. transform: scaleY(1);
  572. opacity: 0.7;
  573. }
  574. 50% {
  575. transform: scaleY(1.8);
  576. opacity: 1;
  577. }
  578. }
  579. .mobile-chapter-action {
  580. width: 40px;
  581. display: flex;
  582. align-items: center;
  583. justify-content: center;
  584. }
  585. .mobile-lock-icon {
  586. color: #ccc;
  587. font-size: 16px;
  588. }
  589. /* 处理设备方向变化时的全屏视频 */
  590. @media screen and (orientation: landscape) {
  591. .mobile-container.fullscreen-active .mobile-video-area {
  592. width: 100vw !important;
  593. height: 100vh !important;
  594. min-height: 100vh !important;
  595. max-height: 100vh !important;
  596. }
  597. }
  598. @media screen and (orientation: portrait) {
  599. .mobile-container.fullscreen-active .mobile-video-area {
  600. width: 100vw !important;
  601. height: 100vh !important;
  602. min-height: 100vh !important;
  603. max-height: 100vh !important;
  604. }
  605. }
  606. </style>