en-nav.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <view class="">
  3. <view class="header" :style="style">
  4. <view class="flexbox" :class="{
  5. 'flexbox-xcx':(isXcx && rightShow),
  6. 'flex-justify-space':!customNav,
  7. 'align-items-center':!customNav,
  8. }" :style="[{'height': customBarH + 'px', 'padding-top': statusBarH + 'px','background':bgckgroundBox}]">
  9. <view @tap="goBack" v-if="leftShow">
  10. <uni-icons type="left" :color="leftColor" size="18"></uni-icons>
  11. <!-- <image class="toLeft" src="@/static/img/toLeft.png" mode=""></image> -->
  12. </view>
  13. <view v-if="!customNav" :style="[{'color': titleColor}]" class="title-text text-overflow-ellipsis-one">
  14. {{title}}</view>
  15. <view v-else class="">
  16. <slot name="custom"></slot>
  17. </view>
  18. <view v-if="rightShow" class="right-button button" @click="rightClick">
  19. <slot name="right">
  20. <text class="rightName" v-if="rightType===1">{{rightText}}</text>
  21. <text class="rightName r-but" v-else>{{rightText}}</text>
  22. </slot>
  23. </view>
  24. <view v-else class="w-right"></view>
  25. </view>
  26. </view>
  27. <view class="box-title">
  28. <view class="" :style="[{'height': customBarH + 'px', 'padding-top': statusBarH + 'px'}]">
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import tools from "@/service/tools";
  35. export default {
  36. name: "en-nav",
  37. data() {
  38. return {
  39. statusBarH: 0,
  40. customBarH: 0,
  41. left: 35,
  42. isXcx: false
  43. }
  44. },
  45. props: {
  46. title: {
  47. type: String,
  48. default: ''
  49. },
  50. customNav: {
  51. type: Boolean,
  52. default: false
  53. },
  54. leftColor: {
  55. type: String,
  56. default: '#333'
  57. },
  58. leftShow: {
  59. type: Boolean,
  60. default: true
  61. },
  62. letTap: {
  63. type: Boolean,
  64. default: false
  65. },
  66. bgckgroundBox: {
  67. type: String,
  68. default: '#fff'
  69. },
  70. titleColor: {
  71. type: String,
  72. default: '#333'
  73. },
  74. bgColor: {
  75. type: String,
  76. default: '#707'
  77. },
  78. rightText: {
  79. type: String,
  80. default: ''
  81. },
  82. rightShow: {
  83. type: Boolean,
  84. default: false
  85. },
  86. rightType: {
  87. default: 1
  88. },
  89. },
  90. computed: {
  91. style() {
  92. let _style = `height: ${this.customBarH}px;`
  93. return _style
  94. }
  95. },
  96. watch: {
  97. leftShow(e) {
  98. if (e == true) {
  99. this.left = 0
  100. }
  101. }
  102. },
  103. methods: {
  104. rightClick() {
  105. this.$emit('rightClick')
  106. },
  107. goBack() {
  108. if (!this.leftShow) {
  109. return;
  110. }
  111. if (this.letTap) {
  112. this.$emit('goBack')
  113. } else {
  114. tools.leftClick()
  115. }
  116. }
  117. },
  118. created() {
  119. uni.getSystemInfo({
  120. success: (e) => {
  121. this.statusBarH = e.statusBarHeight + 10
  122. let custom = 0;
  123. //#ifdef MP-WEIXIN
  124. custom = wx.getMenuButtonBoundingClientRect()
  125. this.customBarH = custom.height
  126. //#endif
  127. //#ifdef H5
  128. this.customBarH = 30
  129. this.left = 0
  130. //#endif
  131. this.$emit('navHeight', this.customBarH - 10)
  132. }
  133. })
  134. //#ifdef MP-WEIXIN
  135. this.isXcx = true
  136. //#endif
  137. }
  138. }
  139. </script>
  140. <style scoped lang="scss">
  141. @import url("../../static/css/en-common.css");
  142. .toLeft {
  143. width: 44rpx;
  144. height: 44rpx;
  145. }
  146. .header {
  147. width: 100vw;
  148. position: fixed;
  149. left: 0;
  150. top: 0;
  151. z-index: 999999;
  152. .flexbox {
  153. // display: flex;
  154. // align-items: center;
  155. // justify-content: space-between;
  156. transition: background-color 1s ease-in-out;
  157. padding: 0 24rpx;
  158. .iconfont {
  159. color: #333333;
  160. font-size: 34rpx;
  161. }
  162. .title-text {
  163. max-width: 275rpx;
  164. font-size: 36rpx;
  165. font-weight: 600;
  166. }
  167. .icon-left {
  168. width: 20px;
  169. height: 20px;
  170. }
  171. .button {
  172. position: relative;
  173. z-index: 5;
  174. // width: 21px;
  175. .rightName {
  176. font-size: 14px;
  177. color: #333333;
  178. }
  179. .r-but {
  180. background-color: #FF0000;
  181. color: #fff;
  182. font-size: 12px;
  183. padding: 5px;
  184. border-radius: 3px;
  185. }
  186. }
  187. }
  188. .flexbox-xcx {
  189. justify-content: left;
  190. position: relative;
  191. .right-button {
  192. position: absolute;
  193. right: 220rpx;
  194. }
  195. }
  196. }
  197. .w-right {
  198. width: 20rpx;
  199. }
  200. .box-title {
  201. width: 100vw;
  202. }
  203. </style>