index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <!-- <view class='product-bg'>
  3. <swiper :indicator-dots="indicatorDots"
  4. :autoplay="autoplay" :circular="circular" :interval="interval" :duration="duration" @change="change">
  5. <block v-for="(item,index) in imgUrls" :key="index">
  6. <swiper-item>
  7. <image :src="item" class="slide-image"/>
  8. </swiper-item>
  9. </block>
  10. </swiper>
  11. <view class='pages'>{{currents}}/{{imgUrls.length || 1}}</view>
  12. </view> -->
  13. <view class='product-bg'>
  14. <swiper :indicator-dots="indicatorDots" indicator-active-color="#e93323" :autoplay="autoplay" :circular="circular"
  15. :interval="interval" :duration="duration" @change="change">
  16. <swiper-item v-if="videoline && videoline != '' && videoline != 'https:'">
  17. <view class="item">
  18. <video id="myVideo" :src='videoline && (videoline.substring(0,4) == "http" || videoline.substring(0,5) == "https") ? videoline : "http:" + videoline'
  19. objectFit="cover" controls style="width:100%;height:100% " show-center-play-btn show-mute-btn="true"
  20. auto-pause-if-navigate :custom-cache="false"></video>
  21. <view class="poster" v-if="controls">
  22. <image class="image" :src="videoCoverImg"></image>
  23. </view>
  24. <view class="stop" v-if="controls" @tap="bindPause">
  25. <image class="image" src="../../static/images/stop.png"></image>
  26. </view>
  27. </view>
  28. </swiper-item>
  29. <block v-for="(item,index) in imgUrls" :key='index'>
  30. <swiper-item>
  31. <image :src="item" class="slide-image" />
  32. </swiper-item>
  33. </block>
  34. </swiper>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. props: {
  40. imgUrls: {
  41. type: Array,
  42. default: function() {
  43. return [];
  44. }
  45. },
  46. videoline: {
  47. type: String,
  48. value: ""
  49. },
  50. videoCoverImg: {
  51. type: String,
  52. }
  53. },
  54. data() {
  55. return {
  56. indicatorDots: true,
  57. circular: true,
  58. autoplay: true,
  59. interval: 5000,
  60. duration: 500,
  61. currents: "1",
  62. controls: true
  63. };
  64. },
  65. created() {
  66. },
  67. watch: {
  68. },
  69. mounted() {
  70. console.log(this.videoline)
  71. this.videoContext = uni.createVideoContext('myVideo', this);
  72. },
  73. methods: {
  74. bindPause: function() {
  75. this.videoContext.play();
  76. this.$set(this, 'controls', false)
  77. this.$set(this, 'autoplay', false)
  78. },
  79. change: function(e) {
  80. this.$set(this, 'currents', e.detail.current + 1);
  81. }
  82. }
  83. }
  84. </script>
  85. <style scoped lang="scss">
  86. .product-bg {
  87. width: 100%;
  88. height: 750rpx;
  89. position: relative;
  90. }
  91. .product-bg swiper {
  92. width: 100%;
  93. height: 100%;
  94. position: relative;
  95. }
  96. .product-bg .slide-image {
  97. width: 100%;
  98. height: 100%;
  99. }
  100. .product-bg .pages {
  101. position: absolute;
  102. background-color: #fff;
  103. height: 34rpx;
  104. padding: 0 10rpx;
  105. border-radius: 3rpx;
  106. right: 30rpx;
  107. bottom: 30rpx;
  108. line-height: 34rpx;
  109. font-size: 24rpx;
  110. color: #050505;
  111. }
  112. #myVideo {
  113. width: 100%;
  114. height: 100%
  115. }
  116. .product-bg .item {
  117. position: relative;
  118. width: 100%;
  119. height: 100%;
  120. }
  121. .product-bg .item .poster {
  122. position: absolute;
  123. top: 0;
  124. left: 0;
  125. height: 750rpx;
  126. width: 100%;
  127. z-index: 9;
  128. }
  129. .product-bg .item .poster .image {
  130. width: 100%;
  131. height: 100%;
  132. }
  133. .product-bg .item .stop {
  134. position: absolute;
  135. top: 50%;
  136. left: 50%;
  137. width: 136rpx;
  138. height: 136rpx;
  139. margin-top: -68rpx;
  140. margin-left: -68rpx;
  141. z-index: 9;
  142. }
  143. .product-bg .item .stop .image {
  144. width: 100%;
  145. height: 100%;
  146. }
  147. </style>