list.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <view class="wrap">
  3. <!-- #ifdef MP-WEIXIN -->
  4. <u-navbar title-color="#000000" :is-back="fasle" title="视频列表"></u-navbar>
  5. <!-- #endif -->
  6. <u-waterfall v-model="flowList" ref="uWaterfall" style="margin-top: 10rpx;">
  7. <template v-slot:left="{leftList}">
  8. <view class="demo-warter" v-for="(item, index) in leftList" :key="index">
  9. <video v-show='item.$index==indexCurrent' :src="item.videoUrl" autoplay :id="'myVideo'+item.$index"></video>
  10. <u-lazy-load v-show='item.$index!=indexCurrent' border-radius="10" :image="item.imageUrl" :index="index" @click="videoPlay(item.$index)"></u-lazy-load>
  11. <u-icon v-show='item.$index!=indexCurrent' class="video-play" color="#fff" size="50" name="play-circle" @click="videoPlay(item.$index)"></u-icon>
  12. </view>
  13. </template>
  14. <template v-slot:right="{rightList}">
  15. <view class="demo-warter" v-for="(item, index) in rightList" :key="index">
  16. <video v-show='item.$index==indexCurrent' :src="item.videoUrl" autoplay :id="'myVideo'+item.$index"></video>
  17. <u-lazy-load v-show='item.$index!=indexCurrent' border-radius="10" :image="item.imageUrl" :index="index" @click="videoPlay(item.$index)"></u-lazy-load>
  18. <u-icon v-show='item.$index!=indexCurrent' class="video-play" color="#fff" size="50" name="play-circle" @click="videoPlay(item.$index)"></u-icon>
  19. </view>
  20. </template>
  21. </u-waterfall>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. data() {
  27. return {
  28. flowList: [],
  29. indexCurrent: null
  30. }
  31. },
  32. async onLoad() {
  33. let params = {
  34. activeId: this.vuex_active_setting.defaultActiveId,
  35. platformSettingEnum: 'ACTIVE_SETTING' ,
  36. }
  37. this.flowList = JSON.parse((await this.$api.platform.getPlatformValue(params)).data.data).learnVideo;
  38. },
  39. methods: {
  40. videoPlay(index){
  41. let curIdx = index;
  42. // 有播放时先将prev暂停,再播放当前点击的current
  43. if (this.indexCurrent != null) {
  44. let videoContextPrev = uni.createVideoContext('myVideo' + this.indexCurrent)
  45. if (this.indexCurrent != curIdx) {
  46. videoContextPrev.pause()
  47. }
  48. this.indexCurrent = curIdx;
  49. let videoContextCurrent = uni.createVideoContext('myVideo' + curIdx)
  50. videoContextCurrent.play()
  51. } else { // 没有播放时播放视频
  52. this.indexCurrent = curIdx
  53. let videoContext = uni.createVideoContext('myVideo' + curIdx) //这里对应的视频id
  54. videoContext.play()
  55. }
  56. },
  57. }
  58. }
  59. </script>
  60. <style lang="scss" scoped>
  61. .demo-warter {
  62. border-radius: 8px;
  63. margin: 5px;
  64. background-color: #ffffff;
  65. padding: 8px;
  66. position: relative;
  67. .video-play{
  68. position: absolute;
  69. bottom: 20rpx;
  70. left: 20rpx;
  71. }
  72. }
  73. video, image{
  74. width: 330rpx;
  75. max-height: 330rpx;
  76. }
  77. </style>