banner1.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <view v-if="storage"
  3. :style="{height:getFatherHeight,backgroundColor:bgColor}"
  4. >
  5. <swiper circular autoplay="true" interval="2000" duration="400" >
  6. <swiper-item v-for="(item, index) in images" :key="index"
  7. @click="naviageToPage(item.link)"
  8. :style="{padding:showStyle}"
  9. >
  10. <image :src="item.url"
  11. style="width: 100%;"
  12. :mode="imgStyle==='cover'?'aspectFill':'scaleToFill'"
  13. :style="{borderRadius:borderRadius,height:getHeight}"
  14. />
  15. </swiper-item>
  16. </swiper>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. name: 'Banner1',
  22. props: ['storage', 'options'],
  23. computed: {
  24. images() {
  25. return this.options.images
  26. },
  27. imgStyle() {
  28. return this.options.imgStyle
  29. },
  30. showStyle() {
  31. if (this.options.showStyle == 'custom'){
  32. return this.options.customStyle
  33. }
  34. return this.options.showStyle
  35. },
  36. bgColor() {
  37. return this.options.bgColor
  38. },
  39. borderRadius() {
  40. return this.options.borderRadius
  41. },
  42. getHeight() {
  43. return this.options.height
  44. },
  45. getFatherHeight() {
  46. let paddingString = this.showStyle;
  47. if(!paddingString){
  48. return this.options.height
  49. }
  50. let matches = paddingString.match(/(\d+px)\s*(\d+px)?/);
  51. console.log('matches------',matches)
  52. let top = 0;
  53. let bottom = 0;
  54. if (matches) {
  55. top = parseInt(matches[1], 10);
  56. bottom = matches[2] ? parseInt(matches[2], 10) : top; // default to top value if no bottom value is present
  57. console.log(`Top111111111: ${top}px, Bottom: ${bottom}px`);
  58. }
  59. // 将 this.options.height 转换为数值
  60. let height = parseInt(this.options.height.replace('px', ''), 10);
  61. // 计算总高度
  62. let totalHeight = height + top + bottom;
  63. console.log(`totalHeight: ${totalHeight}px`);
  64. // 返回带有 px 单位的字符串
  65. return totalHeight + 'px';
  66. }
  67. },
  68. methods: {
  69. naviageToPage(url, title) {
  70. this.$emit('naviage-to-page', url, title)
  71. }
  72. }
  73. }
  74. </script>
  75. <style scoped lang="scss">
  76. </style>