u-navbar-mini.vue 4.0 KB

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