index.vue 2.54 KB
Newer Older
Nature's avatar
Nature committed
1 2 3 4 5 6
/**
* @Author Think
* @Date 2018/11/24
*/

<template>
Nature's avatar
Nature committed
7
  <section :class="cusClass" class="content">
Nature's avatar
Nature committed
8 9 10 11 12 13 14 15 16 17 18 19
    <slot/>
  </section>
</template>

<script>
export default {
  name: 'HContent',
  props: {
    cusClass: {
      type: String,
      default: '',
    },
20 21 22 23
    calContent: {
      type: Boolean,
      default: true,
    },
Nature's avatar
Nature committed
24
  },
25
  mounted () {
26 27 28 29 30 31 32 33
    if (this.calContent) {
      this.contentHeight()
    }
  },
  activated () {
    if (this.calContent) {
      this.contentHeight()
    }
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
  },
  methods: {
    getHeader () {
      let $el = this.$el.previousElementSibling
      do {
        if ($el) {
          if ($el._prevClass.indexOf('h-header') !== -1) {
            break
          }
          $el = $el.previousElementSibling
        }
      } while ($el)

      return $el
    },
    getNextElementHeight () {
      let nextElement = this.$el.nextElementSibling
      let height = 0
      if (nextElement) {
        height = window.getComputedStyle(nextElement).height
        if (height) {
          height = Number(height.replace('px', ''))
        }
      }
      return height
    },
    contentHeight () {
61
      // const headerEl = this.getHeader()
62
      const nextHeight = this.getNextElementHeight()
63 64 65 66 67 68 69 70 71 72 73 74 75 76
      /* const winHeight = window.innerHeight
         const winWidth = window.innerWidth
         let paddingHeight = 0
         if (headerEl) {
           if (detectOS() === 'ios' && winWidth === 375 && winHeight === 812) {
             paddingHeight = 40
           } else if (detectOS() === 'ios' && winWidth === 414 && winHeight === 896) {
             paddingHeight = 40
           } else if (detectOS() === 'ios') {
             paddingHeight = 20
           } else {
             paddingHeight = 0
           }
         } */
77 78
      let content = this.$el
      let offsetTop = content.offsetTop
79 80 81 82
      if (offsetTop >= window.innerHeight) {
        offsetTop = 0
      }
      content.style.height = (window.innerHeight - offsetTop - nextHeight) + 'px'
83 84
    },
  },
Nature's avatar
Nature committed
85 86 87 88
}
</script>

<style lang="less">
Nature's avatar
Nature committed
89 90 91 92 93 94 95
  .content {
    flex: 1;
    overflow: hidden;
    background-color: #fafafa;
    position: relative;
    overflow-y: scroll;
    height: 100%;
JingChao's avatar
JingChao committed
96 97
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
Nature's avatar
Nature committed
98 99 100 101 102 103
  }

  // iPhoneX适配
  @media (device-width: 375px) and (device-height: 812px) and (-webkit-min-device-pixel-ratio: 3) {
    .platform-ios {
      .has-header {
JingChao's avatar
JingChao committed
104
        top: 84px;
Nature's avatar
Nature committed
105 106 107 108 109 110 111 112
      }
    }
  }

  // iPhoneX Max适配
  @media (device-width: 414px) and (device-height: 896px) {
    .platform-ios {
      .has-header {
JingChao's avatar
JingChao committed
113
        top: 84px;
Nature's avatar
Nature committed
114 115 116 117
      }
    }
  }
</style>