study.vue 11 KB

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