courseDetail.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <view class="courseDetail">
  3. <video class="video" show-mute-btn enable-play-gesture page-gesture show-progress show-fullscreen-btn show-play-btn enable-progress-gesture :src="info.chapters[current].chapterUrl" :autoplay="autoplay" controls @ended="onEnd"></video>
  4. <view class="content">
  5. <view class="tab-box">
  6. <view class="tab" :class="[tab == 0?'active':'']" @click="handleTab(0)">
  7. 简介
  8. </view>
  9. <view class="tab" :class="[tab == 1?'active':'']" @click="handleTab(1)">
  10. 章节
  11. </view>
  12. </view>
  13. <view class="video-title">
  14. {{info.courseName}}
  15. </view>
  16. <view class="type-box">
  17. <!-- <view class="type">
  18. 天文课程-天眼
  19. </view> -->
  20. <view class="times">
  21. {{info.chapters[current].viewedCount}}次播放
  22. </view>
  23. </view>
  24. <view class="intro" v-show="tab == 0">
  25. <view class="intro-title">
  26. 课程简介
  27. </view>
  28. <view class="desc">
  29. {{info.courseMsg}}
  30. </view>
  31. </view>
  32. <!-- 章节 -->
  33. <view class="catalogue" v-show="tab == 1">
  34. <view class="item" v-for="(item,index) in info.chapters" :key="index" @click="handleItem(item,index)">
  35. <view class="num" :class="[current == index?'active':'']">
  36. {{index+1<10?'0'+(index+1):index+1}}
  37. </view>
  38. <view class="video-info">
  39. <view class="title" :class="[current == index?'active':'']">
  40. {{item.chapterName}}
  41. </view>
  42. <!-- <view class="info">
  43. <view class="icon-box">
  44. <image class="icon" src="../static/study/time.png" mode=""></image>
  45. <view class="text">
  46. 09:05
  47. </view>
  48. </view>
  49. <view class="icon-box">
  50. <image class="icon" src="../static/study/play-icon.png" mode=""></image>
  51. <view class="text">
  52. 09:05
  53. </view>
  54. </view>
  55. </view> -->
  56. </view>
  57. <image class="btn" :src="current == index?playIng:playBtn" mode=""></image>
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. import {videoDetail,coursePlayLog} from '@/api/study.js'
  65. export default {
  66. data() {
  67. return {
  68. tab:0,
  69. current:0,
  70. autoplay:true,
  71. id:null,
  72. info:{
  73. chapters:[],
  74. columnId:0,
  75. courseImg:'',
  76. id:0,
  77. courseMsg:'',
  78. courseName:''
  79. },
  80. // list:[
  81. // {
  82. // title:'火箭发射',
  83. // times:'09:05',
  84. // playTimes:'1.9万',
  85. // video:'https://sns-video-bd.xhscdn.com/spectrum/01e2e095923d542a01837003823d55acab_259.mp4',
  86. // poster: 'https://gimg4.baidu.com/poster/src=http%3A%2F%2Ft15.baidu.com%2Fit%2Fu%3D4149304328%2C1810644736%26fm%3D225%26app%3D113%26f%3DJPEG%3Fw%3D1499%26h%3D843%26s%3D3352508488112DED7E265C1B03007098&refer=http%3A%2F%2Fwww.baidu.com&app=2004&size=f352,234&n=0&g=0n&q=100?sec=1703215065&t=01d1ccc946fc2cc3600627e2e1aac47f',
  87. // },
  88. // {
  89. // title:'星舰发射',
  90. // times:'09:05',
  91. // playTimes:'1.9万',
  92. // video:'http://flv0.bn.netease.com/00756cf0f624a4622e55ac120cfede7958e925f6eb2ac9a492d01cb163db2ba56e195feabfe3f2c361b91f26fbd86a4969bc4a9669f3e30eeb29cf18d8b8a4fe7727b72ddf34ad1a01d1502ca790f0f7fa40c55400983658284e046bafa6f501687a85211cd279686a278559e76f2a2b36321394c90916b4.mp4',
  93. // poster:'https://nimg.ws.126.net/?url=http%3A%2F%2Fvideoimg.ws.126.net%2Fcover%2F20231221%2FVBtFr5Y9x_cover.jpg&thumbnail=750x2147483647&quality=75&type=jpg',
  94. // }
  95. // ],
  96. playBtn:require('@/static/study/play-btn.png'),
  97. playIng:require('@/static/study/playing.png'),
  98. }
  99. },
  100. methods: {
  101. // 视频播放结束
  102. onEnd(){
  103. if(this.current != this.info.chapters.length-1){
  104. this.current ++
  105. this.addViewCount()
  106. }
  107. },
  108. handleTab(tab){
  109. this.tab = tab
  110. },
  111. handleItem(item,index){
  112. this.current = index
  113. this.addViewCount()
  114. },
  115. videoDetail(id){
  116. videoDetail({id}).then(res=>{
  117. if(res.state == 'Success'){
  118. this.info = res.content
  119. }
  120. })
  121. },
  122. addViewCount(){
  123. setTimeout(() => {
  124. const userInfo = JSON.parse(uni.getStorageSync('userInfo'))
  125. coursePlayLog({
  126. userId:userInfo.userId,
  127. courseId:this.id,
  128. chapterId:this.info.chapters[this.current].id
  129. })
  130. }, 1000);
  131. }
  132. },
  133. onLoad(options) {
  134. this.id = options.id
  135. this.videoDetail(options.id)
  136. this.addViewCount()
  137. }
  138. }
  139. </script>
  140. <style lang="scss" scoped>
  141. .courseDetail{
  142. .video{
  143. width: 100%;
  144. height: 420rpx;
  145. }
  146. .content{
  147. padding: 0 30rpx;
  148. .tab-box{
  149. display: flex;
  150. color: #222222;
  151. font-size: 28rpx;
  152. border-bottom: 1rpx solid #F0F0F0;
  153. .tab{
  154. flex: 1;
  155. padding: 20rpx 0;
  156. text-align: center;
  157. }
  158. .tab.active{
  159. font-weight: bold;
  160. position: relative;
  161. &::after{
  162. content: '';
  163. width: 40rpx;
  164. height: 8rpx;
  165. border-radius: 4rpx;
  166. background: #3879F9;
  167. position: absolute;
  168. bottom: 0%;
  169. left: 50%;
  170. transform: translateX(-50%);
  171. }
  172. }
  173. }
  174. .video-title{
  175. width: 100%;
  176. font-size: 32rpx;
  177. font-weight: bold;
  178. color: #222222;
  179. margin-top: 24rpx;
  180. display: -webkit-box;
  181. -webkit-box-orient: vertical;
  182. -webkit-line-clamp: 2; /* 显示的最大行数 */
  183. overflow: hidden;
  184. }
  185. .type-box{
  186. display: flex;
  187. justify-content: space-between;
  188. align-items: center;
  189. color: #AAAAAA;
  190. font-size: 24rpx;
  191. padding: 28rpx 0;
  192. border-bottom: 1rpx solid #F0F0F0;
  193. }
  194. .intro{
  195. .intro-title{
  196. margin: 24rpx 0;
  197. font-weight: bold;
  198. color: #222222;
  199. font-size: 28rpx;
  200. }
  201. .desc{
  202. font-size: 24rpx;
  203. font-weight: 400;
  204. color: #222222;
  205. line-height: 40rpx;
  206. }
  207. }
  208. .catalogue{
  209. .item{
  210. display: flex;
  211. align-items: center;
  212. padding: 20rpx 0;
  213. border-bottom: 1rpx solid #F0F0F0;
  214. .num.active{
  215. color: #3879F9;
  216. }
  217. .num{
  218. font-size: 28rpx;
  219. font-weight: bold;
  220. color: #AAAAAA;
  221. }
  222. .video-info{
  223. flex: 1;
  224. margin-left: 18rpx;
  225. .title.active{
  226. color: #3879F9;
  227. }
  228. .title{
  229. font-weight: bold;
  230. color: #333333;
  231. font-size: 28rpx;
  232. }
  233. .info{
  234. display: flex;
  235. align-items: center;
  236. margin-top: 12rpx;
  237. .icon-box{
  238. display: flex;
  239. align-items: flex-end;
  240. font-size: 24rpx;
  241. color: #AAAAAA;
  242. margin-right: 36rpx;
  243. .icon{
  244. width: 28rpx;
  245. height: 28rpx;
  246. }
  247. .text{
  248. margin-left: 6rpx;
  249. }
  250. }
  251. }
  252. }
  253. .btn{
  254. width: 40rpx;
  255. height: 40rpx;
  256. }
  257. }
  258. }
  259. }
  260. }
  261. </style>