index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 if (item.url.indexOf('http') === -1) {
  133. uni.navigateTo({
  134. url: item.url
  135. })
  136. } else {
  137. uni.navigateTo({
  138. url: '/pages/index/webview?url=' + item.url
  139. })
  140. }
  141. }
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. .image-wrapper {
  148. position: relative;
  149. .video-play{
  150. @include display-flex-center;
  151. position: absolute;
  152. top: 0;
  153. bottom: 0;
  154. right: 0;
  155. left: 0;
  156. width: 82rpx;
  157. height: 82rpx;
  158. border-radius: 50%;
  159. margin: auto;
  160. background-color: rgba(229, 117, 25, 0.5);
  161. z-index: 1;
  162. .iconfont{
  163. color: #FFFFFF;
  164. font-size: 62rpx;
  165. }
  166. }
  167. image{
  168. width: 100%;
  169. }
  170. }
  171. .overlay-wrapper{
  172. @include display-flex-center;
  173. height: 100%;
  174. video{
  175. width: 100%;
  176. }
  177. }
  178. .swiper-container{
  179. position: relative;
  180. }
  181. /* 自定义指示点样式 */
  182. .custom-indicator {
  183. position: absolute;
  184. bottom: 24rpx;
  185. width: 100%;
  186. display: flex;
  187. justify-content: center;
  188. margin-top: 10rpx;
  189. &.morphing {
  190. .dot{
  191. margin: 0 5rpx;
  192. }
  193. .dot.active{
  194. width: 26rpx;
  195. border-radius: 8rpx;
  196. background-color: white;
  197. }
  198. }
  199. }
  200. .dot {
  201. width: 12rpx;
  202. height: 12rpx;
  203. border-radius: 50%;
  204. background-color: #D9D9D9;
  205. margin: 0 2.5rpx;
  206. &.active {
  207. background-color: $buttonPrimaryColor; /* 当前激活的指示点颜色 */
  208. }
  209. }
  210. </style>