u-navbar-mini.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <view class="u-navbar-mini" :class="[customClass]">
  3. <view class="u-navbar-mini__inner" :class="[fixed && 'u-navbar-mini--fixed']">
  4. <u-status-bar
  5. v-if="safeAreaInsetTop"
  6. ></u-status-bar>
  7. <view
  8. class="u-navbar-mini__content"
  9. :style="{
  10. height: addUnit(height),
  11. backgroundColor: bgColor,
  12. }"
  13. >
  14. <view
  15. class="u-navbar-mini__content__left"
  16. hover-class="u-navbar-mini__content__left--hover"
  17. hover-start-time="150"
  18. @tap="leftClick"
  19. >
  20. <slot name="left">
  21. <up-icon
  22. :name="leftIcon"
  23. :size="iconSize"
  24. :color="iconColor"
  25. ></up-icon>
  26. </slot>
  27. </view>
  28. <view style="padding: 10px 10px;">
  29. <up-line direction="col" color="#fff" length="16px"></up-line>
  30. </view>
  31. <view
  32. class="u-navbar-mini__content__center" @tap="homeClick">
  33. <slot name="center">
  34. <up-icon name="home" :size="iconSize" :color="iconColor"></up-icon>
  35. </slot>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import { props } from './props';
  43. import { mpMixin } from '../../libs/mixin/mpMixin';
  44. import { mixin } from '../../libs/mixin/mixin';
  45. import { addUnit, addStyle, getPx, sys } from '../../libs/function/index';
  46. /**
  47. * NavbarMini 迷你导航栏
  48. * @description 此组件一般用于在全屏页面中,典型的如微信小程序左上角。
  49. * @tutorial https://ijry.github.io/uview-plus/components/navbar-mini.html
  50. * @property {Boolean} safeAreaInsetTop 是否开启顶部安全区适配 (默认 true )
  51. * @property {Boolean} placeholder 固定在顶部时,是否生成一个等高元素,以防止塌陷 (默认 false )
  52. * @property {Boolean} fixed 导航栏是否固定在顶部 (默认 false )
  53. * @property {String} leftIcon 左边返回图标的名称,只能为uView自带的图标 (默认 'arrow-left' )
  54. * @property {String} title 导航栏标题,如设置为空字符,将会隐藏标题占位区域
  55. * @property {String} bgColor 导航栏背景设置 (默认 '#ffffff' )
  56. * @property {String | Number} height 导航栏高度(不包括状态栏高度在内,内部自动加上)(默认 '44px' )
  57. * @property {String | Number} iconSize 左侧返回图标的大小(默认 20px )
  58. * @property {String | Number} leftIconColor 左侧返回图标的颜色(默认 #303133 )
  59. * @property {Boolean} autoBack 点击左侧区域(返回图标),是否自动返回上一页(默认 false )
  60. * @property {Object | String} titleStyle 标题的样式,对象或字符串
  61. * @event {Function} leftClick 点击左侧区域
  62. * @event {Function} rightClick 点击右侧区域
  63. * @example <u-navbar-mini @click-left="onClickBack"></u-navbar-mini>
  64. */
  65. export default {
  66. name: 'u-navbar-mini',
  67. mixins: [mpMixin, mixin, props],
  68. data() {
  69. return {
  70. }
  71. },
  72. emits: ["leftClick", "homeClick"],
  73. created() {
  74. },
  75. methods: {
  76. addStyle,
  77. addUnit,
  78. sys,
  79. getPx,
  80. // 点击左侧区域
  81. leftClick() {
  82. // 如果配置了autoBack,自动返回上一页
  83. this.$emit('leftClick')
  84. if(this.autoBack) {
  85. uni.navigateBack()
  86. }
  87. },
  88. homeClick() {
  89. if (this.homeUrl) {
  90. uni.reLaunch({ url: this.homeUrl })
  91. }
  92. }
  93. }
  94. }
  95. </script>
  96. <style lang="scss" scoped>
  97. .u-navbar-mini {
  98. &__inner {
  99. width: 180rpx;
  100. overflow: hidden;
  101. }
  102. &--fixed {
  103. position: fixed;
  104. left: 20px;
  105. right: 0;
  106. top: 10px;
  107. z-index: 11;
  108. }
  109. &__content {
  110. @include flex(row);
  111. padding: 0 15px;
  112. border-radius: 20px;
  113. align-items: center;
  114. height: 36px;
  115. background-color: #9acafc;
  116. position: relative;
  117. justify-content: space-between;
  118. &__left {
  119. @include flex(row);
  120. align-items: center;
  121. }
  122. &__left {
  123. &--hover {
  124. opacity: 0.7;
  125. }
  126. }
  127. }
  128. }
  129. </style>