pageBody.vue 2.1 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<template>
  <uni-page-wrapper>
    <uni-page-body>
      <slot />
    </uni-page-body>
  </uni-page-wrapper>
</template>
<style>
uni-page-wrapper {
  display: block;
  height: 100%;
  position: relative;
}

15
uni-page-head[uni-page-head-type="default"] ~ uni-page-wrapper {
fxy060608's avatar
fxy060608 已提交
16
  height: calc(100% - 44px);
Q
qiang 已提交
17 18
  height: calc(100% - 44px - constant(safe-area-inset-top));
  height: calc(100% - 44px - env(safe-area-inset-top));
fxy060608's avatar
fxy060608 已提交
19 20 21 22 23 24 25
}

uni-page-body {
  display: block;
  box-sizing: border-box;
  width: 100%;
}
26 27 28 29 30 31 32

@media (prefers-color-scheme: dark) {
  uni-page-body {
    background-color: #191919;
    color: hsla(0, 0%, 100%, 0.8);
  }
}
fxy060608's avatar
fxy060608 已提交
33 34
</style>
<script>
35 36
import appendCss from 'uni-platform/helpers/append-css'
import { tabBar } from '../app/observable'
fxy060608's avatar
fxy060608 已提交
37
export default {
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  name: 'PageBody',
  mounted () {
    const HEIGTH = tabBar.height || '50px'
    let cssText = `.uni-app--showtabbar uni-page-wrapper {
                    display: block;
                    height: calc(100% - ${HEIGTH});
                    height: calc(100% - ${HEIGTH} - constant(safe-area-inset-bottom));
                    height: calc(100% - ${HEIGTH} - env(safe-area-inset-bottom));
                  }`
    cssText += '\n'
    cssText += `.uni-app--showtabbar uni-page-wrapper::after {
                  content: "";
                  display: block;
                  width: 100%;
                  height: ${HEIGTH};
                  height: calc(${HEIGTH} + constant(safe-area-inset-bottom));
                  height: calc(${HEIGTH} + env(safe-area-inset-bottom));
                }`
    cssText += '\n'
    cssText += `.uni-app--showtabbar uni-page-head[uni-page-head-type="default"] ~ uni-page-wrapper {
                  height: calc(100% - 44px - ${HEIGTH});
                  height: calc(100% - 44px - constant(safe-area-inset-top) - ${HEIGTH} - constant(safe-area-inset-bottom));
                  height: calc(100% - 44px - env(safe-area-inset-top) - ${HEIGTH} - env(safe-area-inset-bottom));
                }`
    appendCss(cssText)
  }
fxy060608's avatar
fxy060608 已提交
64 65
}
</script>