uni-nav-bar.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <view class="uni-navbar">
  3. <view :class="{'uni-navbar--fixed': fixed,'uni-navbar--shadow':border,'uni-navbar--border':border}" :style="{'background-color':backgroundColor}" class="uni-navbar__content">
  4. <uni-status-bar v-if="statusBar" />
  5. <view :style="{color:color}" class="uni-navbar__header uni-navbar__content_view">
  6. <view class="uni-navbar__header-btns uni-navbar__content_view" @tap="onClickLeft">
  7. <view v-if="leftIcon.length" class="uni-navbar__content_view">
  8. <uni-icons :type="leftIcon" :color="color" size="24" />
  9. </view>
  10. <view v-if="leftText.length" :class="{'uni-navbar-btn-icon-left':!leftIcon.length}" class="uni-navbar-btn-text uni-navbar__content_view">{{ leftText }}</view>
  11. <slot name="left" />
  12. </view>
  13. <view class="uni-navbar__header-container uni-navbar__content_view">
  14. <view v-if="title.length" class="uni-navbar__header-container-inner uni-navbar__content_view">{{ title }}</view>
  15. <!-- 标题插槽 -->
  16. <slot />
  17. </view>
  18. <view :class="title.length?'uni-navbar__header-btns-right':''" class="uni-navbar__header-btns uni-navbar__content_view" @tap="onClickRight">
  19. <view v-if="rightIcon.length" class="uni-navbar__content_view">
  20. <uni-icons :type="rightIcon" :color="color" size="24" />
  21. </view>
  22. <!-- 优先显示图标 -->
  23. <view v-if="rightText.length&&!rightIcon.length" class="uni-navbar-btn-text uni-navbar__content_view">{{ rightText }}</view>
  24. <slot name="right" />
  25. </view>
  26. </view>
  27. </view>
  28. <view v-if="fixed" class="uni-navbar__placeholder">
  29. <uni-status-bar v-if="statusBar" />
  30. <view class="uni-navbar__placeholder-view" />
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import uniStatusBar from '../uni-status-bar/uni-status-bar.vue'
  36. import uniIcons from '../uni-icons/uni-icons.vue'
  37. export default {
  38. name: 'UniNavBar',
  39. components: {
  40. uniStatusBar,
  41. uniIcons
  42. },
  43. props: {
  44. title: {
  45. type: String,
  46. default: ''
  47. },
  48. leftText: {
  49. type: String,
  50. default: ''
  51. },
  52. rightText: {
  53. type: String,
  54. default: ''
  55. },
  56. leftIcon: {
  57. type: String,
  58. default: ''
  59. },
  60. rightIcon: {
  61. type: String,
  62. default: ''
  63. },
  64. fixed: {
  65. type: [Boolean, String],
  66. default: false
  67. },
  68. color: {
  69. type: String,
  70. default: '#000000'
  71. },
  72. backgroundColor: {
  73. type: String,
  74. default: '#FFFFFF'
  75. },
  76. statusBar: {
  77. type: [Boolean, String],
  78. default: false
  79. },
  80. shadow: {
  81. type: [String, Boolean],
  82. default: true
  83. },
  84. border: {
  85. type: [String, Boolean],
  86. default: true
  87. }
  88. },
  89. methods: {
  90. onClickLeft() {
  91. this.$emit('click-left')
  92. },
  93. onClickRight() {
  94. this.$emit('click-right')
  95. }
  96. }
  97. }
  98. </script>
  99. <style>
  100. @charset "UTF-8";
  101. .uni-navbar__content {
  102. display: block;
  103. position: relative;
  104. width: 100%;
  105. background-color: #fff;
  106. overflow: hidden
  107. }
  108. .uni-navbar__content .uni-navbar__content_view {
  109. display: flex;
  110. align-items: center
  111. }
  112. .uni-navbar__header {
  113. display: flex;
  114. flex-direction: row;
  115. width: 100%;
  116. height: 44px;
  117. line-height: 44px;
  118. font-size: 16px
  119. }
  120. .uni-navbar__header-btns {
  121. display: inline-flex;
  122. flex-wrap: nowrap;
  123. flex-shrink: 0;
  124. width: 120upx;
  125. padding: 0 12upx
  126. }
  127. .uni-navbar__header-btns:first-child {
  128. padding-left: 0
  129. }
  130. .uni-navbar__header-btns:last-child {
  131. width: 60upx
  132. }
  133. .uni-navbar__header-btns-right:last-child {
  134. width: 120rpx;
  135. text-align: right;
  136. flex-direction: row-reverse
  137. }
  138. .uni-navbar__header-container {
  139. width: 100%;
  140. margin: 0 10upx
  141. }
  142. .uni-navbar__header-container-inner {
  143. width: 100%;
  144. display: flex;
  145. justify-content: center;
  146. font-size: 30upx
  147. }
  148. .uni-navbar__placeholder-view {
  149. height: 44px
  150. }
  151. .uni-navbar--fixed {
  152. position: fixed;
  153. z-index: 998
  154. }
  155. .uni-navbar--shadow {
  156. box-shadow: 0 1px 6px #ccc
  157. }
  158. .uni-navbar--border:after {
  159. position: absolute;
  160. z-index: 3;
  161. bottom: 0;
  162. left: 0;
  163. right: 0;
  164. height: 1px;
  165. content: '';
  166. -webkit-transform: scaleY(.5);
  167. transform: scaleY(.5);
  168. background-color: #e5e5e5
  169. }
  170. </style>