study.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <view class="kecheng-study-page">
  3. <view class="icon-title-navBar-box">
  4. <view @click="goUpPage" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">{{title}}</text>
  6. </view>
  7. <!-- 播放器 -->
  8. <videoPlayVue ref="videoRef"></videoPlayVue>
  9. <!-- 中间区域 -->
  10. <view>
  11. <view>{{period}}分钟</view>
  12. <view>{{userCount}}人学习</view>
  13. </view>
  14. <!-- 大纲 -->
  15. <view class="uni-padding-wrap uni-common-mt">
  16. <uni-segmented-control :current="current" :values="items" style-type="text" :active-color="activeColor"
  17. @clickItem="onClickItem" />
  18. </view>
  19. <view class="content">
  20. <!-- 目录 -->
  21. <view v-if="current === 0">
  22. <kechengMuluVue :chapterArr="list" @play="handlePlay" :isHasProgress="false"></kechengMuluVue>
  23. </view>
  24. <!-- 介绍 -->
  25. <view v-if="current === 1 && intro">
  26. <rich-text :nodes="intro"></rich-text>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import * as kechengApi from "@/api/kecheng.js";
  33. import videoPlayVue from "@/components/videoPlay/videoPlay.vue";
  34. import kechengMuluVue from "@/components/kecheng-mulu/kecheng-mulu.vue";
  35. import {
  36. useUserCache
  37. } from "@/utils/kechengCache.js"
  38. import {
  39. formatDuration
  40. } from "@/utils/common.js"
  41. export default {
  42. components: {
  43. videoPlayVue,
  44. kechengMuluVue
  45. },
  46. data() {
  47. return {
  48. items: ['目录', '介绍'],
  49. colors: ['#007aff', '#4cd964', '#dd524d'],
  50. activeColor: '#007aff',
  51. current: 0, // 激活的选项卡
  52. kcId: '', // 课程
  53. title: '',
  54. period: 0, // 时长
  55. userCount: 0, // 学习人数
  56. list: [],
  57. intro: '',
  58. curPlayData: null
  59. }
  60. },
  61. onLoad(options) {
  62. this.kcId = options.kcId;
  63. this.init();
  64. },
  65. methods: {
  66. goUpPage() {
  67. uni.redirectTo({
  68. url: '/pages/admin/Kecheng/list'
  69. })
  70. },
  71. onClickItem(e) {
  72. if (this.current !== e.currentIndex) {
  73. this.current = e.currentIndex
  74. }
  75. },
  76. formatData(data) {
  77. data.forEach(zhang => {
  78. zhang.open = false;
  79. zhang.jieList.forEach(jie => {
  80. jie.open = false;
  81. })
  82. })
  83. return data;
  84. },
  85. handlePlay(data) {
  86. if (this.curPlayData && this.curPlayData.videoId == data.videoId) {
  87. return;
  88. }
  89. // console.log('播放进度', data)
  90. kechengApi.getVideoAuth({
  91. videoId: data.url
  92. }).then(res => {
  93. // console.log('切换视频', {
  94. // videoId: data.url,
  95. // playAuth: res.data,
  96. // seekTime: '',
  97. // });
  98. this.$refs.videoRef.init({
  99. videoId: data.url,
  100. playAuth: res.data,
  101. seekTime: '',
  102. })
  103. })
  104. },
  105. initFirstVideo() {
  106. if (this.list && this.list[0].jieList && this.list[0].jieList[0].kejianList) {
  107. const kejian = this.list[0].jieList[0].kejianList[0];
  108. this.handlePlay(kejian)
  109. }
  110. },
  111. init() {
  112. kechengApi.getKechengGlStart({
  113. kcId: this.kcId
  114. }).then(res => {
  115. const {
  116. userCount,
  117. period,
  118. name,
  119. kejianUserVo,
  120. intro
  121. } = res.data;
  122. this.userCount = userCount;
  123. this.period = formatDuration(period);
  124. this.name = name;
  125. let testData = JSON.parse(JSON.stringify([...kejianUserVo.zhangList, ...kejianUserVo.zhangList,
  126. ...kejianUserVo.zhangList
  127. ]))
  128. this.formatData(testData)
  129. this.list = testData;
  130. this.intro = intro;
  131. this.initFirstVideo();
  132. uni.setNavigationBarTitle({
  133. title: this.name
  134. });
  135. })
  136. }
  137. }
  138. }
  139. </script>
  140. <style>
  141. </style>