en-nav.vue 3.9 KB

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