index.vue 2.3 KB

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