detail.uvue 17 KB

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