banner.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <view>
  3. <view v-if="banners && banners.length > 0" class="swiper-wrapper">
  4. <swiper class="swiper" :style="{height: itemHeight}" circular :duration="400" autoplay :interval="3000"
  5. @change="change">
  6. <swiper-item class="swiper-item" :style="{height: itemHeight}" v-for="(item, index) in banners" :key="index"
  7. @click="showNext(item)">
  8. <image :src="item.cover" webp class="image" :style="{height: itemHeight}" mode="aspectFill" />
  9. </swiper-item>
  10. </swiper>
  11. <view class="dot-wrapper translateX flex-align-around">
  12. <view v-for="item in banners.length" :key="item" class="dot" :class="[active === item && 'active']"></view>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. active: 0
  22. }
  23. },
  24. computed: {
  25. itemHeight() {
  26. let width = this.$store.state.systemInfo.screenWidth - uni.upx2px(56)
  27. return Math.floor((210 / 1053) * width) + 'px'
  28. },
  29. banners() {
  30. if (!this.$store.state.pageConfig || !this.$store.state.pageConfig['magic_luck']) {
  31. return null
  32. }
  33. let components = this.$store.state.pageConfig['magic_luck'].components
  34. if (!components || components.length === 0) return null
  35. let data = null
  36. for (let i = 0; i < components.length; i++) {
  37. if (components[i].type === 'capsule') {
  38. data = components[i].elements
  39. }
  40. }
  41. if(!!this.$store.state.hide) {
  42. data.forEach((item, index) => {
  43. if (item.path && item.path.params && item.path.params.url === 'hidden_activity') {
  44. data.splice(index, 1);
  45. }
  46. })
  47. }
  48. return data
  49. }
  50. },
  51. methods: {
  52. change(e) {
  53. this.active = e.detail.current
  54. },
  55. showNext(item) {
  56. this.$common.showNext(item)
  57. }
  58. }
  59. }
  60. </script>
  61. <style lang="scss" scoped>
  62. .swiper-wrapper {
  63. margin: 20rpx 28rpx 0;
  64. overflow: hidden;
  65. border-radius: 20rpx;
  66. position: relative;
  67. .swiper {
  68. width: 100%;
  69. border-radius: 20rpx;
  70. overflow: hidden;
  71. .swiper-item {
  72. width: 100%;
  73. border-radius: 20rpx;
  74. overflow: hidden;
  75. .image {
  76. width: 100%;
  77. border-radius: 20rpx;
  78. }
  79. }
  80. }
  81. .dot-wrapper {
  82. position: absolute;
  83. bottom: 8rpx;
  84. width: 60rpx;
  85. height: 8rpx;
  86. .dot {
  87. width: 8rpx;
  88. height: 8rpx;
  89. border-radius: 4rpx;
  90. background: rgba($color: #000000, $alpha: 0.4);
  91. &.active {
  92. background: #fff;
  93. }
  94. }
  95. }
  96. }
  97. </style>