en-nav.vue 3.8 KB

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