courseDetail.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <view class="courseDetail">
  3. <video id="courseVideo" class="video" show-mute-btn enable-play-gesture page-gesture show-progress
  4. show-fullscreen-btn show-play-btn enable-progress-gesture :src="info.courseGoodsDto.chapterUrl"
  5. :autoplay="autoplay" controls @timeupdate="videoTimeUpdateEvent" @ended="onEnd">
  6. </video>
  7. <view class="content">
  8. <view class="tab-box">
  9. <view class="tab" :class="[tab == 0 ? 'active' : '']" @click="handleTab(0)">
  10. 简介
  11. </view>
  12. <view class="tab" :class="[tab == 1 ? 'active' : '']" @click="handleTab(1)">
  13. 章节
  14. </view>
  15. </view>
  16. <view class="video-title">
  17. {{ info.courseGoodsDto.courseName }}
  18. </view>
  19. <view class="type-box">
  20. <view class="type">
  21. 课程:{{ info.goodsName }}
  22. </view>
  23. <view class="times">
  24. 10465次播放
  25. </view>
  26. </view>
  27. <view class="intro" v-show="tab == 0">
  28. <view class="intro-title">
  29. 课程简介
  30. </view>
  31. <view class="desc">
  32. {{ info.courseGoodsDto.courseMsg }}
  33. </view>
  34. </view>
  35. <!-- 章节 -->
  36. <view class="catalogue" v-show="tab == 1">
  37. <view class="item" v-for="(item, index) in info.courses" :key="index" @click="handleItem(item, index)">
  38. <view class="num" :class="[current == index ? 'active' : '']">
  39. {{ index + 1 < 10 ? '0' + (index + 1) : index + 1 }} </view>
  40. <view class="video-info">
  41. <view class="title" :class="[current == index ? 'active' : '']">
  42. {{ item.courseName }}
  43. </view>
  44. <view class="info">
  45. <view class="icon-box">
  46. <image class="icon" src="../static/study/time.png" mode=""></image>
  47. <view class="text">
  48. 09:05
  49. </view>
  50. </view>
  51. <view class="icon-box">
  52. <image class="icon" src="../static/study/play-icon.png" mode=""></image>
  53. <view class="text">
  54. 09:05
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. <image class="btn" :src="current == index ? playIng : playBtn" mode=""></image>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import { getCourseDetail, updatePer } from '@/api/study.js'
  67. export default {
  68. data() {
  69. return {
  70. tab: 0,
  71. current: 0,
  72. autoplay: true,
  73. info: {
  74. chapters: [],
  75. columnId: 0,
  76. courseImg: '',
  77. id: 0,
  78. courseMsg: '',
  79. courseName: ''
  80. },
  81. goods: {},
  82. videoContext: {},
  83. query: {},
  84. timmer: null,
  85. per: 0,
  86. // list:[
  87. // {
  88. // title:'火箭发射',
  89. // times:'09:05',
  90. // playTimes:'1.9万',
  91. // video:'https://sns-video-bd.xhscdn.com/spectrum/01e2e095923d542a01837003823d55acab_259.mp4',
  92. // 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',
  93. // },
  94. // {
  95. // title:'星舰发射',
  96. // times:'09:05',
  97. // playTimes:'1.9万',
  98. // video:'http://flv0.bn.netease.com/00756cf0f624a4622e55ac120cfede7958e925f6eb2ac9a492d01cb163db2ba56e195feabfe3f2c361b91f26fbd86a4969bc4a9669f3e30eeb29cf18d8b8a4fe7727b72ddf34ad1a01d1502ca790f0f7fa40c55400983658284e046bafa6f501687a85211cd279686a278559e76f2a2b36321394c90916b4.mp4',
  99. // 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',
  100. // }
  101. // ],
  102. playBtn: require('@/static/study/play-btn.png'),
  103. playIng: require('@/static/study/playing.png'),
  104. }
  105. },
  106. methods: {
  107. // 视频播放结束
  108. onEnd() {
  109. if (this.current != this.info.chapters.length - 1) {
  110. this.current++
  111. }
  112. },
  113. handleTab(tab) {
  114. this.tab = tab
  115. },
  116. handleItem(item, index) {
  117. this.current = index
  118. this.info.courseGoodsDto = item
  119. this.videoContext.play()
  120. },
  121. videoDetail(query) {
  122. this.query = {
  123. dataId: query.id,
  124. orderNo: query.orderNo
  125. }
  126. getCourseDetail(query).then(res => {
  127. if (res.state == 'Success') {
  128. this.info = res.content
  129. }
  130. })
  131. },
  132. videoTimeUpdateEvent(e) { // 播放进度改变
  133. //当前进度
  134. let currentTime = parseInt(e.detail.currentTime);
  135. //总进度
  136. let duration = parseInt(e.detail.duration);
  137. const per = ((currentTime / duration) * 100).toFixed()
  138. if (per % 5 == 0 && per != this.per) {
  139. this.per = per
  140. // console.log('上报进度')
  141. updatePer({
  142. ...this.query,
  143. per
  144. }).then(res => {
  145. console.log(res)
  146. })
  147. }
  148. // console.log('当前进度:', currentTime, '总进度:', duration,'比例:',per);
  149. },
  150. },
  151. onLoad(options) {
  152. this.videoDetail({
  153. id: options.id,
  154. orderNo: options.orderNo
  155. })
  156. this.videoContext = uni.createVideoContext('courseVideo');
  157. }
  158. }
  159. </script>
  160. <style lang="scss" scoped>
  161. .courseDetail {
  162. .video {
  163. width: 100%;
  164. height: 420rpx;
  165. }
  166. .content {
  167. padding: 0 30rpx;
  168. .tab-box {
  169. display: flex;
  170. color: #222222;
  171. font-size: 28rpx;
  172. border-bottom: 1rpx solid #F0F0F0;
  173. .tab {
  174. flex: 1;
  175. padding: 20rpx 0;
  176. text-align: center;
  177. }
  178. .tab.active {
  179. font-weight: bold;
  180. position: relative;
  181. &::after {
  182. content: '';
  183. width: 40rpx;
  184. height: 8rpx;
  185. border-radius: 4rpx;
  186. background: #3879F9;
  187. position: absolute;
  188. bottom: 0%;
  189. left: 50%;
  190. transform: translateX(-50%);
  191. }
  192. }
  193. }
  194. .video-title {
  195. width: 100%;
  196. font-size: 32rpx;
  197. font-weight: bold;
  198. color: #222222;
  199. margin-top: 24rpx;
  200. display: -webkit-box;
  201. -webkit-box-orient: vertical;
  202. -webkit-line-clamp: 2;
  203. /* 显示的最大行数 */
  204. overflow: hidden;
  205. }
  206. .type-box {
  207. display: flex;
  208. justify-content: space-between;
  209. align-items: center;
  210. color: #AAAAAA;
  211. font-size: 24rpx;
  212. padding: 28rpx 0;
  213. border-bottom: 1rpx solid #F0F0F0;
  214. }
  215. .intro {
  216. .intro-title {
  217. margin: 24rpx 0;
  218. font-weight: bold;
  219. color: #222222;
  220. font-size: 28rpx;
  221. }
  222. .desc {
  223. font-size: 24rpx;
  224. font-weight: 400;
  225. color: #222222;
  226. line-height: 40rpx;
  227. }
  228. }
  229. .catalogue {
  230. .item {
  231. display: flex;
  232. align-items: center;
  233. padding: 20rpx 0;
  234. border-bottom: 1rpx solid #F0F0F0;
  235. .num.active {
  236. color: #3879F9;
  237. }
  238. .num {
  239. font-size: 28rpx;
  240. font-weight: bold;
  241. color: #AAAAAA;
  242. }
  243. .video-info {
  244. flex: 1;
  245. margin-left: 18rpx;
  246. .title.active {
  247. color: #3879F9;
  248. }
  249. .title {
  250. font-weight: bold;
  251. color: #333333;
  252. font-size: 28rpx;
  253. }
  254. .info {
  255. display: flex;
  256. align-items: center;
  257. margin-top: 12rpx;
  258. .icon-box {
  259. display: flex;
  260. align-items: flex-end;
  261. font-size: 24rpx;
  262. color: #AAAAAA;
  263. margin-right: 36rpx;
  264. .icon {
  265. width: 28rpx;
  266. height: 28rpx;
  267. }
  268. .text {
  269. margin-left: 6rpx;
  270. }
  271. }
  272. }
  273. }
  274. .btn {
  275. width: 40rpx;
  276. height: 40rpx;
  277. }
  278. }
  279. }
  280. }
  281. }
  282. </style>