index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view
  3. class="swiper-box "
  4. :class="{
  5. loading:loading,
  6. 'main-center':loading,
  7. 'cross-center': loading
  8. }"
  9. :style="{height: height}"
  10. >
  11. <u-loading-icon :show="loading" vertical />
  12. <u-swiper
  13. v-if="list.length"
  14. :list="list"
  15. :height="height"
  16. :radius="radius"
  17. :style="{width: '100%', backgroundPosition: 'center'}"
  18. :indicator="true"
  19. :show-title="true"
  20. indicator-mode="dot"
  21. :indicator-style="{bottom: '24rpx'}"
  22. @change="handleChange"
  23. @click="handleClick"
  24. >
  25. <view
  26. slot="indicator"
  27. class="indicator"
  28. >
  29. <view
  30. v-for="(item, index) in list"
  31. :key="index"
  32. class="indicator__line"
  33. :style="{
  34. width: `${(380 / list.length)}rpx`
  35. }"
  36. :class="[index === currentNum && 'indicator__line--active']"
  37. />
  38. </view>
  39. </u-swiper>
  40. </view>
  41. </template>
  42. <script>
  43. export default {
  44. name: 'SwiperBox',
  45. props: {
  46. height: {
  47. type: [Number, String],
  48. default: '330rpx'
  49. },
  50. radius: {
  51. type: [Number, String],
  52. default: '0rpx'
  53. },
  54. type: {
  55. type: String,
  56. default: 'login'
  57. }
  58. },
  59. data() {
  60. return {
  61. loading: true,
  62. list: [],
  63. original: [],
  64. currentNum: 0
  65. }
  66. },
  67. computed: {
  68. },
  69. created() {
  70. this.getSwiper()
  71. },
  72. methods: {
  73. handleChange(e) {
  74. this.currentNum = e.current
  75. },
  76. getSwiper() {
  77. const method = this.type === 'login' ? 'loginBanner' : 'indexBanner'
  78. this.$api.setting[method]().then(res => {
  79. this.loading = false
  80. this.original = res.data
  81. res.data.forEach(obj => {
  82. this.list.push(obj.image)
  83. })
  84. })
  85. },
  86. handleClick(index) {
  87. const data = this.original[index]
  88. this.$emit('click', data)
  89. }
  90. }
  91. }
  92. </script>
  93. <style lang="scss" scoped>
  94. .swiper-box{
  95. margin: 20rpx 0;
  96. border-radius: 8rpx;
  97. &.loading{
  98. background-color: #FFFFFF;
  99. }
  100. .indicator {
  101. display: flex;
  102. flex-direction: row;
  103. justify-content: center;
  104. position: relative;
  105. margin-bottom: 10%;
  106. &__line {
  107. height: 1rpx;
  108. width: 50rpx;
  109. background-color: rgba(255, 255, 255, 0.7);
  110. transition: background-color 0.3s;
  111. border-radius: 5rpx;
  112. &--active {
  113. height: 8rpx;
  114. margin-top: -4rpx;
  115. background: #fff;
  116. }
  117. }
  118. }
  119. }
  120. </style>