study.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <template>
  2. <view class="kecheng-study-page">
  3. <zmm-watermark :watermark="watermark"
  4. color="#999" column="2" margin="24" opacity="0.1">
  5. </zmm-watermark>
  6. <customNavbarVue :title="name" :show-back-btn="true" @back="goUpPage" class="kecheng-study-navBar"></customNavbarVue>
  7. <!-- 播放器 -->
  8. <!-- <videoPlayVue v-if="showVideo" ref="videoRef" class="phone-video-box" @play-end="onPlayEnd" @play-play="onPlay"
  9. @play-pause="onPause" @play-timeupdate="onTimeupdate"></videoPlayVue> -->
  10. <video v-if="showVideo" :src="videoUrl" :poster="videoPoster" controls class="phone-video-box" :show-fullscreen-btn='false'
  11. @play="onVideoPlay" @pause="onVideoPause" @ended="onVideoEnd" @error="onVideoError" id="myVideo"></video>
  12. <view v-else class="phone-video-box master-image" :style="{ backgroundImage: 'url(' + imgsArr.videoBj + ')' }">
  13. <!-- <view class="video-player-icon" @click="handlePlayFirst"></view> -->
  14. </view>
  15. <view class="kecheng-study-body">
  16. <!-- 播放引导 -->
  17. <view class="yindao-shadow-image" v-if="!shaDowImgFlag"
  18. :style="{ backgroundImage: 'url(' + imgsArr.pointIcon + ')' }"> </view>
  19. <!-- 中间区域 -->
  20. <view class="kc-info-box">
  21. <view class="info-tip">旋转手机,享受横屏沉浸式视频学习体验</view>
  22. <view class="info-content-box">
  23. <view>时长:{{period}}</view>
  24. <view>{{userCount}}人学习</view>
  25. </view>
  26. <view class="info-sm">
  27. 郑重声明:课程版权归平台所有,禁止对本课程进行任何录音录像,违者将承担法律责任。
  28. </view>
  29. </view>
  30. <!-- 大纲 -->
  31. <view class="phone-tab-box">
  32. <uni-segmented-control :current="current" :values="items" style-type="text" :active-color="activeColor"
  33. @clickItem="onClickItem" />
  34. </view>
  35. <view class="kecheng-content-box">
  36. <!-- 目录 -->
  37. <kechengMuluVue v-if="current === 0" :chapterArr="list" @play="handlePlay" :isHasProgress="true"
  38. :activeKjId="curPlayData&&curPlayData.kjId"></kechengMuluVue>
  39. <!-- 介绍 -->
  40. <rich-text :nodes="intro || '暂无内容'" v-if="current === 1 && intro" class="kecheng-jieshao-box"></rich-text>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. import cacheManager from '@/utils/cacheManager.js';
  47. import * as kechengApi from "@/api/kecheng.js";
  48. import customNavbarVue from "@/components/custom-navbar/custom-navbar.vue";
  49. import videoPlayVue from "@/components/videoPlay/videoPlay.vue";
  50. import kechengMuluVue from "@/components/kecheng-mulu/kecheng-mulu.vue";
  51. import {
  52. useUserCache
  53. } from "@/utils/userCache.js"
  54. import {
  55. formatSecondsToCnhms
  56. } from "@/utils/common.js"
  57. import {
  58. useKechengTools
  59. } from "./useKechengCache.js"
  60. const {
  61. getCurKjIndex,
  62. saveKechengData,
  63. getKechengDataFromHistory,
  64. saveKechengSectionPage,
  65. getKechengSectionPageFromHistory,
  66. mergeProgress,
  67. initCourseProgressAll,
  68. saveCourseProgress,
  69. updateSectionProgress,
  70. } = useKechengTools();
  71. export default {
  72. components: {
  73. videoPlayVue,
  74. kechengMuluVue,
  75. customNavbarVue
  76. },
  77. data() {
  78. return {
  79. showVideo: false,
  80. shaDowImgFlag: false,
  81. items: ['目录', '介绍'],
  82. colors: ['#007aff', '#4cd964', '#dd524d'],
  83. activeColor: '#3fd2a1',
  84. current: 0, // 激活的选项卡
  85. operId: '', // 课程
  86. name: '',
  87. period: 0, // 时长
  88. userCount: 0, // 学习人数
  89. list: [],
  90. intro: '',
  91. curPlayData: null,
  92. timer1: null,
  93. kcId: null,
  94. from: '',
  95. jzId: null,
  96. watermark:` <h5>${cacheManager.get('auth').realName}${cacheManager.get('auth').userName.slice(-4)}</h5>`,
  97. videoUrl: '', // 视频地址
  98. videoPoster: '', // 视频封面
  99. videoInfo: {}, // 视频信息
  100. loading: false, // 加载状态
  101. error: false, // 错误状态
  102. errorMessage: '', // 错误信息
  103. videoContext: null, // 视频上下文
  104. imgsArr: {}
  105. }
  106. },
  107. onLoad(options) {
  108. this.kcId = options.kcId;
  109. this.from = options.from;
  110. this.jzId = options.jzId;
  111. this.imgsArr.videoBj = cacheManager.get('projectImg').video_bj;
  112. this.imgsArr.pointIcon = cacheManager.get('projectImg').course_point_icon;
  113. this.init();
  114. },
  115. methods: {
  116. // 播放视频
  117. playVideo() {
  118. if (this.videoUrl) {
  119. this.videoContext.play()
  120. } else {
  121. uni.showToast({
  122. title: '暂无视频可播放',
  123. icon: 'none'
  124. })
  125. }
  126. },
  127. // 暂停视频
  128. pauseVideo() {
  129. this.videoContext.pause()
  130. },
  131. // 重新播放
  132. replayVideo() {
  133. this.videoContext.seek(0)
  134. this.videoContext.play()
  135. },
  136. // 视频开始播放
  137. onVideoPlay() {
  138. console.log('视频开始播放')
  139. },
  140. // 视频暂停
  141. onVideoPause() {
  142. console.log('视频暂停')
  143. },
  144. // 视频播放结束
  145. onVideoEnd() {
  146. console.log('视频播放结束')
  147. uni.showToast({
  148. title: '播放完成',
  149. icon: 'success'
  150. })
  151. },
  152. // 视频播放错误
  153. onVideoError(e) {
  154. console.error('视频播放错误:', e.detail.errMsg)
  155. this.error = true
  156. this.errorMessage = '视频播放出错,请检查视频地址或格式'
  157. },
  158. // 重新加载视频
  159. retryLoadVideo() {
  160. this.getVideoData()
  161. },
  162. handlePlayFirst() {
  163. console.log('this.list', this.list);
  164. if (this.list && this.list[0].jieList && this.list[0].jieList[0].kejianList) {
  165. // 设置默认展开项
  166. this.list[0].open = true;
  167. this.list[0].jieList[0].open = true;
  168. // 设置播放可见
  169. const kejian = this.list[0].jieList[0].kejianList[0];
  170. this.handlePlay(kejian)
  171. }
  172. },
  173. onPause() {
  174. clearInterval(this.timer1);
  175. this.timer1 = null;
  176. },
  177. onPlay() {
  178. clearInterval(this.timer1);
  179. this.timer1 = null;
  180. // this.timer = setInterval(() => {
  181. // updateSectionProgress(this.operId);
  182. // }, 1000 * 1 * 60) // 自动保存进度 1分钟已保存
  183. },
  184. sectionPlayerProgress(progress) {
  185. let sectionPage = getKechengSectionPageFromHistory(this.operId);
  186. let maxProcess = this.list[sectionPage.iChapter].jieList[sectionPage.iSection].kejianList.find(it1 => it1
  187. .kjId == sectionPage.kjId).maxProcess;
  188. // 更新缓存进度
  189. this.list[sectionPage.iChapter].jieList[sectionPage.iSection].kejianList.find(it1 => it1.kjId ==
  190. sectionPage.kjId).curProcess = progress;
  191. if (progress < 100) {
  192. // 播放进度小于100
  193. if (progress < maxProcess) {
  194. this.list[sectionPage.iChapter].jieList[sectionPage.iSection].kejianList.find(it1 => it1.kjId ==
  195. sectionPage.kjId).maxProcess = maxProcess
  196. } else {
  197. this.list[sectionPage.iChapter].jieList[sectionPage.iSection].kejianList.find(it1 => it1.kjId ==
  198. sectionPage.kjId).maxProcess = progress
  199. }
  200. } else {
  201. // 播放进度大于100
  202. this.list[sectionPage.iChapter].jieList[sectionPage.iSection].kejianList.find(it1 => it1.kjId ==
  203. sectionPage.kjId).maxProcess = 100
  204. }
  205. },
  206. onTimeupdate(time) {
  207. const progress = parseInt(time / this.curPlayData.duration * 100);
  208. this.curPlayData.curProgress = parseInt(progress >= 100 ? '99' : progress);
  209. // 保存进度
  210. // saveCourseProgress(time, this.curPlayData.duration, this.operId)
  211. // 更新进度
  212. // this.sectionPlayerProgress(progress)
  213. },
  214. onPlayEnd() {
  215. clearInterval(this.timer1);
  216. this.timer1 = null;
  217. // saveCourseProgress(this.curPlayData.duration, this.curPlayData.duration, this.operId, 'end');
  218. // updateSectionProgress(this.operId, 'end', 'video', () => {
  219. // this.curPlayData.maxProcess = 99;
  220. // this.curPlayData.curProcess = 99;
  221. // });
  222. console.log('end')
  223. },
  224. goUpPage() {
  225. const pages = getCurrentPages();
  226. if (pages.length > 1) {
  227. uni.navigateBack()
  228. } else {
  229. /* if (this.from == 'kechengList') {
  230. uni.redirectTo({
  231. url: '/pages/client/Kecheng/list'
  232. })
  233. } else if (this.from == 'shouye') {
  234. uni.redirectTo({
  235. url: '/pages/client/ShouYe/shouye'
  236. })
  237. } else {
  238. uni.redirectTo({
  239. url: '/pages/client/ShouYe/shouye'
  240. })
  241. } */
  242. history.back();
  243. }
  244. },
  245. onClickItem(e) {
  246. if (this.current !== e.currentIndex) {
  247. this.current = e.currentIndex
  248. }
  249. // if (this.current == 0) {
  250. // if (!this.showVideo) {
  251. // this.shaDowImgFlag = false
  252. // } else {
  253. // this.shaDowImgFlag = true
  254. // }
  255. // } else {
  256. // this.shaDowImgFlag = true
  257. // }
  258. this.shaDowImgFlag = this.current !== 0 || this.showVideo
  259. },
  260. formatData(data) {
  261. data.forEach(zhang => {
  262. zhang.open = false;
  263. zhang.jieList.forEach(jie => {
  264. jie.open = false;
  265. })
  266. })
  267. return data;
  268. },
  269. handlePlay(data) {
  270. this.showVideo = true;
  271. this.shaDowImgFlag = true;
  272. if (this.curPlayData && this.curPlayData.url == data.url) {
  273. return;
  274. }
  275. console.log('data', data);
  276. this.curPlayData = data;
  277. //this.videoUrl = 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4'
  278. kechengApi.getVideoId({
  279. videoId: data.url
  280. }).then(res => {
  281. this.videoUrl = res.data
  282. console.log('res', res);
  283. // const progress = data.curProcess || 0;
  284. // this.$refs.videoRef.init({
  285. // videoId: data.url,
  286. // playAuth: res.data,
  287. // seekTime: data.duration * progress / 100,
  288. // isPlay: false
  289. // })
  290. })
  291. },
  292. initFirstVideo() {
  293. if (this.list && this.list[0].jieList && this.list[0].jieList[0].kejianList) {
  294. // 设置默认展开项
  295. this.list[0].open = true;
  296. this.list[0].jieList[0].open = true;
  297. // 设置播放可见
  298. const kejian = this.list[0].jieList[0].kejianList[0];
  299. // this.handlePlay(kejian)
  300. }
  301. //saveKechengSectionPage(this.operId, sectionPage)
  302. },
  303. init() {
  304. kechengApi.getClientKechengStart({
  305. kcId: this.kcId,
  306. jzId: this.jzId
  307. }).then(res => {
  308. const {
  309. userCount,
  310. period,
  311. name,
  312. kejianUserVo,
  313. intro,
  314. operId,
  315. } = res.data;
  316. this.userCount = userCount;
  317. this.period = formatSecondsToCnhms(period, true);
  318. this.name = name;
  319. this.formatData(kejianUserVo.zhangList)
  320. this.list = kejianUserVo.zhangList;
  321. this.intro = intro;
  322. this.operId = operId;
  323. // 获取课程缓存 && 课件缓存(课件缓存点击后产生)
  324. //let historyArrKecheng = getKechengDataFromHistory(this.operId)
  325. // let sectionPageHistory = getKechengSectionPageFromHistory(this.operId)
  326. // // 判断是否有前台缓存
  327. // if (historyArrKecheng && sectionPageHistory) {
  328. // // 有缓存---- 把start接口中,返回数据进度100%,更新到前台缓存
  329. // const arrKecheng = mergeProgress(kejianUserVo && kejianUserVo.zhangList,
  330. // historyArrKecheng);
  331. // // 后台数据 同步前台缓存
  332. // saveKechengData(this.operId, arrKecheng)
  333. // } else {
  334. // // 无缓存----把start接口中,返回的所有数据,更新到前台缓存
  335. // saveKechengData(this.operId, kejianUserVo && kejianUserVo.zhangList)
  336. // }
  337. // 初始化页面 常规数据
  338. //initCourseProgressAll(this.operId)
  339. console.log('初始化播放首1123次')
  340. // 设置播放视频
  341. this.initFirstVideo();
  342. }).catch(err => {
  343. this.goUpPage();
  344. })
  345. }
  346. }
  347. }
  348. </script>
  349. <style lang="scss">
  350. </style>