study.vue 3.4 KB

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