detail.uvue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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 } from '@/services/subject/course'
  6. import { router } 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 < 2000) {
  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. //通过路由参数获取课程id
  52. async function fetchCatalog() {
  53. course.value = await fetchSubjectCourseApp({ id: router.query().id })
  54. if (!course.value?.courseUserProgress) {
  55. await updateSubjectProgress({
  56. courseId: course.value?.id,
  57. mainProgress: 1,
  58. assistantProgress: 1,
  59. status: 0
  60. })
  61. progress.value = 1
  62. progress2.value = 1
  63. } else if (course.value?.courseUserProgress.status == 0) {
  64. progressStatus.value = course.value?.courseUserProgress.status
  65. progress2.value = course.value?.courseUserProgress.assistantProgress
  66. } else {
  67. progressStatus.value = course.value?.courseUserProgress.status
  68. progress2.value = 1
  69. }
  70. }
  71. onMounted(async () => {
  72. isLoading.value = true
  73. await fetchCatalog()
  74. initOnlibeRecord()
  75. setTimeout(() => {
  76. isLoading.value = false
  77. }, 1000)
  78. })
  79. async function handleEnded() {
  80. progress2.value++
  81. }
  82. const status = ref('wait')
  83. onShow(async () => {
  84. isLoading.value = true
  85. var pages = getCurrentPages();
  86. const prevPage = pages[pages.length - 1];
  87. status.value = (prevPage as any)?.status || 'wait'
  88. console.log(status.value);
  89. if (status.value === 'success') {
  90. if (progress2.value === 6) {
  91. if (progressStatus.value === 0) {
  92. await updateSubjectProgress({
  93. courseId: course.value?.id,
  94. mainProgress: 1,
  95. assistantProgress: 6,
  96. status: 1
  97. })
  98. }
  99. router.back()
  100. return
  101. }
  102. progress2.value++;
  103. (prevPage as any).status = 'wait'
  104. }
  105. isLoading.value = false
  106. })
  107. function handleControlsToggle(e) {
  108. showControls.value = e.detail.show
  109. }
  110. watch(() => progress2.value, (newVal, oldVal) => {
  111. isLoading.value = true
  112. if (course.value?.id && progressStatus.value == 0) {
  113. updateSubjectProgress({
  114. courseId: course.value?.id,
  115. mainProgress: 1,
  116. assistantProgress: progress2.value,
  117. status: progressStatus.value
  118. })
  119. }
  120. console.log(progress2.value);
  121. switch (progress2.value) {
  122. case 1:
  123. setTimeout(() => {
  124. isLoading.value = false
  125. data.value.videoSrc = course.value?.detailItem?.observeVideoPath
  126. }, 2000)
  127. break
  128. case 2:
  129. data.value.webviewSrc = course.value?.detailItem?.summaryVideoPath
  130. router.push({
  131. path: "/pages/catalog/web-view",
  132. query: {
  133. src: data.value.webviewSrc,
  134. progress: progress2.value,
  135. }
  136. });
  137. break
  138. case 3:
  139. setTimeout(() => {
  140. isLoading.value = false
  141. data.value.videoSrc = course.value?.detailItem?.questionVideoPath
  142. }, 2000)
  143. break
  144. case 4:
  145. setTimeout(() => {
  146. isLoading.value = false
  147. playVoice(course.value?.detailItem?.assumeAnimationPath)
  148. }, 2000)
  149. break
  150. case 5:
  151. setTimeout(() => {
  152. isLoading.value = false
  153. data.value.videoSrc = course.value?.detailItem?.testVideoPath
  154. }, 2000)
  155. break
  156. case 6:
  157. data.value.webviewSrc = course.value?.testItem?.animationPath
  158. router.push({
  159. path: "/pages/catalog/web-view",
  160. query: {
  161. src: data.value.webviewSrc,
  162. progress: progress2.value,
  163. }
  164. });
  165. break
  166. }
  167. }, { immediate: true })
  168. const timers = ref(100)
  169. const timer = ref<any>()
  170. function handleTop() {
  171. progress2.value = 5
  172. }
  173. function startRecord() {
  174. console.log('开始录音');
  175. timer.value = setInterval(() => {
  176. timers.value--
  177. console.log(timers.value);
  178. if (timers.value <= 0) {
  179. endRecord()
  180. }
  181. }, 800)
  182. recorderManager.value.start();
  183. }
  184. function endRecord() {
  185. clearInterval(timer.value)
  186. timer.value = null
  187. timers.value = 100
  188. recorderManager.value.stop();
  189. }
  190. function playVoice(val) {
  191. innerAudioContext.value.src = val;
  192. innerAudioContext.value.play();
  193. }
  194. onUnmounted(() => {
  195. clearInterval(timer.value)
  196. innerAudioContext.value.stop();
  197. })
  198. </script>
  199. <template>
  200. <Loading v-show="isLoading" />
  201. <cl-page v-show="!isLoading">
  202. <Back />
  203. <view class="video-container">
  204. <video v-if="progress2 !== 4" id="video1" class="w-full h-full " :src="data.videoSrc"
  205. :show-center-play-btn="false" :show-background-playback-button="false" :show-fullscreen-btn="false"
  206. :show-casting-button="false" autoplay @controlstoggle="handleControlsToggle" @ended="handleEnded">
  207. </video>
  208. <view v-else class="w-full h-full ">
  209. <img src="https://oss.xiaoxiongcode.com/static/home/assert_1.gif" alt="" class="w-full h-full object-cover" />
  210. <!-- 顶部提示文字 -->
  211. <view class="absolute text-[20px] top-[20vh] w-full flex flex-row items-center justify-center">
  212. <!-- <cl-icon name="notification-3-fill" color="#FCE762" :size="40"></cl-icon> -->
  213. <cl-image src="https://oss.xiaoxiongcode.com/static/home/guangbo.png" mode="heightFix" class="!h-[25px]"
  214. @tap="playVoice(course?.detailItem?.assumeAnimationPath)"></cl-image>
  215. <text class=" font-bold text-white">{{ course?.detailItem?.assumeAnimationJavascriptPath }}</text>
  216. </view>
  217. <!-- 居中麦克风按钮 -->
  218. <view class=" mic flex flex-col items-center w-[220px] h-[220px]">
  219. <view v-show="timer" class="mic">
  220. <cl-progress-circle :value="timers"></cl-progress-circle>
  221. </view>
  222. <view
  223. class="mic w-[120px] h-[120px] bg-[#3CB8FF] rounded-full flex items-center justify-center z-[2] border-[4px] border-white border-solid"
  224. @tap="startRecord" v-if="!timer">
  225. <cl-image src="https://oss.xiaoxiongcode.com/static/home/maikefeng.png" mode="heightFix"
  226. class="!h-[60px]"></cl-image>
  227. </view>
  228. <template v-else>
  229. <view class="mic w-[120px] h-[120px] bg-[#3CB8FF] rounded-full flex items-center justify-center z-[2]"
  230. @tap="endRecord">
  231. <view class="w-[50px] h-[50px] rounded-[5px] bg-white"></view>
  232. </view>
  233. </template>
  234. <!-- 指示手指 -->
  235. <view class="absolute bottom-[20px] right-[20px] animate-bounce pointer-events-none z-[2] !h-[60px] w-[100px]"
  236. v-if="!timer && !voicePath">
  237. <cl-image src="https://oss.xiaoxiongcode.com/static/home/shou.png" mode="heightFix" width="100%"
  238. class=""></cl-image>
  239. </view>
  240. </view>
  241. <!-- 下一步按钮 (录音完成后显示) -->
  242. <view v-show="voicePath" class="mic flex flex-row items-center justify-center gap-[200px]">
  243. <button
  244. 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"
  245. @tap="playVoice(voicePath)">
  246. <cl-image src="https://oss.xiaoxiongcode.com/static/home/guangbo-bai.png" mode="heightFix"
  247. class="!h-[25px]"></cl-image>
  248. </button>
  249. <button
  250. 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"
  251. @tap="handleTop">√</button>
  252. </view>
  253. </view>
  254. <view class="video-fullscreen_title" v-show="showControls">
  255. <Back />
  256. <view class="text-[20px] font-bold text-white">
  257. {{ course?.mainTitle }}
  258. </view>
  259. <view class="control-progress">
  260. <view class="before"></view>
  261. <view v-for="(item, i) in menu2Items" :key="item.id"
  262. class="py-2 px-3 flex items-center flex-row justify-center gap-[5px] relative z-[1]"
  263. :class="{ '!bg-[#fff] rounded-l-full': progress2 == i + 1 }" @tap="progress2 = i + 1">
  264. <cl-image :src="item.icon" mode="heightFix" class="!h-[28px] !w-[50px]"></cl-image>
  265. <text class="text-[12px] font-bold" :class="{ '!text-[#2BA0F3]': progress2 == i + 1 }">{{ item.name
  266. }}</text>
  267. </view>
  268. </view>
  269. </view>
  270. </view>
  271. <view class="course-detail-page">
  272. <!-- 顶部标题栏 -->
  273. <view class="flex-[1] h-[100vh] relative">
  274. <!-- <view class="flex flex-row w-full pr-[3vw] pl-[10vw] items-center justify-between absolute top-[30px]">
  275. <text class="text-[5vh] font-bold">{{ course?.mainTitle }}</text>
  276. <text
  277. class="rounded-full p-[1vh] px-[2vh] border-2 border-[#fff] border-solid text-[#fff] text-[3vh] font-bold">课程收获</text>
  278. </view> -->
  279. </view>
  280. <!-- 右侧功能菜单 -->
  281. <!-- <view class="w-[25vw] h-[100vh] bg-[#5CBDFD] flex flex-col justify-center p-5">
  282. <view v-for="(item, i) in menuItems" :key="item.id" class="h-[20vh] flex flex-row items-center ">
  283. <view
  284. 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]"
  285. :class="{ '!bg-[#fff]': progress >= i }">
  286. <cl-image :src="item.icon" mode="heightFix" class="!h-[7vh]"></cl-image>
  287. <text class="text-[2vh] font-bold">{{ item.name }}</text>
  288. </view>
  289. <view class="flex items-center h-[20vh] ml-[2vh] ">
  290. <view class="w-[1vh] bg-[#B4DBF7] flex-1"
  291. :class="{ '!bg-[#71C73D]': progress >= i, '!opacity-0': i === 0 }">
  292. </view>
  293. <view class="w-[5vh] bg-[#fff] h-[5vh] rounded-full" :class="{ '!bg-[#71C73D]': progress >= i }"></view>
  294. <view class="w-[1vh] bg-[#B4DBF7] flex-1"
  295. :class="{ '!bg-[#71C73D]': progress >= i, '!opacity-0': i === menuItems.length - 1 }"></view>
  296. </view>
  297. </view>
  298. </view> -->
  299. </view>
  300. </cl-page>
  301. </template>
  302. <style lang="scss" scoped>
  303. .translate50 {
  304. transform: translateY(-50%);
  305. }
  306. .course-detail-page {
  307. @apply flex flex-row items-center;
  308. background-color: #3498DB;
  309. height: 100vh;
  310. color: black;
  311. transition: all 1s ease-in-out;
  312. }
  313. .video-container {
  314. width: 100vw;
  315. height: 100vh;
  316. top: 0;
  317. left: 0;
  318. transform: translate(0, 0);
  319. animation: spin 2s linear 1;
  320. transition: all 2s ease-in-out;
  321. }
  322. @keyframes spin {
  323. 0% {
  324. opacity: 50%;
  325. }
  326. 100% {
  327. opacity: 1;
  328. }
  329. }
  330. .hidden {
  331. opacity: 0;
  332. transition: all 3s ease-in-out;
  333. }
  334. .video-fullscreen_title {
  335. @apply absolute top-3 left-0 pl-[80px] w-[100vw] z-10 flex items-center justify-between flex-row;
  336. color: #fff;
  337. .control-progress {
  338. @apply fixed top-1/2 right-[0px] flex flex-col gap-[3px] z-[100] h-[280px];
  339. transform: translateY(-50%);
  340. .before {
  341. @apply absolute top-0 right-0 h-full w-full bg-[#2BA0F3];
  342. border-radius: 25px 0 0 25px;
  343. }
  344. }
  345. }
  346. video::-webkit-media-controls-fullscreen-button,
  347. video::-webkit-media-controls-enter-fullscreen-button,
  348. video::-webkit-media-controls-rotate-button,
  349. video::-webkit-media-controls-seek-back-button,
  350. video::-webkit-media-controls-seek-forward-button {
  351. display: none !important;
  352. }
  353. .mic {
  354. @apply absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2;
  355. }
  356. </style>