uv-status-bar.vue 1.5 KB

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