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

151 lines
3.3 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. indicator-active-color="#186c6b"
  29. >
  30. <swiper-item v-for="(item, index) in bannerData" :key="index">
  31. <image mode="widthFix" :src="item.image" :data-src="item.link" class="slide-image" @load="_imgLoad" @tap="_jumpImg"></image>
  32. </swiper-item>
  33. </swiper>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. // 对应data
  41. data() {
  42. return {
  43. imgHeight: '450'
  44. };
  45. },
  46. options: {
  47. addGlobalClass: true,
  48. },
  49. // 对应properties里面的字段
  50. props: {
  51. //轮播图数据
  52. bannerData: {
  53. type: Array,
  54. value: ''
  55. },
  56. screenWidth: {
  57. type: String,
  58. value: ''
  59. },
  60. bannerTitle: {
  61. type: String,
  62. value: ''
  63. },
  64. show: {
  65. type: Number,
  66. value: ''
  67. },
  68. meta: {
  69. type: Object,
  70. value: ""
  71. }
  72. },
  73. // 对应methods
  74. methods: {
  75. //内部方法建议以下划线开头
  76. _imgLoad(e) {
  77. return; // PS 不执行自动高
  78. var height = e.detail.height;
  79. var width = e.detail.width;
  80. var ratio = width / height;
  81. var screenWidth = this.screenWidth;
  82. if(this.meta && this.meta.padding_left){
  83. this.imgHeight = screenWidth / ratio - this.meta.padding_left
  84. } else{
  85. this.imgHeight = screenWidth / ratio
  86. }
  87. },
  88. _jumpImg(e) {
  89. var src = e.currentTarget.dataset.src;
  90. if (!src || src == 'uto_miniprogram') return;
  91. wx.navigateTo({
  92. url: src,
  93. fail: err => {
  94. wx.switchTab({
  95. url: src
  96. });
  97. }
  98. });
  99. },
  100. },
  101. };
  102. </script>
  103. <!-- 复制之前的less放进来就可以 -->
  104. <style lang="less" scoped>
  105. .index-banner{
  106. // height: 900rpx;
  107. //margin-bottom: 10px;
  108. .banner-title{
  109. padding: 10px 15px 10px 15px;
  110. display: flex;
  111. justify-content: space-between;
  112. color: #000;
  113. align-items: center;
  114. background: #FFFFFF;
  115. span:nth-child(1) {
  116. font-size: 24px;
  117. font-weight: bold;
  118. line-height: 33px;
  119. display: inline-block;
  120. //padding-left: 6px;
  121. //border-left: 4px solid #E7031C;
  122. }
  123. span:nth-child(2) {
  124. font-size: 12px;
  125. display: flex;
  126. align-items: center;
  127. text{
  128. font-size: 15px;
  129. font-weight: 700;
  130. margin-left: 5px;
  131. }
  132. }
  133. }
  134. .banner {
  135. background: #FFFFFF;
  136. height: 100%;
  137. image {
  138. width: 100%;
  139. height: 100% !important;
  140. object-fit: cover;
  141. vertical-align: middle !important;
  142. border-radius: 0 0 30rpx 30rpx;
  143. }
  144. }
  145. }
  146. </style>