金诚优选前端代码
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.

147 lines
3.1 KiB

  1. <!-- template只能有一个顶级标签,语法需要改成vue的语法来写 -->
  2. <template>
  3. <view class="index-banner" :style="{marginBottom: meta.margin_bottom + 'px',background: meta.background_color}" v-if="bannerData && bannerData.length">
  4. <view class="banner-title" v-if="bannerTitle && show">
  5. <span>{{ bannerTitle }}</span>
  6. <span data-src="/pages/index/microPages/microPages?id=brand&name=brand" @tap="_jumpImg">
  7. 更多
  8. <text class="iconfont icon-gengduo"></text>
  9. </span>
  10. </view>
  11. <view class="banner">
  12. <view class="top-image">
  13. <swiper
  14. :style="
  15. 'height: ' +
  16. imgHeight +
  17. 'px; padding-left: ' +
  18. meta.padding_left +
  19. 'px; padding-right: ' +
  20. meta.padding_right +
  21. 'px; padding-bottom: ' +
  22. meta.padding_bottom +
  23. 'px; '
  24. "
  25. indicator-dots="true"
  26. autoplay="true"
  27. circular="true"
  28. >
  29. <swiper-item v-for="(item, index) in bannerData" :key="index">
  30. <image mode="widthFix" :src="item.image" :data-src="item.link" class="slide-image" @load="_imgLoad" @tap="_jumpImg"></image>
  31. </swiper-item>
  32. </swiper>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. // 对应data
  40. data() {
  41. return {
  42. imgHeight: ''
  43. };
  44. },
  45. options: {
  46. addGlobalClass: true,
  47. },
  48. // 对应properties里面的字段
  49. props: {
  50. //轮播图数据
  51. bannerData: {
  52. type: Array,
  53. value: ''
  54. },
  55. screenWidth: {
  56. type: String,
  57. value: ''
  58. },
  59. bannerTitle: {
  60. type: String,
  61. value: ''
  62. },
  63. show: {
  64. type: Number,
  65. value: ''
  66. },
  67. meta: {
  68. type: Object,
  69. value: ""
  70. }
  71. },
  72. // 对应methods
  73. methods: {
  74. //内部方法建议以下划线开头
  75. _imgLoad(e) {
  76. var height = e.detail.height;
  77. var width = e.detail.width;
  78. var ratio = width / height;
  79. var screenWidth = this.screenWidth;
  80. if(this.meta && this.meta.padding_left){
  81. this.imgHeight = screenWidth / ratio - this.meta.padding_left
  82. } else{
  83. this.imgHeight = screenWidth / ratio
  84. }
  85. },
  86. _jumpImg(e) {
  87. var src = e.currentTarget.dataset.src;
  88. if (!src || src == 'uto_miniprogram') return;
  89. wx.navigateTo({
  90. url: src,
  91. fail: err => {
  92. wx.switchTab({
  93. url: src
  94. });
  95. }
  96. });
  97. },
  98. },
  99. };
  100. </script>
  101. <!-- 复制之前的less放进来就可以 -->
  102. <style lang="less">
  103. .index-banner{
  104. height: 900rpx;
  105. //margin-bottom: 10px;
  106. .banner-title{
  107. padding: 10px 15px 10px 15px;
  108. display: flex;
  109. justify-content: space-between;
  110. color: #000;
  111. align-items: center;
  112. background: #FFFFFF;
  113. span:nth-child(1) {
  114. font-size: 24px;
  115. font-weight: bold;
  116. line-height: 33px;
  117. display: inline-block;
  118. //padding-left: 6px;
  119. //border-left: 4px solid #E7031C;
  120. }
  121. span:nth-child(2) {
  122. font-size: 12px;
  123. display: flex;
  124. align-items: center;
  125. text{
  126. font-size: 15px;
  127. font-weight: 700;
  128. margin-left: 5px;
  129. }
  130. }
  131. }
  132. .banner {
  133. background: #FFFFFF;
  134. image {
  135. width: 100%;
  136. height: 100%;
  137. object-fit: cover;
  138. }
  139. }
  140. }
  141. </style>