wu-safe-bottom.vue 1.5 KB

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