studydetails.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <view class="">
  3. <!-- <u-navbar
  4. :title="title"
  5. :placeholder="true"
  6. :autoBack="true"
  7. :safeAreaInsetTop="true"
  8. >
  9. </u-navbar> -->
  10. <view class="page-wrap">
  11. <view class="base-info">
  12. <view class="title">{{pageData.title}}</view>
  13. <view class="info u-flex u-row-between">
  14. <view class="time">{{pageData.createTime}}</view>
  15. <view class="view-count">{{pageData.studyUserNum}}人已学</view>
  16. </view>
  17. </view>
  18. <view class="content-wrap">
  19. <view class="content" v-if="pageData.libType!=2">
  20. <u-parse :content="pageData.content"></u-parse>
  21. </view>
  22. <view class="video-wrap" v-else>
  23. <video
  24. id="myVideo" :src="pageData.videoUrl"
  25. @error="videoErrorCallback"
  26. :show-fullscreen-btn="true"
  27. @timeupdate="timeupdate"
  28. @ended="ended"
  29. :initial-time="initial_time"
  30. @loadedmetadata="loadedmetadata"
  31. :controls="true">
  32. </video>
  33. <view class="video-tip">{{videoTip}}</view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. export default{
  41. data(){
  42. return{
  43. pageHeight:null,
  44. windowTop:null,
  45. windowHeight:null,
  46. scrollHeight:null,
  47. title:'详情',
  48. id:null,
  49. type:'',
  50. pageData:{
  51. title:'',
  52. content:''
  53. },
  54. swiperDetails:{},
  55. // 视频创建dom
  56. videoContext: uni.createVideoContext('myVideo', this),
  57. // 视频已经播放时间
  58. playedTime: 0,
  59. // 视频总时长
  60. duration: 0,
  61. // 视频实时时间
  62. initial_time:0,
  63. // 视频实际时间
  64. video_real_time: 0,
  65. // 视频总时长
  66. duration: 0,
  67. // 当前视频选中播放
  68. currentDuration: 0,
  69. // 视频信息
  70. videoInfo: {},
  71. hasAddView:false,
  72. videoTip:'请完整学习视频!(未完成)'
  73. }
  74. },
  75. onLoad(page) {
  76. this.id = page.id;
  77. this.getDetails(this.id);
  78. },
  79. onReady(){
  80. this.windowTop = uni.getSystemInfoSync().windowTop;
  81. this.windowHeight = uni.getSystemInfoSync().windowHeight;
  82. this.pageHeight = this.windowTop + this.windowHeight;
  83. this.scrollHeight = document.documentElement.scrollHeight;
  84. // console.log('this.pageHeight',this.pageHeight);
  85. // console.log('this.scrollHeight',this.scrollHeight);
  86. if(this.scrollHeight>this.pageHeight){
  87. console.log('有滚动条');
  88. }else{
  89. console.log('没有滚动条');
  90. }
  91. },
  92. // 在 onPageScroll 监听函数中监听滚动事件
  93. onPageScroll(e) {
  94. // console.log('onPageScroll',e);
  95. // console.log('this.pageHeight',this.pageHeight);
  96. // console.log('this.scrollHeight',this.scrollHeight);
  97. // console.log('document.body.scrollTop',document.body.scrollTop);
  98. // 如果页面滚动到底部,则执行相应的操作
  99. if (e.scrollTop + this.windowHeight >= this.scrollHeight) {
  100. console.log('页面滚动到底部');
  101. // 执行操作
  102. }
  103. },
  104. beforeDestroy() {
  105. if(this.pageData.libType==2){
  106. console.log('hasAddView',this.hasAddView);
  107. }
  108. },
  109. methods:{
  110. getDetails(id){
  111. this.$u.api.courseDetails({id:id}).then(res=>{
  112. this.pageData = res.data;
  113. if(this.pageData.libType!=2){
  114. this.addViewCount(this.id)
  115. }
  116. // console.log('res',res);
  117. }).catch(err=>{
  118. console.log('courseDetails',err.data);
  119. })
  120. },
  121. addViewCount(id){
  122. this.$u.api.addViewCount({id:id}, { custom: { noload: true } }).then(res=>{
  123. this.videoTip = '请完整学习视频!(已完成)';
  124. // console.log('res',res);
  125. }).catch(err=>{
  126. console.log('addViewCount',err.data);
  127. })
  128. },
  129. timeupdate(e){
  130. // console.log('timeupdate',e.detail);
  131. //播放的总时长
  132. let duration = e.detail.duration;
  133. //实时播放进度 秒数
  134. let jumpTime = parseInt(e.detail.currentTime);
  135. //当前视频进度
  136. if (jumpTime - this.playedTime > 3) {
  137. // 差别过大,调用seek方法跳转到实际观看时间
  138. this.videoContext.seek(this.playedTime);
  139. wx.showToast({
  140. title: '未完整看完该视频,不能快进',
  141. icon: 'none',
  142. duration: 2000
  143. });
  144. } else {
  145. this.video_real_time = parseInt(e.detail.currentTime);
  146. this.currentDuration = e.detail.currentTime;
  147. if (this.video_real_time > this.playedTime) {
  148. this.playedTime = this.video_real_time;
  149. }
  150. }
  151. // console.log('playedTime',this.playedTime);
  152. // console.log('duration',parseInt(duration));
  153. // 距离播放完成多少秒算看完,并调用接口
  154. if(parseInt(duration)-this.playedTime==5&&this.hasAddView==false){
  155. // console.log('看完了');
  156. this.hasAddView = true;
  157. this.addViewCount(this.id)
  158. }
  159. },
  160. loadedmetadata(data) {
  161. this.duration = data.detail.duration;
  162. },
  163. ended() {
  164. // 用户把进度条拉到最后,但是实际观看时间不够,跳转回去会自动暂停。
  165. // 这里加个判断。
  166. if (this.videoUrl) {
  167. this.$emit(
  168. 'recordDuration',
  169. { playDuration: this.playedTime, duration: this.duration, currentDuration: this.currentDuration },
  170. this.videoIndex,
  171. true
  172. );
  173. }
  174. }
  175. }
  176. }
  177. </script>
  178. <style>
  179. page{background-color: #F5F9FC;}
  180. </style>
  181. <style lang="scss" scoped>
  182. .title{
  183. font-size: 36rpx;
  184. font-weight: 600;
  185. color: #333333;
  186. line-height: 50rpx;
  187. margin-bottom: 20rpx;
  188. text-align: center;
  189. }
  190. .info{
  191. margin-bottom: 50rpx;
  192. font-size: 24rpx;
  193. font-weight: 400;
  194. color: #999999;
  195. line-height: 33rpx;
  196. }
  197. .page-wrap{
  198. font-size: 26rpx;
  199. font-weight: 400;
  200. color: #666666;
  201. line-height: 44rpx;
  202. p{
  203. text-indent: 2em;
  204. }
  205. /deep/ .u-image{
  206. margin-bottom: 20rpx;
  207. }
  208. }
  209. .content{
  210. font-size: 26rpx;
  211. font-weight: 400;
  212. color: #666666;
  213. line-height: 44rpx;
  214. margin: 20rpx 0;
  215. }
  216. .u-image{
  217. max-width: 100%;
  218. }
  219. .video-wrap{
  220. video{
  221. width:100%;
  222. }
  223. .video-tip{
  224. text-align: center;
  225. margin: 20rpx;
  226. }
  227. }
  228. </style>