banner2.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <view v-if="storage" >
  3. <view class="swiper-container" :style="{backgroundColor:bgColor}" >
  4. <view class="left-swiper" :style="{padding: showStyle1}" style="width: 100%; height: 100%;">
  5. <swiper :style="{height:getFatherHeight}" circular autoplay="true" interval="2200" duration="200" >
  6. <swiper-item v-for="(item, index) in images1" :key="index"
  7. @click="naviageToPage(item.link)"
  8. :style="{padding: showStyle1}" >
  9. <image :src="item.url" style="width: 100%; height: 100%;"
  10. :style="{borderRadius:borderRadius1,height:getHeight}"
  11. ></image>
  12. </swiper-item>
  13. </swiper>
  14. <!-- <div :style="{backgroundSize:swiperImgStyle1,borderRadius:borderRadius1,height:getHeight}" />-->
  15. </view>
  16. <view class="right-swiper" :style="{padding: showStyle2}" style="width: 100%; height: 100%;">
  17. <swiper :style="{height:getFatherHeight}" circular autoplay="true" interval="2400" duration="200" >
  18. <swiper-item v-for="(item, index) in images2" :key="index"
  19. @click="naviageToPage(item.link)"
  20. :style="{padding: showStyle2}" >
  21. <image :src="item.url"
  22. style="width: 100%; height: 100%;"
  23. :style="{borderRadius:borderRadius2,height:getHeight}"
  24. ></image>
  25. </swiper-item>
  26. </swiper>
  27. <!-- <div :style="{backgroundSize:swiperImgStyle2,borderRadius:borderRadius2,height:getHeight}" />-->
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. export default {
  34. name: 'Banner2',
  35. props: ['storage', 'categoryButtomList', 'options'],
  36. computed: {
  37. getHeight() {
  38. return this.options.height
  39. },
  40. bgColor() {
  41. return this.options.bgColor
  42. },
  43. images1() {
  44. return this.options.images1
  45. },
  46. showStyle1() {
  47. if (this.options.showStyle1 == 'custom'){
  48. return this.options.customStyle1
  49. }
  50. return this.options.showStyle1
  51. },
  52. imgStyle1() {
  53. return this.options.imgStyle1
  54. },
  55. borderRadius1() {
  56. return this.options.borderRadius1
  57. },
  58. images2() {
  59. return this.options.images2
  60. },
  61. showStyle2() {
  62. if (this.options.showStyle2 == 'custom'){
  63. return this.options.customStyle2
  64. }
  65. return this.options.showStyle2
  66. },
  67. imgStyle2() {
  68. return this.options.imgStyle2
  69. },
  70. borderRadius2() {
  71. return this.options.borderRadius2
  72. },
  73. getFatherHeight() {
  74. let paddingString = this.showStyle1;
  75. if(!paddingString){
  76. return this.options.height
  77. }
  78. let matches = paddingString.match(/(\d+px)\s*(\d+px)?/);
  79. console.log('matches------',matches)
  80. let top = 0;
  81. let bottom = 0;
  82. if (matches) {
  83. top = parseInt(matches[1], 10);
  84. bottom = matches[2] ? parseInt(matches[2], 10) : top; // default to top value if no bottom value is present
  85. console.log(`Top111111111: ${top}px, Bottom: ${bottom}px`);
  86. }
  87. // 将 this.options.height 转换为数值
  88. let height = parseInt(this.options.height.replace('px', ''), 10);
  89. // 计算总高度
  90. let totalHeight = height + top + bottom;
  91. console.log(`totalHeight: ${totalHeight}px`);
  92. // 返回带有 px 单位的字符串
  93. return totalHeight + 'px';
  94. }
  95. },
  96. methods: {
  97. naviageToPage(url, title) {
  98. this.$emit('naviage-to-page', url, title);
  99. }
  100. }
  101. }
  102. </script>
  103. <style scoped lang="scss">
  104. .swiper-container {
  105. display: flex;
  106. justify-content: space-between;
  107. }
  108. // .left-swiper,
  109. // .right-swiper {
  110. // width: 48%; /* Adjust width according to your design */
  111. // /* Add any additional styles you need */
  112. // }
  113. </style>