detail.uvue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <script setup lang='ts'>
  2. import Back from '@/components/back.uvue'
  3. import Loading from '@/components/loading.uvue'
  4. import { ref, onMounted, watchEffect } from 'vue'
  5. import { type SubjectCourseResult, fetchSubjectCourseApp, updateSubjectProgress } from '@/services/subject/course'
  6. import { router } from '@/.cool'
  7. const isLoading = ref(true)
  8. const showProgress = ref(true)
  9. const showControls = ref(true)
  10. const showVideo = ref(true)
  11. const data = ref({
  12. videoSrc: 'https://oss.xiaoxiongcode.com/course-1/animate/第1集_观察.mp4',
  13. webviewSrc: '',
  14. })
  15. const menuItems = [
  16. { id: 'watch', name: '看课', icon: 'https://oss.xiaoxiongcode.com/static/home/kanke.png' },
  17. { id: 'practice', name: '练习', icon: 'https://oss.xiaoxiongcode.com/static/home/lianxi.png' },
  18. { id: 'experiment', name: '虚拟实验', icon: 'https://oss.xiaoxiongcode.com/static/home/shiyan.png' },
  19. { id: 'diary', name: '科学日记', icon: 'https://oss.xiaoxiongcode.com/static/home/riji.png' }
  20. ]
  21. const menu2Items = [
  22. { id: '1', name: '观察', icon: 'https://oss.xiaoxiongcode.com/static/home/kanke.png' },
  23. { id: '2', name: '提问', icon: 'https://oss.xiaoxiongcode.com/static/home/lianxi.png' },
  24. { id: '3', name: '假设', icon: 'https://oss.xiaoxiongcode.com/static/home/shiyan.png' },
  25. { id: '4', name: '实验', icon: 'https://oss.xiaoxiongcode.com/static/home/riji.png' },
  26. { id: '5', name: '总结', icon: 'https://oss.xiaoxiongcode.com/static/home/riji.png' },
  27. { id: '6', name: '拓展', icon: 'https://oss.xiaoxiongcode.com/static/home/riji.png' },
  28. ]
  29. //当前进度
  30. const progress = ref(1)
  31. const progress2 = ref(1)
  32. const course = ref<SubjectCourseResult>()
  33. //通过路由参数获取课程id
  34. async function fetchCatalog() {
  35. course.value = await fetchSubjectCourseApp({ id: router.query().id })
  36. if (!course.value?.courseUserProgress) {
  37. await updateSubjectProgress({
  38. courseId: course.value?.id,
  39. mainProgress: 1,
  40. assistantProgress: 1,
  41. status: 0
  42. })
  43. progress.value = 1
  44. progress2.value = 1
  45. data.value.videoSrc = course.value?.detailItem?.observeVideoPath || ''
  46. data.value.webviewSrc = course.value?.detailItem?.observeAnimationPath || ''
  47. } else {
  48. progress.value = 1
  49. progress2.value = 1
  50. // progress.value = course.value?.courseUserProgress.mainProgress
  51. // progress2.value = course.value?.courseUserProgress.assistantProgress
  52. }
  53. }
  54. onMounted(async () => {
  55. await fetchCatalog()
  56. isLoading.value = false
  57. setTimeout(() => {
  58. showProgress.value = false
  59. }, 2000)
  60. })
  61. async function handleEnded() {
  62. // await updateSubjectProgress({
  63. // courseId: course.value?.id,
  64. // mainProgress: 1,
  65. // assistantProgress: 2,
  66. // status: 0
  67. // })
  68. // progress2.value = 2
  69. switch (progress2.value) {
  70. case 1:
  71. showVideo.value = false
  72. break
  73. }
  74. }
  75. function handleControlsToggle(e) {
  76. console.log(e)
  77. showControls.value = e.detail.show
  78. }
  79. watchEffect(() => {
  80. if (progress.value === 1) {
  81. switch (progress2.value) {
  82. case 1:
  83. showVideo.value = true
  84. data.value.videoSrc = course.value?.detailItem?.observeVideoPath || ''
  85. data.value.webviewSrc = course.value?.detailItem?.observeAnimationPath || ''
  86. break
  87. case 2:
  88. showVideo.value = true
  89. data.value.videoSrc = course.value?.detailItem?.questionVideoPath || ''
  90. break
  91. case 3:
  92. showVideo.value = false
  93. data.value.webviewSrc = course.value?.detailItem?.assumeAnimationPath || ''
  94. break
  95. case 4:
  96. showVideo.value = true
  97. data.value.videoSrc = course.value?.detailItem?.testVideoPath || ''
  98. data.value.webviewSrc = course.value?.detailItem?.testAnimationPath || ''
  99. break
  100. case 5:
  101. data.value.videoSrc = course.value?.detailItem?.summaryVideoPath || ''
  102. break
  103. case 6:
  104. data.value.videoSrc = course.value?.detailItem?.expandVideoPath || ''
  105. break
  106. }
  107. }
  108. console.log(data.value.videoSrc)
  109. })
  110. function handleMessage(e) {
  111. console.log(e)
  112. }
  113. </script>
  114. <template>
  115. <Loading v-show="isLoading" />
  116. <cl-page v-show="!isLoading">
  117. <Back v-show="showProgress" />
  118. <view v-if="showVideo" class="w-[64vw] h-[36vw] absolute top-1/2 z-[1] left-[7vw] translate50"
  119. :class="{ ' rounded-2xl p-[3px] bg-black mt-[25px] ': showProgress, 'video-container': !showProgress }">
  120. <video id="video1" class="w-full h-full " :class="{ 'rounded-2xl': showProgress }" :src="data.videoSrc"
  121. :show-center-play-btn="false" :show-background-playback-button="false" :show-fullscreen-btn="false"
  122. :show-casting-button="false" autoplay @controlstoggle="handleControlsToggle" @ended="handleEnded">
  123. </video>
  124. <view class="video-fullscreen_title" v-show="showControls && !showProgress">
  125. <Back />
  126. <view class="text-[20px] font-bold text-white">
  127. {{ course?.mainTitle }}
  128. </view>
  129. <view class="control-progress">
  130. <view class="before"></view>
  131. <view v-for="(item, i) in menu2Items" :key="item.id"
  132. class="px-0 py-3 flex items-center justify-center gap-[5px] relative z-[1]"
  133. :class="{ '!bg-[#fff] rounded-full': progress2 == i + 1 }">
  134. <cl-image :src="item.icon" mode="heightFix" class="!h-[30px]"></cl-image>
  135. <text class="text-[14px] font-bold" :class="{ '!text-[#2BA0F3]': progress2 == i + 1 }">{{ item.name
  136. }}</text>
  137. </view>
  138. <view class="before"></view>
  139. </view>
  140. </view>
  141. </view>
  142. <view v-if="!showVideo" class="w-full h-full absolute top-0 left-0 z-[1]">
  143. <view class="video-fullscreen_title">
  144. <Back v-show="!showProgress" />
  145. <view class="control-progress">
  146. <view class="before"></view>
  147. <view v-for="(item, i) in menu2Items" :key="item.id"
  148. class="px-0 py-3 flex items-center justify-center gap-[5px] relative z-[1]"
  149. :class="{ '!bg-[#fff] rounded-full': progress2 == i + 1 }">
  150. <cl-image :src="item.icon" mode="heightFix" class="!h-[30px]"></cl-image>
  151. <text class="text-[14px] font-bold" :class="{ '!text-[#2BA0F3]': progress2 == i + 1 }">{{ item.name
  152. }}</text>
  153. </view>
  154. </view>
  155. </view>
  156. <web-view :src="data.webviewSrc" class="w-full h-full" @message="handleMessage"></web-view>
  157. </view>
  158. <view class="course-detail-page" :class="{ 'hidden': !showProgress }">
  159. <!-- 顶部标题栏 -->
  160. <view class="flex-[1] h-[100vh] relative">
  161. <view class="flex flex-row w-full pr-[3vw] pl-[10vw] items-center justify-between absolute top-[30px]">
  162. <text class="text-[5vh] font-bold">{{ course?.mainTitle }}</text>
  163. <text
  164. class="rounded-full p-[1vh] px-[2vh] border-2 border-[#fff] border-solid text-[#fff] text-[3vh] font-bold">课程收获</text>
  165. </view>
  166. </view>
  167. <!-- 右侧功能菜单 -->
  168. <view class="w-[25vw] h-[100vh] bg-[#5CBDFD] flex flex-col justify-center p-5">
  169. <view v-for="(item, i) in menuItems" :key="item.id" class="h-[20vh] flex flex-row items-center ">
  170. <view
  171. class="h-[15vh] w-[20vh] bg-[#999999] rounded-2xl border-[.5vh] border-[#254AD9] border-b-[1vh] border-solid flex items-center justify-center gap-[1vh]"
  172. :class="{ '!bg-[#fff]': progress > i }">
  173. <cl-image :src="item.icon" mode="heightFix" class="!h-[7vh]"></cl-image>
  174. <text class="text-[2vh] font-bold">{{ item.name }}</text>
  175. </view>
  176. <view class="flex items-center h-[20vh] ml-[2vh] ">
  177. <view class="w-[1vh] bg-[#B4DBF7] flex-1" :class="{ '!bg-[#71C73D]': progress > i, '!opacity-0': i === 0 }">
  178. </view>
  179. <view class="w-[5vh] bg-[#fff] h-[5vh] rounded-full" :class="{ '!bg-[#71C73D]': progress > i }"></view>
  180. <view class="w-[1vh] bg-[#B4DBF7] flex-1"
  181. :class="{ '!bg-[#71C73D]': progress > i, '!opacity-0': i === menuItems.length - 1 }"></view>
  182. </view>
  183. </view>
  184. </view>
  185. </view>
  186. </cl-page>
  187. </template>
  188. <style lang="scss" scoped>
  189. .translate50 {
  190. transform: translateY(-50%);
  191. }
  192. .course-detail-page {
  193. @apply flex flex-row items-center;
  194. background-color: #3498DB;
  195. height: 100vh;
  196. color: black;
  197. transition: all 1s ease-in-out;
  198. }
  199. .video-container {
  200. width: 100vw;
  201. height: 100vh;
  202. top: 0;
  203. left: 0;
  204. transform: translate(0, 0);
  205. animation: spin 2s linear 1;
  206. transition: all 2s ease-in-out;
  207. }
  208. @keyframes spin {
  209. 0% {
  210. opacity: 50%;
  211. }
  212. 100% {
  213. opacity: 1;
  214. }
  215. }
  216. .hidden {
  217. opacity: 0;
  218. transition: all 3s ease-in-out;
  219. }
  220. .video-fullscreen_title {
  221. @apply absolute top-3 left-0 pl-[80px] w-[100vw] z-10 flex items-center justify-between flex-row;
  222. color: #fff;
  223. .control-progress {
  224. @apply flex flex-row gap-[1vh] relative justify-end;
  225. flex: 1;
  226. .before {
  227. @apply absolute top-1/2 right-0 w-[410px] h-[40px] bg-[#2BA0F3] rounded-l-full;
  228. transform: translateY(-30%);
  229. }
  230. }
  231. }
  232. video::-webkit-media-controls-fullscreen-button,
  233. video::-webkit-media-controls-enter-fullscreen-button,
  234. video::-webkit-media-controls-rotate-button,
  235. video::-webkit-media-controls-seek-back-button,
  236. video::-webkit-media-controls-seek-forward-button {
  237. display: none !important;
  238. }
  239. </style>