detail.uvue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. prevPage.status = 'wait'
  98. }
  99. isLoading.value = false
  100. })
  101. function handleControlsToggle(e) {
  102. console.log(e)
  103. showControls.value = e.detail.show
  104. }
  105. watchEffect(() => {
  106. if (progress.value === 1) {
  107. switch (progress2.value) {
  108. case 1:
  109. data.value.videoSrc = course.value?.detailItem?.observeVideoPath
  110. data.value.webviewSrc = course.value?.detailItem?.observeAnimationPath
  111. break
  112. case 2:
  113. data.value.videoSrc = course.value?.detailItem?.questionVideoPath
  114. break
  115. case 3:
  116. // data.value.webviewSrc = course.value?.detailItem?.assumeAnimationPath || data.value.webviewSrc
  117. // router.push({
  118. // path: "/pages/catalog/web-view",
  119. // query: {
  120. // src: data.value.webviewSrc,
  121. // progress: progress2.value,
  122. // }
  123. // });
  124. break
  125. case 4:
  126. // data.value.videoSrc = course.value?.detailItem?.testVideoPath || data.value.videoSrc
  127. data.value.webviewSrc = course.value?.detailItem?.testAnimationPath
  128. router.push({
  129. path: "/pages/catalog/web-view",
  130. query: {
  131. src: data.value.webviewSrc,
  132. progress: progress2.value,
  133. }
  134. });
  135. break
  136. case 5:
  137. data.value.videoSrc = course.value?.detailItem?.summaryVideoPath
  138. break
  139. case 6:
  140. data.value.videoSrc = course.value?.detailItem?.expandVideoPath
  141. break
  142. }
  143. }
  144. })
  145. function handleTop() {
  146. progress2.value = 4
  147. console.log(progress2.value)
  148. }
  149. </script>
  150. <template>
  151. <Loading v-show="isLoading" />
  152. <cl-page v-show="!isLoading">
  153. <Back v-show="showProgress" />
  154. <view class="w-[64vw] h-[36vw] absolute top-1/2 z-[1] left-[7vw] translate50"
  155. :class="{ ' rounded-2xl p-[3px] bg-black mt-[25px] ': showProgress, 'video-container': !showProgress }">
  156. <video v-if="progress2 !== 3" id="video1" class="w-full h-full " :class="{ 'rounded-2xl': showProgress }"
  157. :src="data.videoSrc" :show-center-play-btn="false" :show-background-playback-button="false"
  158. :show-fullscreen-btn="false" :show-casting-button="false" autoplay @controlstoggle="handleControlsToggle"
  159. @ended="handleEnded">
  160. </video>
  161. <view v-else class="w-full h-full ">
  162. <img src="https://oss.xiaoxiongcode.com/static/home/2.png" alt="" class="w-full h-full object-cover" />
  163. <view class="absolute top-1/2 left-1/2 text-[20px] font-bold text-white text-center" @tap="handleTop">
  164. 假设
  165. </view>
  166. </view>
  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>