index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. :bg-color="$colors.bgColor"
  19. :indicator="true"
  20. :show-title="true"
  21. indicator-mode="dot"
  22. :indicator-style="{bottom: '24rpx'}"
  23. img-mode=""
  24. @click="handleClick"
  25. @change="handleChange"
  26. >
  27. <view
  28. slot="indicator"
  29. class="indicator"
  30. >
  31. <view
  32. v-for="(item, index) in list"
  33. :key="index"
  34. class="indicator__dot"
  35. :class="[index === currentNum && 'indicator__dot--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: '10rpx'
  52. }
  53. },
  54. data() {
  55. return {
  56. loading: true,
  57. list: [],
  58. currentNum: 0
  59. }
  60. },
  61. computed: {
  62. },
  63. created() {
  64. this.getSwiper()
  65. },
  66. methods: {
  67. handleClick(index) {
  68. const item = this.list[index]
  69. console.log('-->data', item)
  70. },
  71. handleChange(e) {
  72. this.currentNum = e.current
  73. },
  74. getSwiper() {
  75. this.$api.setting.banner().then(res => {
  76. this.loading = false
  77. res.data.forEach(obj => {
  78. this.list.push(obj.image)
  79. })
  80. })
  81. }
  82. }
  83. }
  84. </script>
  85. <style lang="scss" scoped>
  86. .swiper-box{
  87. margin: 20rpx 0;
  88. border-radius: 8rpx;
  89. &.loading{
  90. background-color: #1B203C;
  91. }
  92. .indicator {
  93. display: flex;
  94. flex-direction: row;
  95. justify-content: center;
  96. &__dot {
  97. height: 20rpx;
  98. width: 20rpx;
  99. border-radius: 50%;
  100. background-color: rgba(255, 255, 255, 0.35);
  101. margin: 0 10px;
  102. transition: background-color 0.3s;
  103. &--active {
  104. background-color: #6EEBE8;
  105. }
  106. }
  107. }
  108. }
  109. </style>