kechengInfo.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <view class="course-container">
  3. <!-- 视频播放器 -->
  4. <video v-if="currentVideo.url" :src="currentVideo.url" :id="videoId" controls @ended="handleVideoEnd"
  5. @timeupdate="handleTimeUpdate" @loadedmetadata="handleVideoLoaded">
  6. </video>
  7. <!-- 课程信息 -->
  8. <view class="course-header">
  9. <text class="course-title">测试课程1</text>
  10. <view class="course-meta">
  11. <text>讲师:张老师</text>
  12. <text>时长:3分42秒</text>
  13. <text>1人学习</text>
  14. </view>
  15. </view>
  16. <!-- 选项卡 -->
  17. <view class="course-tabs">
  18. <text :class="['tab-item', activeTab === '目录' ? 'active' : '']" @click="activeTab = '目录'">目录</text>
  19. <text :class="['tab-item', activeTab === '介绍' ? 'active' : '']" @click="activeTab = '介绍'">介绍</text>
  20. <text :class="['tab-item', activeTab === '评论' ? 'active' : '']" @click="activeTab = '评论'">评论</text>
  21. <text :class="['tab-item', activeTab === '考试' ? 'active' : '']" @click="activeTab = '考试'">考试</text>
  22. </view>
  23. <!-- 目录内容 -->
  24. <view v-if="activeTab == '目录'" class="course-content">
  25. <catalogue ref="catalogueRef" @kejianInfo='getKejianInfo' :options="kejianUserVo"
  26. :current-video="currentVideo"></catalogue>
  27. </view>
  28. <view v-if="activeTab == '介绍'" class="course-content">
  29. <view v-if="!kechengData.intro" class="s-kehceng-default">
  30. <view>
  31. <img :src="jieshaoImg">
  32. <text>还没有介绍</text>
  33. </view>
  34. </view>
  35. <view v-else v-html="kechengData.intro" class="kecheng-tab-jieshao"></view>
  36. </view>
  37. <view v-if="activeTab == '评论'" class="course-content">
  38. <view v-if="!kechengData.intro" class="s-kehceng-default">
  39. <view>
  40. <text>还没有介绍</text>
  41. </view>
  42. </view>
  43. <view v-else v-html="kechengData.intro" class="kecheng-tab-jieshao"></view>
  44. </view>
  45. </view>
  46. </template>
  47. <script setup>
  48. import {
  49. ref,
  50. onMounted
  51. } from 'vue';
  52. import {
  53. onLoad,
  54. onReady,
  55. } from "@dcloudio/uni-app"
  56. import {
  57. kechengStart
  58. } from "@/api/course.js";
  59. import catalogue from './common/catalogue.vue';
  60. // 选项卡状态
  61. const activeTab = ref('');
  62. let kcId = ref('');
  63. let kejianUserVo = ref(null);
  64. let kechengData = ref(null);
  65. // 当前播放信息
  66. const currentVideo = ref({
  67. url: '',
  68. kjId: ''
  69. });
  70. const currentChapter = ref(0);
  71. const currentSection = ref(0);
  72. const catalogueRef = ref(null);
  73. const videoId = ref('courseVideo');
  74. let videoContext = null;
  75. onLoad((options) => {
  76. console.log('options', options);
  77. kcId.value = options.kcId
  78. });
  79. onMounted(() => {
  80. getKechengData()
  81. });
  82. function getKechengData() {
  83. kechengStart({
  84. kcId: kcId.value
  85. }).then(res => {
  86. console.log('res', res);
  87. activeTab.value = '目录'
  88. kejianUserVo.value = res.data.kejianUserVo
  89. kechengData.value = res.data
  90. })
  91. }
  92. function getKejianInfo(data) {
  93. console.log('data', data.url);
  94. currentVideo.value = {
  95. url: data.url,
  96. kjId: data.kjId
  97. };
  98. setTimeout(() => {
  99. if (!videoContext) {
  100. videoContext = uni.createVideoContext(videoId.value, this);
  101. }
  102. const cachedTime = uni.getStorageSync(`video_${data.kjId}`) || 0;
  103. videoContext.seek(cachedTime);
  104. }, 300);
  105. }
  106. const handleTimeUpdate = (e) => {
  107. const currentTime = e.detail.currentTime;
  108. uni.setStorageSync(`video_${currentVideo.value.kjId}`, currentTime);
  109. };
  110. const handleVideoEnd = () => {
  111. catalogueRef.value.playNextVideo();
  112. };
  113. const handleVideoLoaded = (e) => {
  114. uni.setStorageSync(`duration_${currentVideo.value.kjId}`, e.detail.duration);
  115. };
  116. </script>
  117. <style scoped>
  118. .course-container {
  119. display: flex;
  120. flex-direction: column;
  121. height: 100vh;
  122. }
  123. .course-header {
  124. padding: 20rpx;
  125. background: #f5f5f5;
  126. }
  127. .course-title {
  128. font-size: 36rpx;
  129. font-weight: bold;
  130. }
  131. .course-meta {
  132. margin-top: 10rpx;
  133. font-size: 24rpx;
  134. color: #666;
  135. }
  136. .course-tabs {
  137. display: flex;
  138. justify-content: space-around;
  139. padding: 20rpx;
  140. background: #fff;
  141. border-bottom: 1rpx solid #ddd;
  142. }
  143. .tab-item {
  144. font-size: 28rpx;
  145. color: #666;
  146. }
  147. .tab-item.active {
  148. color: #09BB07;
  149. font-weight: bold;
  150. }
  151. .course-content {
  152. flex: 1;
  153. overflow-y: auto;
  154. padding: 20rpx;
  155. }
  156. .chapter-list {
  157. background: #fff;
  158. }
  159. .chapter-item {
  160. margin-bottom: 20rpx;
  161. }
  162. .chapter-title {
  163. padding: 20rpx;
  164. background: #f5f5f5;
  165. display: flex;
  166. justify-content: space-between;
  167. border-bottom: 1rpx solid #ddd;
  168. }
  169. .section-list {
  170. background: #fff;
  171. }
  172. .section-item {
  173. padding: 20rpx;
  174. display: flex;
  175. justify-content: space-between;
  176. border-bottom: 1rpx solid #eee;
  177. }
  178. .section-info {
  179. flex: 1;
  180. }
  181. .section-title {
  182. display: block;
  183. font-size: 28rpx;
  184. color: #333;
  185. }
  186. .play-status {
  187. width: 180rpx;
  188. text-align: right;
  189. }
  190. .playing {
  191. color: #09BB07;
  192. font-size: 24rpx;
  193. }
  194. .progress {
  195. color: #666;
  196. font-size: 24rpx;
  197. }
  198. .unplayed {
  199. color: #999;
  200. font-size: 24rpx;
  201. }
  202. video {
  203. width: 100%;
  204. height: 300rpx;
  205. background: #000;
  206. }
  207. </style>