detail.uvue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. isLoading.value = false
  60. }, 2000)
  61. })
  62. async function handleEnded() {
  63. // await updateSubjectProgress({
  64. // courseId: course.value?.id,
  65. // mainProgress: 1,
  66. // assistantProgress: 2,
  67. // status: 0
  68. // })
  69. // progress2.value = 2
  70. switch (progress2.value) {
  71. case 1:
  72. router.push({
  73. path: "/pages/catalog/web-view",
  74. query: {
  75. src: data.value.webviewSrc,
  76. progress: progress2.value,
  77. }
  78. });
  79. break
  80. case 2:
  81. case 4:
  82. case 5:
  83. case 6:
  84. progress2.value++
  85. break
  86. }
  87. }
  88. const status = ref('wait')
  89. onShow(() => {
  90. isLoading.value = true
  91. var pages = getCurrentPages();
  92. const prevPage = pages[pages.length - 1];
  93. console.log('prevPage', prevPage)
  94. status.value = prevPage?.status || 'wait'
  95. if (status.value === 'success') {
  96. progress2.value++
  97. }
  98. isLoading.value = false
  99. })
  100. function handleControlsToggle(e) {
  101. console.log(e)
  102. showControls.value = e.detail.show
  103. }
  104. watchEffect(() => {
  105. if (progress.value === 1) {
  106. switch (progress2.value) {
  107. case 1:
  108. data.value.videoSrc = course.value?.detailItem?.observeVideoPath
  109. data.value.webviewSrc = course.value?.detailItem?.observeAnimationPath
  110. break
  111. case 2:
  112. data.value.videoSrc = course.value?.detailItem?.questionVideoPath
  113. break
  114. case 3:
  115. // data.value.webviewSrc = course.value?.detailItem?.assumeAnimationPath || data.value.webviewSrc
  116. // router.push({
  117. // path: "/pages/catalog/web-view",
  118. // query: {
  119. // src: data.value.webviewSrc,
  120. // progress: progress2.value,
  121. // }
  122. // });
  123. break
  124. case 4:
  125. // data.value.videoSrc = course.value?.detailItem?.testVideoPath || data.value.videoSrc
  126. data.value.webviewSrc = course.value?.detailItem?.testAnimationPath
  127. router.push({
  128. path: "/pages/catalog/web-view",
  129. query: {
  130. src: data.value.webviewSrc,
  131. progress: progress2.value,
  132. }
  133. });
  134. break
  135. case 5:
  136. data.value.videoSrc = course.value?.detailItem?.summaryVideoPath
  137. break
  138. case 6:
  139. data.value.videoSrc = course.value?.detailItem?.expandVideoPath
  140. break
  141. }
  142. }
  143. })
  144. function handleMessage(e) {
  145. console.log(123, e)
  146. }
  147. </script>
  148. <template>
  149. <Loading v-show="isLoading" />
  150. <cl-page v-show="!isLoading">
  151. <Back v-show="showProgress" />
  152. <view class="w-[64vw] h-[36vw] absolute top-1/2 z-[1] left-[7vw] translate50"
  153. :class="{ ' rounded-2xl p-[3px] bg-black mt-[25px] ': showProgress, 'video-container': !showProgress }">
  154. <video v-if="progress2 !== 3" id="video1" class="w-full h-full " :class="{ 'rounded-2xl': showProgress }"
  155. :src="data.videoSrc" :show-center-play-btn="false" :show-background-playback-button="false"
  156. :show-fullscreen-btn="false" :show-casting-button="false" autoplay @controlstoggle="handleControlsToggle"
  157. @ended="handleEnded">
  158. </video>
  159. <view v-else class="w-full h-full ">
  160. <img src="https://oss.xiaoxiongcode.com/static/home/2.png" alt="" class="w-full h-full object-cover" />
  161. <view class="">
  162. </view>
  163. </view>
  164. <view class="video-fullscreen_title" v-show="showControls && !showProgress">
  165. <Back />
  166. <view class="text-[20px] font-bold text-white">
  167. {{ course?.mainTitle }}
  168. </view>
  169. <view class="control-progress">
  170. <view class="before"></view>
  171. <view v-for="(item, i) in menu2Items" :key="item.id"
  172. class="px-0 py-3 flex items-center justify-center gap-[5px] relative z-[1]"
  173. :class="{ '!bg-[#fff] rounded-full': progress2 == i + 1 }">
  174. <cl-image :src="item.icon" mode="heightFix" class="!h-[30px]"></cl-image>
  175. <text class="text-[14px] font-bold" :class="{ '!text-[#2BA0F3]': progress2 == i + 1 }">{{ item.name
  176. }}</text>
  177. </view>
  178. <view class="before"></view>
  179. </view>
  180. </view>
  181. </view>
  182. <view class="course-detail-page" :class="{ 'hidden': !showProgress }">
  183. <!-- 顶部标题栏 -->
  184. <view class="flex-[1] h-[100vh] relative">
  185. <view class="flex flex-row w-full pr-[3vw] pl-[10vw] items-center justify-between absolute top-[30px]">
  186. <text class="text-[5vh] font-bold">{{ course?.mainTitle }}</text>
  187. <text
  188. class="rounded-full p-[1vh] px-[2vh] border-2 border-[#fff] border-solid text-[#fff] text-[3vh] font-bold">课程收获</text>
  189. </view>
  190. </view>
  191. <!-- 右侧功能菜单 -->
  192. <view class="w-[25vw] h-[100vh] bg-[#5CBDFD] flex flex-col justify-center p-5">
  193. <view v-for="(item, i) in menuItems" :key="item.id" class="h-[20vh] flex flex-row items-center ">
  194. <view
  195. 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]"
  196. :class="{ '!bg-[#fff]': progress > i }">
  197. <cl-image :src="item.icon" mode="heightFix" class="!h-[7vh]"></cl-image>
  198. <text class="text-[2vh] font-bold">{{ item.name }}</text>
  199. </view>
  200. <view class="flex items-center h-[20vh] ml-[2vh] ">
  201. <view class="w-[1vh] bg-[#B4DBF7] flex-1" :class="{ '!bg-[#71C73D]': progress > i, '!opacity-0': i === 0 }">
  202. </view>
  203. <view class="w-[5vh] bg-[#fff] h-[5vh] rounded-full" :class="{ '!bg-[#71C73D]': progress > i }"></view>
  204. <view class="w-[1vh] bg-[#B4DBF7] flex-1"
  205. :class="{ '!bg-[#71C73D]': progress > i, '!opacity-0': i === menuItems.length - 1 }"></view>
  206. </view>
  207. </view>
  208. </view>
  209. </view>
  210. </cl-page>
  211. </template>
  212. <style lang="scss" scoped>
  213. .translate50 {
  214. transform: translateY(-50%);
  215. }
  216. .course-detail-page {
  217. @apply flex flex-row items-center;
  218. background-color: #3498DB;
  219. height: 100vh;
  220. color: black;
  221. transition: all 1s ease-in-out;
  222. }
  223. .video-container {
  224. width: 100vw;
  225. height: 100vh;
  226. top: 0;
  227. left: 0;
  228. transform: translate(0, 0);
  229. animation: spin 2s linear 1;
  230. transition: all 2s ease-in-out;
  231. }
  232. @keyframes spin {
  233. 0% {
  234. opacity: 50%;
  235. }
  236. 100% {
  237. opacity: 1;
  238. }
  239. }
  240. .hidden {
  241. opacity: 0;
  242. transition: all 3s ease-in-out;
  243. }
  244. .video-fullscreen_title {
  245. @apply absolute top-3 left-0 pl-[80px] w-[100vw] z-10 flex items-center justify-between flex-row;
  246. color: #fff;
  247. .control-progress {
  248. @apply flex flex-row gap-[1vh] relative justify-end;
  249. flex: 1;
  250. .before {
  251. @apply absolute top-1/2 right-0 w-[410px] h-[40px] bg-[#2BA0F3] rounded-l-full;
  252. transform: translateY(-30%);
  253. }
  254. }
  255. }
  256. video::-webkit-media-controls-fullscreen-button,
  257. video::-webkit-media-controls-enter-fullscreen-button,
  258. video::-webkit-media-controls-rotate-button,
  259. video::-webkit-media-controls-seek-back-button,
  260. video::-webkit-media-controls-seek-forward-button {
  261. display: none !important;
  262. }
  263. </style>