u-safe-bottom.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <template>
  2. <view
  3. class="u-safe-bottom"
  4. :style="[style]"
  5. :class="[!isNvue && 'u-safe-area-inset-bottom']"
  6. >
  7. </view>
  8. </template>
  9. <script>
  10. import props from "./props.js";
  11. import mpMixin from '../../libs/mixin/mpMixin.js';
  12. import mixin from '../../libs/mixin/mixin.js';
  13. /**
  14. * SafeBottom 底部安全区
  15. * @description 这个适配,主要是针对IPhone X等一些底部带指示条的机型,指示条的操作区域与页面底部存在重合,容易导致用户误操作,因此我们需要针对这些机型进行底部安全区适配。
  16. * @tutorial https://ijry.github.io/uview-plus/components/safeAreaInset.html
  17. * @property {type} prop_name
  18. * @property {Object} customStyle 定义需要用到的外部样式
  19. *
  20. * @event {Function()}
  21. * @example <u-status-bar></u-status-bar>
  22. */
  23. export default {
  24. name: "u-safe-bottom",
  25. mixins: [mpMixin, mixin, props],
  26. data() {
  27. return {
  28. safeAreaBottomHeight: 0,
  29. isNvue: false,
  30. };
  31. },
  32. computed: {
  33. style() {
  34. const style = {};
  35. // #ifdef APP-NVUE || MP-TOUTIAO
  36. // nvue下,高度使用js计算填充
  37. style.height = uni.$u.addUnit(uni.$u.sys().safeAreaInsets.bottom, 'px');
  38. // #endif
  39. return uni.$u.deepMerge(style, uni.$u.addStyle(this.customStyle));
  40. },
  41. },
  42. mounted() {
  43. // #ifdef APP-NVUE
  44. // 标识为是否nvue
  45. this.isNvue = true;
  46. // #endif
  47. },
  48. };
  49. </script>
  50. <style lang="scss" scoped>
  51. .u-safe-bottom {
  52. /* #ifndef APP-NVUE */
  53. width: 100%;
  54. /* #endif */
  55. }
  56. </style>