detail.uvue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. <script setup lang='ts'>
  2. import Back from '@/components/back.uvue'
  3. import Loading from '@/components/loading.uvue'
  4. import { ref, onMounted, watch, nextTick, onUnmounted } from 'vue'
  5. import { type SubjectCourseResult, fetchSubjectCourseApp, updateSubjectProgress, queryNextSubjectCourse } from '@/services/subject/course'
  6. import { router, user } from '@/.cool'
  7. const isLoading = ref(true)
  8. const showControls = ref(true)
  9. const showVideo = ref(true)
  10. const data = ref({
  11. videoSrc: '',
  12. webviewSrc: '',
  13. })
  14. // const menuItems = [
  15. // { id: 'watch', name: '看课', icon: 'https://oss.xiaoxiongcode.com/static/home/kanke.png' },
  16. // // { id: 'practice', name: '练习', icon: 'https://oss.xiaoxiongcode.com/static/home/lianxi.png' },
  17. // { id: 'experiment', name: '虚拟实验', icon: 'https://oss.xiaoxiongcode.com/static/home/shiyan.png' },
  18. // // { id: 'diary', name: '科学日记', icon: 'https://oss.xiaoxiongcode.com/static/home/riji.png' }
  19. // ]
  20. const menu2Items = [
  21. { id: '1', name: '观察', icon: 'https://oss.xiaoxiongcode.com/static/home/观察.png' },
  22. { id: '2', name: '交互', icon: 'https://oss.xiaoxiongcode.com/static/home/总结.png' },
  23. { id: '3', name: '思考', icon: 'https://oss.xiaoxiongcode.com/static/home/假设.png' },
  24. { id: '4', name: '假设', icon: 'https://oss.xiaoxiongcode.com/static/home/卡通扁平化功能图标设计.png' },
  25. { id: '5', name: '总结', icon: 'https://oss.xiaoxiongcode.com/static/home/拓展.png' },
  26. { id: '6', name: '实验', icon: 'https://oss.xiaoxiongcode.com/static/home/shiyan.png' },
  27. ]
  28. //当前进度
  29. const progress = ref(1)
  30. const progress2 = ref(0)
  31. const progressStatus = ref(0)
  32. const recorderManager = ref<any>()
  33. const innerAudioContext = ref<any>()
  34. const voicePath = ref('')
  35. function initOnlibeRecord() {
  36. recorderManager.value = uni.getRecorderManager();
  37. innerAudioContext.value = uni.createInnerAudioContext();
  38. innerAudioContext.value.autoplay = true;
  39. recorderManager.value?.onStop(function (res) {
  40. if (res.duration < 1000) {
  41. uni.showToast({
  42. title: '录音时间过短',
  43. icon: 'none'
  44. })
  45. return
  46. }
  47. voicePath.value = res.tempFilePath;
  48. });
  49. }
  50. const course = ref<SubjectCourseResult>()
  51. const nextCourse = ref<SubjectCourseResult>()
  52. //通过路由参数获取课程id
  53. async function fetchCatalog() {
  54. course.value = await fetchSubjectCourseApp({ id: user.courseId.value })
  55. progressStatus.value = course.value?.courseUserProgress.status
  56. progress2.value = Number(router.query().progress)
  57. console.log(progress2.value);
  58. // if (!course.value?.courseUserProgress) {
  59. // await updateSubjectProgress({
  60. // courseId: course.value?.id,
  61. // mainProgress: 1,
  62. // assistantProgress: 1,
  63. // status: 0
  64. // })
  65. // progress.value = 1
  66. // progress2.value = 1
  67. // } else if (course.value?.courseUserProgress.status == 0) {
  68. // } else {
  69. // progressStatus.value = course.value?.courseUserProgress.status
  70. // progress2.value = 1
  71. // }
  72. }
  73. async function fetchNextCatalog(id: string) {
  74. nextCourse.value = await fetchSubjectCourseApp({ id })
  75. }
  76. onMounted(async () => {
  77. isLoading.value = true
  78. await fetchCatalog()
  79. initOnlibeRecord()
  80. setTimeout(() => {
  81. isLoading.value = false
  82. }, 1000)
  83. })
  84. async function handleEnded() {
  85. progress2.value++
  86. }
  87. const status = ref('wait')
  88. const visible = ref(false)
  89. onShow(async () => {
  90. isLoading.value = true
  91. var pages = getCurrentPages();
  92. const prevPage = pages[pages.length - 1];
  93. status.value = (prevPage as any)?.status || 'wait'
  94. console.log(status.value);
  95. if (status.value === 'success') {
  96. if (progress2.value === 6) {
  97. let nextCourseId = ''
  98. if (progressStatus.value === 0) {
  99. nextCourseId = await updateSubjectProgress({
  100. courseId: course.value?.id,
  101. mainProgress: 1,
  102. assistantProgress: 6,
  103. status: 1
  104. })
  105. console.log(nextCourseId);
  106. user.setCourseId(nextCourseId)
  107. await fetchNextCatalog(nextCourseId)
  108. uni.createVideoContext('video1').pause()
  109. console.log(222);
  110. isLoading.value = false
  111. visible.value = true
  112. } else {
  113. nextCourseId = await queryNextSubjectCourse({
  114. id: course.value?.id,
  115. })
  116. console.log(nextCourseId);
  117. user.setCourseId(nextCourseId)
  118. await fetchNextCatalog(nextCourseId)
  119. uni.createVideoContext('video1').pause()
  120. console.log(222);
  121. isLoading.value = false
  122. visible.value = true
  123. }
  124. return
  125. }
  126. progress2.value++;
  127. (prevPage as any).status = 'wait'
  128. }
  129. isLoading.value = false
  130. })
  131. function handleControlsToggle(e) {
  132. showControls.value = e.detail.show
  133. }
  134. watch(() => progress2.value, (newVal, oldVal) => {
  135. isLoading.value = true
  136. if (course.value?.id && progressStatus.value == 0) {
  137. updateSubjectProgress({
  138. courseId: course.value?.id,
  139. mainProgress: 1,
  140. assistantProgress: progress2.value,
  141. status: progressStatus.value
  142. })
  143. }
  144. console.log(progress2.value);
  145. switch (progress2.value) {
  146. case 1:
  147. setTimeout(() => {
  148. isLoading.value = false
  149. data.value.videoSrc = course.value?.detailItem?.observeVideoPath
  150. }, 2000)
  151. break
  152. case 2:
  153. data.value.webviewSrc = course.value?.detailItem?.summaryVideoPath
  154. router.push({
  155. path: "/pages/catalog/web-view",
  156. query: {
  157. src: data.value.webviewSrc,
  158. progress: progress2.value,
  159. }
  160. });
  161. data.value.videoSrc = course.value?.detailItem?.observeVideoPath
  162. break
  163. case 3:
  164. data.value.videoSrc = ''
  165. setTimeout(() => {
  166. isLoading.value = false
  167. data.value.videoSrc = course.value?.detailItem?.questionVideoPath
  168. }, 2000)
  169. break
  170. case 4:
  171. data.value.videoSrc = ''
  172. setTimeout(() => {
  173. isLoading.value = false
  174. playVoice(course.value?.detailItem?.assumeAnimationPath)
  175. }, 2000)
  176. break
  177. case 5:
  178. data.value.videoSrc = ''
  179. setTimeout(() => {
  180. isLoading.value = false
  181. data.value.videoSrc = course.value?.detailItem?.testVideoPath
  182. }, 2000)
  183. break
  184. case 6:
  185. console.log(course.value?.testItem?.animationPath);
  186. data.value.webviewSrc = course.value?.testItem?.animationPath
  187. router.push({
  188. path: "/pages/catalog/web-view",
  189. query: {
  190. src: data.value.webviewSrc,
  191. progress: progress2.value,
  192. }
  193. });
  194. data.value.videoSrc = course.value?.detailItem?.testVideoPath
  195. break
  196. }
  197. }, { immediate: true })
  198. const timers = ref(100)
  199. const timer = ref<any>()
  200. function handleTop() {
  201. progress2.value = 5
  202. }
  203. function startRecord() {
  204. console.log('开始录音');
  205. timer.value = setInterval(() => {
  206. timers.value--
  207. console.log(timers.value);
  208. if (timers.value <= 0) {
  209. endRecord()
  210. }
  211. }, 800)
  212. recorderManager.value.start();
  213. }
  214. function endRecord() {
  215. clearInterval(timer.value)
  216. timer.value = null
  217. timers.value = 100
  218. recorderManager.value.stop();
  219. }
  220. function playVoice(val) {
  221. innerAudioContext.value.src = val;
  222. innerAudioContext.value.play();
  223. }
  224. function handleLoadedMetadata() {
  225. // 视频加载完成后,设置全屏播放
  226. // uni.createVideoContext('video1').requestFullScreen()
  227. }
  228. function playNext() {
  229. visible.value = false
  230. course.value = nextCourse.value
  231. progressStatus.value = nextCourse.value?.courseUserProgress.status
  232. progress2.value = 1
  233. }
  234. onUnmounted(() => {
  235. clearInterval(timer.value)
  236. innerAudioContext.value.stop();
  237. })
  238. </script>
  239. <template>
  240. <Loading v-show="isLoading" />
  241. <cl-page v-show="!isLoading">
  242. <Back />
  243. <view class="video-container">
  244. <video v-if="progress2 !== 4" id="video1" class="w-full h-full " enable-play-gesture :src="data.videoSrc"
  245. enable-auto-rotation :show-center-play-btn="false" :show-background-playback-button="false"
  246. :show-fullscreen-btn="false" :show-casting-button="false" autoplay @controlstoggle="handleControlsToggle"
  247. @ended="handleEnded" @play="handleLoadedMetadata">
  248. </video>
  249. <view v-else class="w-full h-full ">
  250. <image mode="aspectFill" src="https://oss.xiaoxiongcode.com/static/home/assert_1.gif" alt=""
  251. class="w-full h-full object-cover" />
  252. <!-- 顶部提示文字 -->
  253. <view class="absolute text-[20px] top-[20vh] w-full flex flex-row items-center justify-center">
  254. <!-- <cl-icon name="notification-3-fill" color="#FCE762" :size="40"></cl-icon> -->
  255. <cl-image src="https://oss.xiaoxiongcode.com/static/home/guangbo.png" mode="heightFix" class="!h-[25px]"
  256. @tap="playVoice(course?.detailItem?.assumeAnimationPath)"></cl-image>
  257. <text class=" font-bold text-white">{{ course?.detailItem?.assumeAnimationJavascriptPath }}</text>
  258. </view>
  259. <!-- 居中麦克风按钮 -->
  260. <view class=" mic flex flex-col items-center w-[220px] h-[220px]">
  261. <!-- <view v-show="timer" class="mic">
  262. <cl-progress-circle :value="timers"></cl-progress-circle>
  263. </view> -->
  264. <view
  265. class="mic w-[120px] h-[120px] bg-[#3CB8FF] rounded-full flex items-center justify-center z-[2] border-[4px] border-white border-solid"
  266. @tap="startRecord" v-if="!timer">
  267. <cl-image src="https://oss.xiaoxiongcode.com/static/home/maikefeng.png" mode="heightFix"
  268. class="!h-[60px]"></cl-image>
  269. </view>
  270. <template v-else>
  271. <view class="mic w-[120px] h-[120px] bg-[#3CB8FF] rounded-full flex items-center justify-center z-[2]"
  272. @tap="endRecord">
  273. <view
  274. class="w-[50px] h-[50px] rounded-[5px] bg-white flex items-center justify-center text-[20px] font-bold text-[#3CB8FF]">
  275. <text class="text-[20px] font-bold text-[#3CB8FF]">{{ timers }}</text>
  276. </view>
  277. </view>
  278. </template>
  279. <!-- 指示手指 -->
  280. <view class="absolute bottom-[20px] right-[20px] animate-bounce pointer-events-none z-[2] !h-[60px] w-[100px]"
  281. v-if="!timer && !voicePath">
  282. <cl-image src="https://oss.xiaoxiongcode.com/static/home/shou.png" mode="heightFix" width="100%"
  283. class=""></cl-image>
  284. </view>
  285. </view>
  286. <!-- 下一步按钮 (录音完成后显示) -->
  287. <view v-show="voicePath" class="mic flex flex-row items-center justify-center gap-[200px]">
  288. <button
  289. class="bg-[#3CB8FF] text-white w-[80px] h-[80px] flex items-center justify-center rounded-full font-bold text-[25px] shadow-md active:opacity-80 border-[4px] border-white border-solid"
  290. @tap="playVoice(voicePath)">
  291. <cl-image src="https://oss.xiaoxiongcode.com/static/home/guangbo-bai.png" mode="heightFix"
  292. class="!h-[25px]"></cl-image>
  293. </button>
  294. <button
  295. class="bg-[#71C73D] text-white w-[80px] h-[80px] flex items-center justify-center rounded-full font-bold text-[25px] shadow-md active:opacity-80 border-[4px] border-white border-solid"
  296. @tap="handleTop">
  297. <cl-image src="https://oss.xiaoxiongcode.com/static/home/6241.png" mode="heightFix"
  298. class="!h-[25px]"></cl-image>
  299. </button>
  300. </view>
  301. </view>
  302. <view class="video-fullscreen_title" v-show="showControls">
  303. <Back />
  304. <view class="text-[20px] font-bold text-white">
  305. <text class="text-[20px] font-bold text-[#fff]">
  306. {{ course?.mainTitle }}
  307. </text>
  308. </view>
  309. <!-- <view class="control-progress">
  310. <view class="before"></view>
  311. <view v-for="(item, i) in menu2Items" :key="item.id"
  312. class="py-2 px-3 flex items-center flex-row justify-center ov gap-[5px] relative z-[1]"
  313. :class="{ '!bg-[#fff] rounded-l-full': progress2 == i + 1 }" @tap="progress2 = i + 1">
  314. <cl-image :src="item.icon" mode="heightFix" class="!h-[28px] !w-[50px]"></cl-image>
  315. <text class="text-[12px] font-bold" :class="{ '!text-[#2BA0F3]': progress2 == i + 1 }">{{ item.name
  316. }}</text>
  317. </view>
  318. </view> -->
  319. </view>
  320. </view>
  321. <view class="course-detail-page">
  322. <!-- 顶部标题栏 -->
  323. <view class="flex-[1] h-[100vh] relative">
  324. <!-- <view class="flex flex-row w-full pr-[3vw] pl-[10vw] items-center justify-between absolute top-[30px]">
  325. <text class="text-[5vh] font-bold">{{ course?.mainTitle }}</text>
  326. <text
  327. class="rounded-full p-[1vh] px-[2vh] border-2 border-[#fff] border-solid text-[#fff] text-[3vh] font-bold">课程收获</text>
  328. </view> -->
  329. </view>
  330. <!-- 右侧功能菜单 -->
  331. <!-- <view class="w-[25vw] h-[100vh] bg-[#5CBDFD] flex flex-col justify-center p-5">
  332. <view v-for="(item, i) in menuItems" :key="item.id" class="h-[20vh] flex flex-row items-center ">
  333. <view
  334. 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]"
  335. :class="{ '!bg-[#fff]': progress >= i }">
  336. <cl-image :src="item.icon" mode="heightFix" class="!h-[7vh]"></cl-image>
  337. <text class="text-[2vh] font-bold">{{ item.name }}</text>
  338. </view>
  339. <view class="flex items-center h-[20vh] ml-[2vh] ">
  340. <view class="w-[1vh] bg-[#B4DBF7] flex-1"
  341. :class="{ '!bg-[#71C73D]': progress >= i, '!opacity-0': i === 0 }">
  342. </view>
  343. <view class="w-[5vh] bg-[#fff] h-[5vh] rounded-full" :class="{ '!bg-[#71C73D]': progress >= i }"></view>
  344. <view class="w-[1vh] bg-[#B4DBF7] flex-1"
  345. :class="{ '!bg-[#71C73D]': progress >= i, '!opacity-0': i === menuItems.length - 1 }"></view>
  346. </view>
  347. </view>
  348. </view> -->
  349. </view>
  350. </cl-page>
  351. <cl-popup v-model="visible" :width="300" direction="center" :show-header="false" :maskClosable="false">
  352. <view class="p-2">
  353. <cl-image lazy-load :src="nextCourse?.ossIconPath" mode="heightFix"
  354. class="!w-full !h-[150px] mb-[10px] rounded-xl"></cl-image>
  355. <cl-row :gutter="12">
  356. <cl-col :span="12"> <cl-button size="small" type="info" @click="router.back()">返回</cl-button></cl-col>
  357. <cl-col :span="12"> <cl-button size="small" type="success" @click="playNext">播放下集</cl-button></cl-col>
  358. </cl-row>
  359. </view>
  360. </cl-popup>
  361. </template>
  362. <style lang="scss" scoped>
  363. .translate50 {
  364. transform: translateY(-50%);
  365. }
  366. .course-detail-page {
  367. @apply flex flex-row items-center;
  368. background-color: #3498DB;
  369. height: 100vh;
  370. color: black;
  371. transition: all 1s ease-in-out;
  372. }
  373. .video-container {
  374. width: 100vw;
  375. height: 100vh;
  376. top: 0;
  377. left: 0;
  378. transform: translate(0, 0);
  379. animation: spin 2s linear 1;
  380. transition: all 2s ease-in-out;
  381. }
  382. @keyframes spin {
  383. 0% {
  384. opacity: 50%;
  385. }
  386. 100% {
  387. opacity: 1;
  388. }
  389. }
  390. .hidden {
  391. opacity: 0;
  392. transition: all 3s ease-in-out;
  393. }
  394. .video-fullscreen_title {
  395. @apply absolute top-3 left-0 pl-[80px] w-[100vw] z-10 flex items-center justify-between flex-row;
  396. color: #fff;
  397. .control-progress {
  398. @apply fixed top-1/2 right-[0px] flex flex-col gap-[3px] z-[100] h-[280px] w-[105px];
  399. transform: translateY(-50%);
  400. view {
  401. overflow: initial !important;
  402. }
  403. .before {
  404. @apply absolute top-0 right-0 h-full w-full bg-[#2BA0F3];
  405. border-radius: 25px 0 0 25px;
  406. }
  407. .ov {
  408. overflow: initial !important;
  409. }
  410. }
  411. }
  412. video::-webkit-media-controls-fullscreen-button,
  413. video::-webkit-media-controls-enter-fullscreen-button,
  414. video::-webkit-media-controls-rotate-button,
  415. video::-webkit-media-controls-seek-back-button,
  416. video::-webkit-media-controls-seek-forward-button {
  417. display: none !important;
  418. }
  419. .mic {
  420. @apply absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2;
  421. }
  422. </style>