app-swiper.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <view class="bigBox">
  3. <div class="swiper-wrap" :style="{'width': widthFn,'height': heightFn}">
  4. <swiper :indicator-dots="tagShow" :autoplay="autoplay" :interval="5000" :duration="150" class="tui-banner-swiper" :circular="true" indicator-color="#969696" indicator-active-color="#3387ff" @change="bannerChange">
  5. <swiper-item v-for="(item, index) in list" :key="index" @tap.stop="detail">
  6. <img :src="item.img" class="tui-slide-image" mode="scaleToFill" />
  7. <view class="info">{{item.name || ''}}</view>
  8. </swiper-item>
  9. </swiper>
  10. <!-- <app-tag v-if="tagShow" class="swiper-tag" type="translucent" shape="circleLeft" size="small">{{index + 1}}/{{list.length}}</app-tag> -->
  11. </div>
  12. <view class="swiper_dots">
  13. <text v-for="(item, index) in list" :key="index" :class="{'active': index === currentIndex}"></text>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import AppTag from '@/components/module/app-tag.vue'
  19. export default {
  20. name: 'app-swiper',
  21. components: {
  22. AppTag
  23. },
  24. props: {
  25. list: {
  26. type: Array,
  27. default: () => {
  28. return []
  29. }
  30. },
  31. // 是否显示右下角tag
  32. tagShow: {
  33. type: Boolean,
  34. default: false
  35. },
  36. // 是否自动播放
  37. autoplay: {
  38. type: Boolean,
  39. default: true
  40. },
  41. // 宽度
  42. width: {
  43. type: Object,
  44. default: () => {
  45. return {
  46. type: 'string',
  47. val: '100%'
  48. }
  49. }
  50. },
  51. // 高度
  52. height: {
  53. type: Object,
  54. default: () => {
  55. return {
  56. type: 'number',
  57. val: 480
  58. }
  59. }
  60. }
  61. },
  62. data() {
  63. return {
  64. currentIndex: 0
  65. }
  66. },
  67. computed: {
  68. widthFn() {
  69. if (this.width.type == 'number') {
  70. return uni.upx2px(this.width.val) + 'px'
  71. } else {
  72. return this.width.val
  73. }
  74. },
  75. heightFn() {
  76. if (this.height.type == 'number') {
  77. return uni.upx2px(this.height.val) + 'px'
  78. } else {
  79. return this.height.val
  80. }
  81. }
  82. },
  83. methods: {
  84. bannerChange: function(e) {
  85. this.currentIndex = e.detail.current
  86. },
  87. detail(data) {
  88. this.$emit('detail', data)
  89. }
  90. }
  91. }
  92. </script>
  93. <style lang="scss" scoped>
  94. .swiper-wrap {
  95. position: relative;
  96. height: 480upx;
  97. margin: 0 auto ;
  98. border-radius: 20upx;
  99. overflow: hidden;
  100. -webkit-backface-visibility: hidden;
  101. -webkit-transform: translate3d(0, 0, 0);
  102. .tui-banner-swiper {
  103. height: 100%;
  104. }
  105. .tui-slide-image {
  106. width: 100%;
  107. height: 100%;
  108. }
  109. .info{
  110. position: absolute;
  111. bottom: 0;
  112. left: 0;
  113. width: 100%;
  114. height: 88upx;
  115. line-height: 88upx;
  116. text-align: center;
  117. font-size: 32upx;
  118. color: #fff;
  119. background: rgba(0,0,0,0.6)
  120. }
  121. /* #ifdef H5 */
  122. ::v-deep.tui-banner-swiper .uni-swiper-dot {
  123. width: 28upx;
  124. height: 8upx;
  125. display: inline-flex;
  126. background: none;
  127. justify-content: space-between;
  128. }
  129. ::v-deep.tui-banner-swiper .uni-swiper-dot::before {
  130. content: '';
  131. flex-grow: 1;
  132. background: #969696;
  133. border-radius: 16upx;
  134. overflow: hidden;
  135. }
  136. ::v-deep.tui-banner-swiper .uni-swiper-dot-active::before {
  137. background: #F04545;
  138. }
  139. /* #endif */
  140. }
  141. .bigBox{
  142. height: 450upx;
  143. position: relative;
  144. .swiper_dots{
  145. position: absolute;
  146. bottom: 10upx;
  147. left: 50%;
  148. z-index: 2021;
  149. transform: translateX(-50%);
  150. // height: 16upx;
  151. // width: 100upx;
  152. // background-color: red !important;
  153. &>text{
  154. display: inline-block;
  155. height: 12upx;
  156. width: 12upx;
  157. background: #CCCCCC;
  158. border-radius: 6upx;
  159. margin-left: 14upx;
  160. }
  161. &>.active{
  162. width: 26upx;
  163. background: #3387FF;
  164. }
  165. }
  166. }
  167. </style>