study.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <view class="kecheng-study-page">
  3. <!-- <view class="icon-title-bjcolor-navBar-box">
  4. <view @click="goUpPage" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">{{name}}</text>
  6. </view> -->
  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. <!-- 视频背景图 -->
  11. <view v-else class="phone-video-box master-image">
  12. <!-- <view class="video-player-icon" @click="handlePlayFirst"></view> -->
  13. </view>
  14. <!-- 播放引导 -->
  15. <view class="yindao-shadow-image" v-if="!showVideo"> </view>
  16. <!-- 中间区域 -->
  17. <view class="kc-name-box">
  18. <icon @click="goUpPage"></icon>
  19. <view>{{name}}</view>
  20. </view>
  21. <view class="kc-info-box">
  22. <view>时长:{{period}}</view>
  23. <view>{{userCount}}人学习</view>
  24. </view>
  25. <!-- 大纲 -->
  26. <view class="phone-tab-box">
  27. <uni-segmented-control :current="current" :values="items" style-type="text" :active-color="activeColor"
  28. @clickItem="onClickItem" />
  29. </view>
  30. <view class="kecheng-content-box">
  31. <!-- 目录 -->
  32. <kechengMuluVue v-if="current === 0" :chapterArr="list" @play="handlePlay" :isHasProgress="true"
  33. :activeKjId="curPlayData&&curPlayData.kjId"></kechengMuluVue>
  34. <!-- 介绍 -->
  35. <rich-text :nodes="intro || '暂无内容'" v-if="current === 1 && intro" class="kecheng-jieshao-box"></rich-text>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import * as kechengApi from "@/api/kecheng.js";
  41. import videoPlayVue from "@/components/videoPlay/videoPlay.vue";
  42. import kechengMuluVue from "@/components/kecheng-mulu/kecheng-mulu.vue";
  43. import {
  44. useUserCache
  45. } from "@/utils/userCache.js"
  46. import {
  47. formatSecondsToCnhms
  48. } from "@/utils/common.js"
  49. import {
  50. useKechengTools
  51. } from "./useKechengCache.js"
  52. const {
  53. getCurKjIndex,
  54. saveKechengData,
  55. getKechengDataFromHistory,
  56. saveKechengSectionPage,
  57. getKechengSectionPageFromHistory,
  58. mergeProgress,
  59. initCourseProgressAll,
  60. saveCourseProgress,
  61. updateSectionProgress,
  62. } = useKechengTools();
  63. export default {
  64. components: {
  65. videoPlayVue,
  66. kechengMuluVue
  67. },
  68. data() {
  69. return {
  70. showVideo: false,
  71. items: ['目录', '介绍'],
  72. colors: ['#007aff', '#4cd964', '#dd524d'],
  73. activeColor: '#3fd2a1',
  74. current: 0, // 激活的选项卡
  75. operId: '', // 课程
  76. name: '',
  77. period: 0, // 时长
  78. userCount: 0, // 学习人数
  79. list: [],
  80. intro: '',
  81. curPlayData: null,
  82. timer1: null,
  83. kcId: null,
  84. from: '',
  85. jzId: null,
  86. }
  87. },
  88. onLoad(options) {
  89. this.kcId = options.kcId;
  90. this.from = options.from;
  91. this.jzId = options.jzId;
  92. this.init();
  93. },
  94. methods: {
  95. handlePlayFirst() {
  96. if (this.list && this.list[0].jieList && this.list[0].jieList[0].kejianList) {
  97. // 设置默认展开项
  98. this.list[0].open = true;
  99. this.list[0].jieList[0].open = true;
  100. // 设置播放可见
  101. const kejian = this.list[0].jieList[0].kejianList[0];
  102. this.handlePlay(kejian)
  103. }
  104. },
  105. onPause() {
  106. clearInterval(this.timer1);
  107. this.timer1 = null;
  108. },
  109. onPlay() {
  110. clearInterval(this.timer1);
  111. this.timer1 = null;
  112. // this.timer = setInterval(() => {
  113. // updateSectionProgress(this.operId);
  114. // }, 1000 * 1 * 60) // 自动保存进度 1分钟已保存
  115. },
  116. sectionPlayerProgress(progress) {
  117. let sectionPage = getKechengSectionPageFromHistory(this.operId);
  118. let maxProcess = this.list[sectionPage.iChapter].jieList[sectionPage.iSection].kejianList.find(it1=>it1.kjId == sectionPage.kjId).maxProcess;
  119. // 更新缓存进度
  120. this.list[sectionPage.iChapter].jieList[sectionPage.iSection].kejianList.find(it1=>it1.kjId == sectionPage.kjId).curProcess = progress;
  121. if (progress < 100) {
  122. // 播放进度小于100
  123. if (progress < maxProcess) {
  124. this.list[sectionPage.iChapter].jieList[sectionPage.iSection].kejianList.find(it1=>it1.kjId == sectionPage.kjId).maxProcess = maxProcess
  125. } else {
  126. this.list[sectionPage.iChapter].jieList[sectionPage.iSection].kejianList.find(it1=>it1.kjId == sectionPage.kjId).maxProcess = progress
  127. }
  128. } else {
  129. // 播放进度大于100
  130. this.list[sectionPage.iChapter].jieList[sectionPage.iSection].kejianList.find(it1=>it1.kjId == sectionPage.kjId).maxProcess = 100
  131. }
  132. },
  133. onTimeupdate(time) {
  134. const progress = parseInt(time / this.curPlayData.duration * 100);
  135. this.curPlayData.curProgress = parseInt(progress >= 100 ? '99' : progress);
  136. // 保存进度
  137. // saveCourseProgress(time, this.curPlayData.duration, this.operId)
  138. // 更新进度
  139. // this.sectionPlayerProgress(progress)
  140. },
  141. onPlayEnd() {
  142. clearInterval(this.timer1);
  143. this.timer1 = null;
  144. // saveCourseProgress(this.curPlayData.duration, this.curPlayData.duration, this.operId, 'end');
  145. // updateSectionProgress(this.operId, 'end', 'video', () => {
  146. // this.curPlayData.maxProcess = 99;
  147. // this.curPlayData.curProcess = 99;
  148. // });
  149. console.log('end')
  150. },
  151. goUpPage() {
  152. const pages = getCurrentPages();
  153. if (pages.length>1) {
  154. uni.navigateBack()
  155. } else {
  156. /* if (this.from == 'kechengList') {
  157. uni.redirectTo({
  158. url: '/pages/client/Kecheng/list'
  159. })
  160. } else if (this.from == 'shouye') {
  161. uni.redirectTo({
  162. url: '/pages/client/ShouYe/shouye'
  163. })
  164. } else {
  165. uni.redirectTo({
  166. url: '/pages/client/ShouYe/shouye'
  167. })
  168. } */
  169. history.back();
  170. }
  171. },
  172. onClickItem(e) {
  173. if (this.current !== e.currentIndex) {
  174. this.current = e.currentIndex
  175. }
  176. },
  177. formatData(data) {
  178. data.forEach(zhang => {
  179. zhang.open = false;
  180. zhang.jieList.forEach(jie => {
  181. jie.open = false;
  182. })
  183. })
  184. return data;
  185. },
  186. handlePlay(data) {
  187. this.showVideo = true;
  188. if (this.curPlayData && this.curPlayData.url == data.url) {
  189. return;
  190. }
  191. this.curPlayData = data;
  192. const {
  193. zhangIndex,
  194. jieIndex
  195. } = getCurKjIndex(data.kjId,this.operId)
  196. const sectionPage = {};
  197. sectionPage.iChapter = zhangIndex;
  198. sectionPage.iSection = jieIndex;
  199. sectionPage.kjId = data.kjId;
  200. sectionPage.operId = this.operId;
  201. // saveKechengSectionPage(this.operId, sectionPage)
  202. kechengApi.getVideoAuth({
  203. videoId: data.url
  204. }).then(res => {
  205. const progress = data.curProcess || 0;
  206. this.$refs.videoRef.init({
  207. videoId: data.url,
  208. playAuth: res.data,
  209. seekTime: data.duration * progress / 100,
  210. isPlay: false
  211. })
  212. })
  213. },
  214. initFirstVideo() {
  215. if (this.list && this.list[0].jieList && this.list[0].jieList[0].kejianList) {
  216. // 设置默认展开项
  217. this.list[0].open = true;
  218. this.list[0].jieList[0].open = true;
  219. // 设置播放可见
  220. const kejian = this.list[0].jieList[0].kejianList[0];
  221. // this.handlePlay(kejian)
  222. }
  223. //saveKechengSectionPage(this.operId, sectionPage)
  224. },
  225. init() {
  226. kechengApi.getClientKechengStart({
  227. kcId: this.kcId,
  228. jzId:this.jzId
  229. }).then(res => {
  230. const {
  231. userCount,
  232. period,
  233. name,
  234. kejianUserVo,
  235. intro,
  236. operId,
  237. } = res.data;
  238. this.userCount = userCount;
  239. this.period = formatSecondsToCnhms(period,true);
  240. this.name = name;
  241. this.formatData(kejianUserVo.zhangList)
  242. this.list = kejianUserVo.zhangList;
  243. this.intro = intro;
  244. this.operId = operId;
  245. // 获取课程缓存 && 课件缓存(课件缓存点击后产生)
  246. //let historyArrKecheng = getKechengDataFromHistory(this.operId)
  247. // let sectionPageHistory = getKechengSectionPageFromHistory(this.operId)
  248. // // 判断是否有前台缓存
  249. // if (historyArrKecheng && sectionPageHistory) {
  250. // // 有缓存---- 把start接口中,返回数据进度100%,更新到前台缓存
  251. // const arrKecheng = mergeProgress(kejianUserVo && kejianUserVo.zhangList,
  252. // historyArrKecheng);
  253. // // 后台数据 同步前台缓存
  254. // saveKechengData(this.operId, arrKecheng)
  255. // } else {
  256. // // 无缓存----把start接口中,返回的所有数据,更新到前台缓存
  257. // saveKechengData(this.operId, kejianUserVo && kejianUserVo.zhangList)
  258. // }
  259. // 初始化页面 常规数据
  260. //initCourseProgressAll(this.operId)
  261. console.log('初始化播放首1123次')
  262. // 设置播放视频
  263. this.initFirstVideo();
  264. }).catch(err => {
  265. this.goUpPage();
  266. })
  267. }
  268. }
  269. }
  270. </script>
  271. <style>
  272. </style>