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. 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 handleTop() {
  145. progress2.value = 4
  146. console.log(progress2.value)
  147. }
  148. </script>
  149. <template>
  150. <Loading v-show="isLoading" />
  151. <cl-page v-show="!isLoading">
  152. <Back v-show="showProgress" />
  153. <view class="w-[64vw] h-[36vw] absolute top-1/2 z-[1] left-[7vw] translate50"
  154. :class="{ ' rounded-2xl p-[3px] bg-black mt-[25px] ': showProgress, 'video-container': !showProgress }">
  155. <video v-if="progress2 !== 3" id="video1" class="w-full h-full " :class="{ 'rounded-2xl': showProgress }"
  156. :src="data.videoSrc" :show-center-play-btn="false" :show-background-playback-button="false"
  157. :show-fullscreen-btn="false" :show-casting-button="false" autoplay @controlstoggle="handleControlsToggle"
  158. @ended="handleEnded">
  159. </video>
  160. <view v-else class="w-full h-full ">
  161. <img src="https://oss.xiaoxiongcode.com/static/home/2.png" alt="" class="w-full h-full object-cover" />
  162. <view class="absolute top-1/2 left-1/2 text-[20px] font-bold text-white text-center" @tap="handleTop">
  163. 假设
  164. </view>
  165. </view>
  166. <view class="video-fullscreen_title" v-show="showControls && !showProgress">
  167. <Back />
  168. <view class="text-[20px] font-bold text-white">
  169. {{ course?.mainTitle }}
  170. </view>
  171. <view class="control-progress">
  172. <view class="before"></view>
  173. <view v-for="(item, i) in menu2Items" :key="item.id"
  174. class="px-0 py-3 flex items-center justify-center gap-[5px] relative z-[1]"
  175. :class="{ '!bg-[#fff] rounded-full': progress2 == i + 1 }">
  176. <cl-image :src="item.icon" mode="heightFix" class="!h-[30px]"></cl-image>
  177. <text class="text-[14px] font-bold" :class="{ '!text-[#2BA0F3]': progress2 == i + 1 }">{{ item.name
  178. }}</text>
  179. </view>
  180. <view class="before"></view>
  181. </view>
  182. </view>
  183. </view>
  184. <view class="course-detail-page" :class="{ 'hidden': !showProgress }">
  185. <!-- 顶部标题栏 -->
  186. <view class="flex-[1] h-[100vh] relative">
  187. <view class="flex flex-row w-full pr-[3vw] pl-[10vw] items-center justify-between absolute top-[30px]">
  188. <text class="text-[5vh] font-bold">{{ course?.mainTitle }}</text>
  189. <text
  190. class="rounded-full p-[1vh] px-[2vh] border-2 border-[#fff] border-solid text-[#fff] text-[3vh] font-bold">课程收获</text>
  191. </view>
  192. </view>
  193. <!-- 右侧功能菜单 -->
  194. <view class="w-[25vw] h-[100vh] bg-[#5CBDFD] flex flex-col justify-center p-5">
  195. <view v-for="(item, i) in menuItems" :key="item.id" class="h-[20vh] flex flex-row items-center ">
  196. <view
  197. 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]"
  198. :class="{ '!bg-[#fff]': progress > i }">
  199. <cl-image :src="item.icon" mode="heightFix" class="!h-[7vh]"></cl-image>
  200. <text class="text-[2vh] font-bold">{{ item.name }}</text>
  201. </view>
  202. <view class="flex items-center h-[20vh] ml-[2vh] ">
  203. <view class="w-[1vh] bg-[#B4DBF7] flex-1" :class="{ '!bg-[#71C73D]': progress > i, '!opacity-0': i === 0 }">
  204. </view>
  205. <view class="w-[5vh] bg-[#fff] h-[5vh] rounded-full" :class="{ '!bg-[#71C73D]': progress > i }"></view>
  206. <view class="w-[1vh] bg-[#B4DBF7] flex-1"
  207. :class="{ '!bg-[#71C73D]': progress > i, '!opacity-0': i === menuItems.length - 1 }"></view>
  208. </view>
  209. </view>
  210. </view>
  211. </view>
  212. </cl-page>
  213. </template>
  214. <style lang="scss" scoped>
  215. .translate50 {
  216. transform: translateY(-50%);
  217. }
  218. .course-detail-page {
  219. @apply flex flex-row items-center;
  220. background-color: #3498DB;
  221. height: 100vh;
  222. color: black;
  223. transition: all 1s ease-in-out;
  224. }
  225. .video-container {
  226. width: 100vw;
  227. height: 100vh;
  228. top: 0;
  229. left: 0;
  230. transform: translate(0, 0);
  231. animation: spin 2s linear 1;
  232. transition: all 2s ease-in-out;
  233. }
  234. @keyframes spin {
  235. 0% {
  236. opacity: 50%;
  237. }
  238. 100% {
  239. opacity: 1;
  240. }
  241. }
  242. .hidden {
  243. opacity: 0;
  244. transition: all 3s ease-in-out;
  245. }
  246. .video-fullscreen_title {
  247. @apply absolute top-3 left-0 pl-[80px] w-[100vw] z-10 flex items-center justify-between flex-row;
  248. color: #fff;
  249. .control-progress {
  250. @apply flex flex-row gap-[1vh] relative justify-end;
  251. flex: 1;
  252. .before {
  253. @apply absolute top-1/2 right-0 w-[410px] h-[40px] bg-[#2BA0F3] rounded-l-full;
  254. transform: translateY(-30%);
  255. }
  256. }
  257. }
  258. video::-webkit-media-controls-fullscreen-button,
  259. video::-webkit-media-controls-enter-fullscreen-button,
  260. video::-webkit-media-controls-rotate-button,
  261. video::-webkit-media-controls-seek-back-button,
  262. video::-webkit-media-controls-seek-forward-button {
  263. display: none !important;
  264. }
  265. </style>