猫妈狗爸伴宠师小程序前端代码
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.

139 lines
4.0 KiB

  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>