uni-nav-bar.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view class="uni-navbar">
  3. <view :class="{ 'uni-navbar--fixed': fixed, 'uni-navbar--shadow': false, 'uni-navbar--border': false }" :style="{ 'background-color': backgroundColor }"
  4. class="uni-navbar__content">
  5. <uni-status-bar v-if="statusBar" />
  6. <view :style="{ color: color,backgroundColor: backgroundColor }" class="uni-navbar__header uni-navbar__content_view">
  7. <view @tap="onClickLeft" class="uni-navbar__header-btns uni-navbar__header-btns-left uni-navbar__content_view">
  8. <view class="uni-navbar__content_view" v-if="leftIcon.length">
  9. <uni-icons :color="color" :type="leftIcon" size="24" />
  10. </view>
  11. <view :class="{ 'uni-navbar-btn-icon-left': !leftIcon.length }" class="uni-navbar-btn-text uni-navbar__content_view"
  12. v-if="leftText.length">
  13. <text :style="{ color: color, fontSize: '14px' }">{{ leftText }}</text>
  14. </view>
  15. <slot name="left" />
  16. </view>
  17. <view class="uni-navbar__header-container uni-navbar__content_view">
  18. <view class="uni-navbar__header-container-inner uni-navbar__content_view" v-if="title.length">
  19. <text class="uni-nav-bar-text" :style="{color: color }">{{ title }}</text>
  20. </view>
  21. <!-- 标题插槽 -->
  22. <slot />
  23. </view>
  24. <view :class="title.length ? 'uni-navbar__header-btns-right' : ''" @tap="onClickRight" class="uni-navbar__header-btns uni-navbar__content_view">
  25. <view class="uni-navbar__content_view" v-if="rightIcon.length">
  26. <uni-icons :color="color" :type="rightIcon" size="24" />
  27. </view>
  28. <!-- 优先显示图标 -->
  29. <view class="uni-navbar-btn-text uni-navbar__content_view" v-if="rightText.length && !rightIcon.length">
  30. <text class="uni-nav-bar-right-text">{{ rightText }}</text>
  31. </view>
  32. <slot name="right" />
  33. </view>
  34. </view>
  35. </view>
  36. <view class="uni-navbar__placeholder" v-if="fixed">
  37. <uni-status-bar v-if="statusBar" />
  38. <view class="uni-navbar__placeholder-view" />
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import uniStatusBar from "../uni-status-bar/uni-status-bar.vue";
  44. import uniIcons from "../uni-icons/uni-icons.vue";
  45. export default {
  46. name: "UniNavBar",
  47. components: {
  48. uniStatusBar,
  49. uniIcons
  50. },
  51. props: {
  52. title: {
  53. type: String,
  54. default: ""
  55. },
  56. leftText: {
  57. type: String,
  58. default: ""
  59. },
  60. rightText: {
  61. type: String,
  62. default: ""
  63. },
  64. leftIcon: {
  65. type: String,
  66. default: ""
  67. },
  68. rightIcon: {
  69. type: String,
  70. default: ""
  71. },
  72. fixed: {
  73. type: [Boolean, String],
  74. default: false
  75. },
  76. color: {
  77. type: String,
  78. default: "#000000"
  79. },
  80. backgroundColor: {
  81. type: String,
  82. default: "#FFFFFF"
  83. },
  84. statusBar: {
  85. type: [Boolean, String],
  86. default: false
  87. },
  88. shadow: {
  89. type: [String, Boolean],
  90. default: false
  91. },
  92. border: {
  93. type: [String, Boolean],
  94. default: true
  95. }
  96. },
  97. mounted() {
  98. if(uni.report && this.title !== '') {
  99. uni.report('title', this.title)
  100. }
  101. },
  102. methods: {
  103. onClickLeft() {
  104. this.$emit("clickLeft");
  105. },
  106. onClickRight() {
  107. this.$emit("clickRight");
  108. }
  109. }
  110. };
  111. </script>
  112. <style lang="scss" scoped>
  113. $nav-height: 44px;
  114. .uni-nav-bar-text {
  115. /* #ifdef APP-PLUS */
  116. font-size: 34rpx;
  117. /* #endif */
  118. /* #ifndef APP-PLUS */
  119. font-size: $uni-font-size-lg;
  120. /* #endif */
  121. }
  122. .uni-nav-bar-right-text {
  123. font-size: $uni-font-size-base;
  124. }
  125. .uni-navbar {
  126. width: 750rpx;
  127. }
  128. .uni-navbar__content {
  129. position: relative;
  130. width: 750rpx;
  131. background-color: $uni-bg-color;
  132. overflow: hidden;
  133. }
  134. .uni-navbar__content_view {
  135. /* #ifndef APP-NVUE */
  136. display: flex;
  137. /* #endif */
  138. align-items: center;
  139. flex-direction: row;
  140. // background-color: #FFFFFF;
  141. }
  142. .uni-navbar__header {
  143. /* #ifndef APP-NVUE */
  144. display: flex;
  145. /* #endif */
  146. flex-direction: row;
  147. width: 750rpx;
  148. height: $nav-height;
  149. line-height: $nav-height;
  150. font-size: 16px;
  151. // background-color: #ffffff;
  152. }
  153. .uni-navbar__header-btns {
  154. /* #ifndef APP-NVUE */
  155. display: flex;
  156. /* #endif */
  157. flex-wrap: nowrap;
  158. width: 120rpx;
  159. padding: 0 6px;
  160. justify-content: center;
  161. align-items: center;
  162. }
  163. .uni-navbar__header-btns-left {
  164. /* #ifndef APP-NVUE */
  165. display: flex;
  166. /* #endif */
  167. width: 150rpx;
  168. justify-content: flex-start;
  169. }
  170. .uni-navbar__header-btns-right {
  171. /* #ifndef APP-NVUE */
  172. display: flex;
  173. /* #endif */
  174. width: 150rpx;
  175. padding-right: 30rpx;
  176. justify-content: flex-end;
  177. }
  178. .uni-navbar__header-container {
  179. flex: 1;
  180. }
  181. .uni-navbar__header-container-inner {
  182. /* #ifndef APP-NVUE */
  183. display: flex;
  184. /* #endif */
  185. flex: 1;
  186. align-items: center;
  187. justify-content: center;
  188. font-size: $uni-font-size-base;
  189. }
  190. .uni-navbar__placeholder-view {
  191. height: $nav-height;
  192. }
  193. .uni-navbar--fixed {
  194. position: fixed;
  195. z-index: 998;
  196. }
  197. .uni-navbar--shadow {
  198. /* #ifndef APP-NVUE */
  199. box-shadow: 0 1px 6px #ccc;
  200. /* #endif */
  201. }
  202. .uni-navbar--border {
  203. border-bottom-width: 1rpx;
  204. border-bottom-style: solid;
  205. border-bottom-color: $uni-border-color;
  206. }
  207. </style>