小程序端工程代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
2.6 KiB

  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" @click="goRoll(item)" mode="widthFix" 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. async 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', '#c40414');
  45. that.$emit('getbgcolor', '#c40414');
  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. this.$emit('getbgcolor', bgcolor);
  56. },
  57. // 路由跳转
  58. goRoll(item) {
  59. if (item.uniapp_url) {
  60. this.$yrouter.push(item.uniapp_url)
  61. }
  62. },
  63. }
  64. }
  65. </script>
  66. <style lang="less">
  67. // 轮播
  68. .banner-swiper-box {
  69. background: #fff;
  70. }
  71. .banner-swiper-box,
  72. .banner-carousel {
  73. width: 750rpx;
  74. height: 350upx;
  75. position: relative;
  76. .carousel-item {
  77. width: 100%;
  78. height: 100%;
  79. // padding: 0 28upx;
  80. overflow: hidden;
  81. }
  82. .swiper-image {
  83. width: 100%;
  84. height: 100%;
  85. // border-radius: 10upx;
  86. // background: #ccc;
  87. }
  88. }
  89. .banner-swiper-dots {
  90. display: flex;
  91. position: absolute;
  92. left: 50%;
  93. transform: translateX(-50%);
  94. bottom: 20rpx;
  95. z-index: 5;
  96. .banner-dot {
  97. width: 14rpx;
  98. height: 14rpx;
  99. background: rgba(255, 255, 255, 1);
  100. border-radius: 50%;
  101. margin-right: 10rpx;
  102. }
  103. .banner-dot-active {
  104. width: 14rpx;
  105. height: 14rpx;
  106. background: #a8700d;
  107. border-radius: 50%;
  108. margin-right: 10rpx;
  109. }
  110. }
  111. .hide-canvas {
  112. position: fixed !important;
  113. top: -99999upx;
  114. left: -99999upx;
  115. z-index: -99999;
  116. }
  117. </style>