index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <view class="swiper-container">
  3. <swiper class="swiper" circular :indicator-dots="false" :circular="circular" :next-margin="nextMargin" :autoplay="autoplay" :interval="interval"
  4. :duration="duration" :style="style" @change="onSwiperChange">
  5. <template v-for="(item, index) in items">
  6. <swiper-item :key="index">
  7. <view class="image-wrapper" @tap="onImageClick(item)">
  8. <image v-if="item.src" :mode="imageMode" :src="item.src" :style="imageStyle"/>
  9. <slot v-else :scope="item"></slot>
  10. <view class="video-play" v-if="item.url && item.url.indexOf('.mp4') !== -1">
  11. <view class="iconfont icon-playcircle"></view>
  12. </view>
  13. </view>
  14. </swiper-item>
  15. </template>
  16. </swiper>
  17. <!-- 自定义指示点 -->
  18. <view v-if="indicatorDots" class="custom-indicator" :class="{ 'morphing': indicatoDotsStyle === 'morphing' }">
  19. <view
  20. v-for="(item, index) in items"
  21. :key="index"
  22. class="dot"
  23. :class="{ 'active': current === index }"
  24. ></view>
  25. </view>
  26. <van-overlay :show="showOverlay" @tap="onClickHideOverlay">
  27. <view class="overlay-wrapper">
  28. <video v-if="videoUrl" :src="videoUrl" controls autoplay loop @tap.stop></video>
  29. </view>
  30. </van-overlay>
  31. </view>
  32. </template>
  33. <script>
  34. import VanOverlay from '@/wxcomponents/vant/overlay/index'
  35. export default {
  36. options: {
  37. styleIsolation: 'shared'
  38. },
  39. components: {
  40. VanOverlay
  41. },
  42. props: {
  43. items: Array,
  44. borderRadius: {
  45. type: Number
  46. },
  47. nextMargin: {
  48. type: String,
  49. default: ''
  50. },
  51. height: {
  52. type: Number,
  53. default: 400
  54. },
  55. imageWidth: {
  56. type: Number,
  57. default: 0
  58. },
  59. imageHeight: {
  60. type: Number,
  61. default: 0
  62. },
  63. imageMode: {
  64. type: String,
  65. default: 'aspectFill' // 参考https://zh.uniapp.dcloud.io/component/image.html
  66. },
  67. indicatoDotsStyle: {
  68. type: String,
  69. default: 'default' // or 'morphing'
  70. },
  71. indicatorDots: {
  72. type: Boolean,
  73. default: true
  74. },
  75. circular: {
  76. type: Boolean,
  77. default: true
  78. },
  79. autoplay: {
  80. type: Boolean,
  81. default: true
  82. },
  83. interval: {
  84. type: Number,
  85. default: 5000
  86. },
  87. duration: {
  88. type: Number,
  89. default: 500
  90. }
  91. },
  92. computed: {
  93. style() {
  94. return 'height:' + this.height + 'rpx;'
  95. },
  96. imageStyle() {
  97. let style = 'height:' + (this.imageHeight || this.height) + 'rpx;'
  98. if (this.imageWidth) {
  99. style += 'width:' + this.imageWidth + 'rpx;'
  100. }
  101. if (this.borderRadius) {
  102. style += 'border-radius:' + this.borderRadius + 'rpx;'
  103. }
  104. return style
  105. }
  106. },
  107. watch: {
  108. },
  109. data() {
  110. return {
  111. showOverlay: false,
  112. videoUrl: '',
  113. current: 0
  114. }
  115. },
  116. created() {
  117. },
  118. mounted() {
  119. },
  120. methods: {
  121. onClickHideOverlay() {
  122. this.showOverlay = false
  123. },
  124. onSwiperChange(e) {
  125. this.current = e.detail.current
  126. },
  127. onImageClick(item) {
  128. if (item.url) {
  129. if (item.url.indexOf('.mp4') !== -1) {
  130. this.videoUrl = item.url
  131. this.showOverlay = true
  132. } else {
  133. this.navigateTo(item.url)
  134. }
  135. }
  136. }
  137. }
  138. }
  139. </script>
  140. <style lang="scss" scoped>
  141. .image-wrapper {
  142. position: relative;
  143. .video-play{
  144. @include display-flex-center;
  145. position: absolute;
  146. top: 0;
  147. bottom: 0;
  148. right: 0;
  149. left: 0;
  150. width: 82rpx;
  151. height: 82rpx;
  152. border-radius: 50%;
  153. margin: auto;
  154. background-color: rgba(229, 117, 25, 0.5);
  155. z-index: 1;
  156. .iconfont{
  157. color: #FFFFFF;
  158. font-size: 62rpx;
  159. }
  160. }
  161. image{
  162. width: 100%;
  163. }
  164. }
  165. .overlay-wrapper{
  166. @include display-flex-center;
  167. height: 100%;
  168. video{
  169. width: 100%;
  170. }
  171. }
  172. .swiper-container{
  173. position: relative;
  174. }
  175. /* 自定义指示点样式 */
  176. .custom-indicator {
  177. position: absolute;
  178. bottom: 24rpx;
  179. width: 100%;
  180. display: flex;
  181. justify-content: center;
  182. margin-top: 10rpx;
  183. &.morphing {
  184. .dot{
  185. margin: 0 5rpx;
  186. }
  187. .dot.active{
  188. width: 26rpx;
  189. border-radius: 8rpx;
  190. background-color: white;
  191. }
  192. }
  193. }
  194. .dot {
  195. width: 12rpx;
  196. height: 12rpx;
  197. border-radius: 50%;
  198. background-color: #D9D9D9;
  199. margin: 0 2.5rpx;
  200. &.active {
  201. background-color: $buttonPrimaryColor; /* 当前激活的指示点颜色 */
  202. }
  203. }
  204. </style>