index.vue 2.1 KB

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