index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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%"
  18. :indicator="true"
  19. :show-title="true"
  20. indicator-mode="dot"
  21. :indicator-style="{bottom: '24rpx'}"
  22. @click="handleClick"
  23. @change="handleChange"
  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__dot"
  33. :class="[index === currentNum && 'indicator__dot--active']"
  34. />
  35. </view>
  36. </u-swiper>
  37. </view>
  38. </template>
  39. <script>
  40. export default {
  41. name: 'SwiperBox',
  42. props: {
  43. height: {
  44. type: [Number, String],
  45. default: '330rpx'
  46. },
  47. radius: {
  48. type: [Number, String],
  49. default: '10rpx'
  50. }
  51. },
  52. data() {
  53. return {
  54. loading: true,
  55. list: [],
  56. currentNum: 0
  57. }
  58. },
  59. computed: {
  60. },
  61. created() {
  62. this.getSwiper()
  63. },
  64. methods: {
  65. handleClick(index) {
  66. const item = this.list[index]
  67. console.log('-->data', item)
  68. },
  69. handleChange(e) {
  70. this.currentNum = e.current
  71. },
  72. getSwiper() {
  73. this.$api.setting.banner().then(res => {
  74. this.loading = false
  75. res.data.forEach(obj => {
  76. this.list.push(obj.image)
  77. })
  78. })
  79. }
  80. }
  81. }
  82. </script>
  83. <style lang="scss" scoped>
  84. .swiper-box{
  85. margin: 20rpx 0;
  86. border-radius: 8rpx;
  87. &.loading{
  88. background-color: #1B203C;
  89. }
  90. .indicator {
  91. display: flex;
  92. flex-direction: row;
  93. justify-content: center;
  94. &__dot {
  95. height: 20rpx;
  96. width: 20rpx;
  97. border-radius: 50%;
  98. background-color: rgba(255, 255, 255, 0.35);
  99. margin: 0 10px;
  100. transition: background-color 0.3s;
  101. &--active {
  102. background-color: #6EEBE8;
  103. }
  104. }
  105. }
  106. }
  107. </style>