detail.uvue 9.4 KB

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