app-swiper.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div class="swiper-wrap" :style="{'width': widthFn,'height': heightFn}">
  3. <swiper :indicator-dots="!tagShow" :autoplay="autoplay" :interval="5000" :duration="150" class="tui-banner-swiper" :circular="true" indicator-color="#969696" indicator-active-color="#F04545" @change="bannerChange">
  4. <swiper-item v-for="(item, index) in list" :key="index" @tap.stop="detail">
  5. <img :src="item" class="tui-slide-image" mode="center" />
  6. </swiper-item>
  7. </swiper>
  8. <app-tag v-if="tagShow" type="translucent" shape="circleLeft" size="small">{{index + 1}}/{{list.length}}</app-tag>
  9. </div>
  10. </template>
  11. <script>
  12. import AppTag from '@/components/module/app-tag.vue'
  13. export default {
  14. name: 'app-swiper',
  15. components: {
  16. AppTag
  17. },
  18. props: {
  19. list: {
  20. type: Array,
  21. default: () => {
  22. return []
  23. }
  24. },
  25. // 是否显示右下角tag
  26. tagShow: {
  27. type: Boolean,
  28. default: false
  29. },
  30. // 是否自动播放
  31. autoplay: {
  32. type: Boolean,
  33. default: true
  34. },
  35. // 宽度
  36. width: {
  37. type: Object,
  38. default: () => {
  39. return {
  40. type: 'string',
  41. val: '100%'
  42. }
  43. }
  44. },
  45. // 高度
  46. height: {
  47. type: Object,
  48. default: () => {
  49. return {
  50. type: 'number',
  51. val: 480
  52. }
  53. }
  54. }
  55. },
  56. data() {
  57. return {
  58. index: 0
  59. }
  60. },
  61. computed: {
  62. widthFn() {
  63. if (this.width.type == 'number') {
  64. return uni.upx2px(this.width.val) + 'px'
  65. } else {
  66. return this.width.val
  67. }
  68. },
  69. heightFn() {
  70. if (this.height.type == 'number') {
  71. return uni.upx2px(this.height.val) + 'px'
  72. } else {
  73. return this.height.val
  74. }
  75. }
  76. },
  77. methods: {
  78. bannerChange: function(e) {
  79. this.index = e.detail.current
  80. },
  81. detail(data) {
  82. this.$emit('detail', data)
  83. }
  84. }
  85. }
  86. </script>
  87. <style lang="scss" scoped>
  88. .swiper-wrap {
  89. position: relative;
  90. height: 480px;
  91. .tui-banner-swiper {
  92. height: 100%;
  93. }
  94. .tui-slide-image {
  95. width: 100%;
  96. height: 100%;
  97. }
  98. /* #ifdef H5 */
  99. /deep/.tui-banner-swiper .uni-swiper-dot {
  100. width: 28rpx;
  101. height: 8rpx;
  102. display: inline-flex;
  103. background: none;
  104. justify-content: space-between;
  105. }
  106. /deep/.tui-banner-swiper .uni-swiper-dot::before {
  107. content: '';
  108. flex-grow: 1;
  109. background: #969696;
  110. border-radius: 16rpx;
  111. overflow: hidden;
  112. }
  113. /deep/.tui-banner-swiper .uni-swiper-dot-active::before {
  114. background: #F04545;
  115. }
  116. /* #endif */
  117. // tag
  118. .tui-tag-class {
  119. position: absolute;
  120. color: #fff;
  121. bottom: 30rpx;
  122. right: 0;
  123. }
  124. }
  125. </style>