足力健前端,vue版本

uni-nav-bar.vue 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <view class="uni-navbar">
  3. <view :class="{ 'uni-navbar--fixed': fixed, 'uni-navbar--shadow': shadow, 'uni-navbar--border': border }" :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. /**
  46. * NavBar 自定义导航栏
  47. * @description 导航栏组件,主要用于头部导航
  48. * @tutorial https://ext.dcloud.net.cn/plugin?id=52
  49. * @property {String} title 标题文字
  50. * @property {String} leftText 左侧按钮文本
  51. * @property {String} rightText 右侧按钮文本
  52. * @property {String} leftIcon 左侧按钮图标(图标类型参考 [Icon 图标](http://ext.dcloud.net.cn/plugin?id=28) type 属性)
  53. * @property {String} rightIcon 右侧按钮图标(图标类型参考 [Icon 图标](http://ext.dcloud.net.cn/plugin?id=28) type 属性)
  54. * @property {String} color 图标和文字颜色
  55. * @property {String} backgroundColor 导航栏背景颜色
  56. * @property {Boolean} fixed = [true|false] 是否固定顶部
  57. * @property {Boolean} statusBar = [true|false] 是否包含状态栏
  58. * @property {Boolean} shadow = [true|false] 导航栏下是否有阴影
  59. * @event {Function} clickLeft 左侧按钮点击时触发
  60. * @event {Function} clickRight 右侧按钮点击时触发
  61. */
  62. export default {
  63. name: "UniNavBar",
  64. components: {
  65. uniStatusBar,
  66. uniIcons
  67. },
  68. props: {
  69. title: {
  70. type: String,
  71. default: ""
  72. },
  73. leftText: {
  74. type: String,
  75. default: ""
  76. },
  77. rightText: {
  78. type: String,
  79. default: ""
  80. },
  81. leftIcon: {
  82. type: String,
  83. default: ""
  84. },
  85. rightIcon: {
  86. type: String,
  87. default: ""
  88. },
  89. fixed: {
  90. type: [Boolean, String],
  91. default: false
  92. },
  93. color: {
  94. type: String,
  95. default: "#000000"
  96. },
  97. backgroundColor: {
  98. type: String,
  99. default: "#FFFFFF"
  100. },
  101. statusBar: {
  102. type: [Boolean, String],
  103. default: false
  104. },
  105. shadow: {
  106. type: [Boolean, String],
  107. default: false
  108. },
  109. border: {
  110. type: [Boolean, String],
  111. default: true
  112. }
  113. },
  114. mounted() {
  115. if(uni.report && this.title !== '') {
  116. uni.report('title', this.title)
  117. }
  118. },
  119. methods: {
  120. onClickLeft() {
  121. this.$emit("clickLeft");
  122. },
  123. onClickRight() {
  124. this.$emit("clickRight");
  125. }
  126. }
  127. };
  128. </script>
  129. <style lang="scss" scoped>
  130. $nav-height: 44px;
  131. .uni-nav-bar-text {
  132. /* #ifdef APP-PLUS */
  133. font-size: 34rpx;
  134. /* #endif */
  135. /* #ifndef APP-PLUS */
  136. font-size: $uni-font-size-lg;
  137. /* #endif */
  138. }
  139. .uni-nav-bar-right-text {
  140. font-size: $uni-font-size-base;
  141. }
  142. .uni-navbar__content {
  143. position: relative;
  144. background-color: $uni-bg-color;
  145. overflow: hidden;
  146. }
  147. .uni-navbar__content_view {
  148. /* #ifndef APP-NVUE */
  149. display: flex;
  150. /* #endif */
  151. align-items: center;
  152. flex-direction: row;
  153. // background-color: #FFFFFF;
  154. }
  155. .uni-navbar__header {
  156. /* #ifndef APP-NVUE */
  157. display: flex;
  158. /* #endif */
  159. flex-direction: row;
  160. height: $nav-height;
  161. line-height: $nav-height;
  162. font-size: 16px;
  163. // background-color: #ffffff;
  164. }
  165. .uni-navbar__header-btns {
  166. /* #ifndef APP-NVUE */
  167. display: flex;
  168. /* #endif */
  169. flex-wrap: nowrap;
  170. width: 120rpx;
  171. padding: 0 6px;
  172. justify-content: center;
  173. align-items: center;
  174. }
  175. .uni-navbar__header-btns-left {
  176. /* #ifndef APP-NVUE */
  177. display: flex;
  178. /* #endif */
  179. width: 150rpx;
  180. justify-content: flex-start;
  181. }
  182. .uni-navbar__header-btns-right {
  183. /* #ifndef APP-NVUE */
  184. display: flex;
  185. /* #endif */
  186. width: 150rpx;
  187. padding-right: 30rpx;
  188. justify-content: flex-end;
  189. }
  190. .uni-navbar__header-container {
  191. flex: 1;
  192. }
  193. .uni-navbar__header-container-inner {
  194. /* #ifndef APP-NVUE */
  195. display: flex;
  196. /* #endif */
  197. flex: 1;
  198. align-items: center;
  199. justify-content: center;
  200. font-size: $uni-font-size-base;
  201. }
  202. .uni-navbar__placeholder-view {
  203. height: $nav-height;
  204. }
  205. .uni-navbar--fixed {
  206. position: fixed;
  207. z-index: 998;
  208. }
  209. .uni-navbar--shadow {
  210. /* #ifndef APP-NVUE */
  211. box-shadow: 0 1px 6px #ccc;
  212. /* #endif */
  213. }
  214. .uni-navbar--border {
  215. border-bottom-width: 1rpx;
  216. border-bottom-style: solid;
  217. border-bottom-color: $uni-border-color;
  218. }
  219. </style>