index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. data: []
  60. }
  61. },
  62. computed: {
  63. },
  64. async created() {
  65. await this.getSwiper()
  66. },
  67. methods: {
  68. handleClick(index) {
  69. const item = this.data[index]
  70. console.log('-->data', item)
  71. if (item.episode_id) {
  72. this.$u.route({
  73. url: 'pages/episode/play',
  74. params: {
  75. id: item.episode_id
  76. }
  77. })
  78. }
  79. },
  80. handleChange(e) {
  81. this.currentNum = e.current
  82. },
  83. async getSwiper() {
  84. await this.$api.setting.banner().then(res => {
  85. this.loading = false
  86. this.data = res.data
  87. res.data.forEach(obj => {
  88. this.list.push(obj.image)
  89. })
  90. })
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. .swiper-box{
  97. margin: 20rpx 0;
  98. border-radius: 8rpx;
  99. &.loading{
  100. background-color: $bg-color;
  101. }
  102. .indicator {
  103. display: flex;
  104. flex-direction: row;
  105. justify-content: center;
  106. &__dot {
  107. height: 20rpx;
  108. width: 20rpx;
  109. border-radius: 50%;
  110. background-color: rgba(255, 255, 255, 0.35);
  111. margin: 0 10px;
  112. transition: background-color 0.3s;
  113. &--active {
  114. background-color: #6EEBE8;
  115. }
  116. }
  117. }
  118. }
  119. </style>