study.vue 3.8 KB

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