You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.4 KiB

2 months ago
  1. <template>
  2. <view
  3. :style="[style]"
  4. class="u-status-bar"
  5. >
  6. <slot />
  7. </view>
  8. </template>
  9. <script>
  10. import { props } from './props';
  11. import { mpMixin } from '../../libs/mixin/mpMixin';
  12. import { mixin } from '../../libs/mixin/mixin';
  13. import { addUnit, addStyle, deepMerge, sys } from '../../libs/function/index';
  14. /**
  15. * StatbusBar 状态栏占位
  16. * @description 本组件主要用于状态填充比如在自定导航栏的时候它会自动适配一个恰当的状态栏高度
  17. * @tutorial https://uview-plus.jiangruyi.com/components/statusBar.html
  18. * @property {String} bgColor 背景色 (默认 'transparent' )
  19. * @property {String | Object} customStyle 自定义样式
  20. * @example <u-status-bar></u-status-bar>
  21. */
  22. export default {
  23. name: 'u-status-bar',
  24. mixins: [mpMixin, mixin, props],
  25. data() {
  26. return {
  27. }
  28. },
  29. computed: {
  30. style() {
  31. const style = {}
  32. // 状态栏高度,由于某些安卓和微信开发工具无法识别css的顶部状态栏变量,所以使用js获取的方式
  33. style.height = addUnit(sys().statusBarHeight, 'px')
  34. style.backgroundColor = this.bgColor
  35. return deepMerge(style, addStyle(this.customStyle))
  36. }
  37. },
  38. }
  39. </script>
  40. <style lang="scss" scoped>
  41. .u-status-bar {
  42. // nvue会默认100%,如果nvue下,显式写100%的话,会导致宽度不为100%而异常
  43. /* #ifndef APP-NVUE */
  44. width: 100%;
  45. /* #endif */
  46. }
  47. </style>