en-nav.vue 4.2 KB

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