modeVideo.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <view class="container">
  3. <u-list @scrolltolower="scrolltolower" class="notice-ul" height="100%">
  4. <u-list-item v-for="(video, index) in videoList" :key="video.id">
  5. <view class="video">
  6. <video :src="playerURL(video.url)" controls :id="video.id" :data-id="video.id" :title="video.name" @play="videoPlay" :type="video.type"></video>
  7. <view class="info">{{video.name}}</view>
  8. </view>
  9. </u-list-item>
  10. <u-list-item v-if="textShow">
  11. <view style="text-align: center;margin-bottom: 30rpx;">
  12. 已加载全部
  13. </view>
  14. </u-list-item>
  15. </u-list>
  16. </view>
  17. </template>
  18. <script>
  19. import { demoVideo, playerVideo } from '@/api/visitor.js'
  20. export default {
  21. data() {
  22. return {
  23. page: 1,
  24. total:0,
  25. pageSize:10,
  26. textShow:false,
  27. videoList: []
  28. };
  29. },
  30. methods: {
  31. scrolltolower(){
  32. if(Math.ceil(this.total/this.pageSize)<this.page){
  33. return;
  34. }else if(Math.ceil(this.total/this.pageSize)>=this.page){
  35. this.getDemoVideo(this.page,this.pageSize)
  36. }
  37. },
  38. getDemoVideo(x, y) {
  39. const that = this
  40. uni.showLoading({
  41. icon:"none",
  42. title:"记载中"
  43. })
  44. try{
  45. demoVideo(x, y).then(res => {
  46. uni.hideLoading()
  47. if (res.data.rows) {
  48. if(that.page===1){
  49. that.videoList = res.data.rows
  50. }else{
  51. that.videoList = [...that.videoList,...res.data.rows]
  52. }
  53. that.total = res.data.total
  54. that.page = that.page +1
  55. if(Math.ceil(that.total/that.pageSize)<that.page){
  56. that.textShow = true
  57. }else{
  58. that.textShow = false
  59. }
  60. }
  61. })
  62. }catch(err){
  63. uni.hideLoading()
  64. }
  65. },
  66. playerURL(url) {
  67. return playerVideo(url)
  68. },
  69. videoPlay(e) {
  70. // 获取当前视频id
  71. let currentId = e.currentTarget.dataset.id;
  72. // uni.createVideoContext获取视频上下文对象
  73. this.videoContent = uni.createVideoContext(currentId);
  74. // 获取json对象并遍历, 停止非当前视频
  75. let videoList = this.videoList;
  76. for (let i = 0; i < videoList.length; i++) {
  77. let temp = videoList[i].id;
  78. if (temp !== currentId) {
  79. uni.createVideoContext(temp).pause();
  80. }
  81. }
  82. }
  83. },
  84. onLoad() {
  85. this.getDemoVideo(1, this.pageSize)
  86. }
  87. }
  88. </script>
  89. <style lang="less">
  90. .video {
  91. text-align: center;
  92. // box-shadow: rgba(0, 0, 0, 0.45) 0px 25px 20px -20px;
  93. box-shadow: rgba(17, 17, 26, 0.1) 0px 1px 0px;
  94. margin-bottom: 50rpx;
  95. &:last-child {
  96. margin-bottom: 20rpx;
  97. }
  98. .info {
  99. padding: 10rpx;
  100. }
  101. }
  102. </style>