IndexBanner.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <template>
  2. <swiper class="index-banner" :class="{'full':full}" :autoplay="true" v-bind:style="'width:'+getBannerStyle.width+'px;height:'+getBannerStyle.height+'px'" :indicator-dots="isShowIndicators">
  3. <swiper-item v-for="(item, index) in items" :key="index">
  4. <view class="div banner-wrapper"><image mode="aspectFit" class="img banner-image" :src="item.adv_code" v-if='item.adv_code' @click="goAdUrl(item)"></view>
  5. </swiper-item>
  6. </swiper>
  7. </template>
  8. <script>
  9. import { urlencode } from '@/util/common'
  10. export default {
  11. name: 'IndexBanner',
  12. data () {
  13. return {
  14. }
  15. },
  16. props: ['items','full'],
  17. computed: {
  18. getBannerStyle: function () {
  19. const res = uni.getSystemInfoSync()
  20. var width = res.windowWidth
  21. var height = res.windowHeight
  22. let itemWidth = width
  23. let itemHeight = width * (300 / 702)
  24. return {
  25. width: itemWidth,
  26. height: itemHeight
  27. }
  28. },
  29. isShowIndicators () {
  30. if (this.items && this.items.length > 1) {
  31. return true
  32. }
  33. return false
  34. }
  35. },
  36. methods: {
  37. goAdUrl (item) {
  38. uni.navigateTo({url:item.adv_typedate})
  39. }
  40. }
  41. }
  42. </script>
  43. <style scoped lang="scss">
  44. .index-banner{padding-top:$modelSpace;padding-bottom:1.5rem;background: #fff;
  45. .banner-wrapper{position:absolute;top:0;bottom:0;left:$pageSpace;right:$pageSpace;
  46. .banner-image{width:100%;height:100%;border-radius:.4rem;}
  47. }
  48. }
  49. .index-banner.full{padding-top:0;
  50. .banner-wrapper{left:0;right:0;
  51. .banner-image{border-radius:0}
  52. }
  53. }
  54. </style>