Banner.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <view class="banner-swiper-box">
  3. <canvas canvas-id="colorThief" class="hide-canvas"></canvas>
  4. <swiper class="banner-carousel Shop-selector-rect" circular @change="swiperChange" :autoplay="true">
  5. <swiper-item v-for="(item, index) in detail" :key="index" class="carousel-item">
  6. <image class="swiper-image" :src="item.pic" mode="heightFix" lazy-load>
  7. </image>
  8. </swiper-item>
  9. </swiper>
  10. <view class="banner-swiper-dots">
  11. <text :class="swiperCurrent === index ? 'banner-dot-active' : 'banner-dot'" v-for="(dot, index) in detail.length"
  12. :key="index"></text>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import colorThief from 'miniapp-color-thief';
  18. export default {
  19. data() {
  20. return {
  21. swiperCurrent: 0, //轮播下标
  22. webviewId: 0,
  23. };
  24. },
  25. props: {
  26. detail: {
  27. type: Array,
  28. default: []
  29. }
  30. },
  31. created: async function() {
  32. await this.doColorThief();
  33. },
  34. computed: {},
  35. methods: {
  36. doColorThief() {
  37. let that = this;
  38. // 获取轮播图
  39. let item = this.detail[this.swiperCurrent];
  40. // 获取轮播图颜色
  41. let bgcolor = item.color;
  42. // 颜色不存在
  43. if (!bgcolor) {
  44. that.$set(item, 'bgcolor', '#2A2A2A');
  45. that.$emit('getbgcolor', '#2A2A2A');
  46. } else {
  47. that.$set(item, 'bgcolor', bgcolor);
  48. that.$emit('getbgcolor', bgcolor);
  49. }
  50. },
  51. swiperChange(e) {
  52. this.swiperCurrent = e.detail.current;
  53. this.doColorThief();
  54. let bgcolor = this.detail[this.swiperCurrent].bgcolor;
  55. },
  56. // 路由跳转
  57. goRoll(item) {
  58. if (item.uniapp_url) {
  59. this.$yrouter.push(item.uniapp_url)
  60. }
  61. },
  62. }
  63. }
  64. </script>
  65. <style lang="less">
  66. // 轮播
  67. .banner-swiper-box {
  68. background: #fff;
  69. }
  70. .banner-swiper-box,
  71. .banner-carousel {
  72. width: 750rpx;
  73. height: 380rpx;
  74. position: relative;
  75. .carousel-item {
  76. width: 100%;
  77. height: 100%;
  78. // padding: 0 28upx;
  79. overflow: hidden;
  80. }
  81. .swiper-image {
  82. width: 100%;
  83. height: 100%;
  84. // border-radius: 10upx;
  85. // background: #ccc;
  86. }
  87. }
  88. .banner-swiper-dots {
  89. display: flex;
  90. position: absolute;
  91. left: 50%;
  92. transform: translateX(-50%);
  93. bottom: 20rpx;
  94. z-index: 5;
  95. .banner-dot {
  96. width: 8rpx;
  97. height: 8rpx;
  98. border-radius: 50%;
  99. margin-right: 6rpx;
  100. background: rgba(255, 255, 255, 1);
  101. }
  102. .banner-dot-active {
  103. width: 30rpx;
  104. height: 8rpx;
  105. background: #C3102E;
  106. border-radius: 4rpx;
  107. margin-right: 6rpx;
  108. }
  109. }
  110. .hide-canvas {
  111. position: fixed !important;
  112. top: -99999upx;
  113. left: -99999upx;
  114. z-index: -99999;
  115. }
  116. </style>