en-nav.vue 3.9 KB

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