en-nav.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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" v-if="leftShow">
  12. <uni-icons type="left" :color="leftColor" size="18" ></uni-icons>
  13. </view>
  14. <view v-if="!customNav" class="title-text">{{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. bgckgroundBox: {
  63. type: String,
  64. default: '#fff'
  65. },
  66. titleColor: {
  67. type: String,
  68. default: '#fff'
  69. },
  70. bgColor: {
  71. type: String,
  72. default: '#707'
  73. },
  74. rightText: {
  75. type: String,
  76. default: ''
  77. },
  78. rightShow: {
  79. type: Boolean,
  80. default: false
  81. },
  82. rightType: {
  83. default: 1
  84. },
  85. },
  86. computed: {
  87. style() {
  88. let _style = `height: ${this.customBarH}px;`
  89. return _style
  90. }
  91. },
  92. watch: {
  93. leftShow(e) {
  94. if (e == true) {
  95. this.left = 0
  96. }
  97. }
  98. },
  99. methods: {
  100. rightClick() {
  101. this.$emit('rightClick')
  102. },
  103. goBack() {
  104. if(!this.leftShow){
  105. return ;
  106. }
  107. tools.leftClick()
  108. }
  109. },
  110. created() {
  111. uni.getSystemInfo({
  112. success: (e) =>{
  113. this.statusBarH = e.statusBarHeight + 10
  114. let custom=0;
  115. //#ifdef MP-WEIXIN
  116. custom = wx.getMenuButtonBoundingClientRect()
  117. this.customBarH = custom.height
  118. //#endif
  119. //#ifdef H5
  120. this.customBarH = 30
  121. this.left=0
  122. //#endif
  123. this.$emit('navHeight', this.customBarH-10)
  124. }
  125. })
  126. //#ifdef MP-WEIXIN
  127. this.isXcx=true
  128. //#endif
  129. }
  130. }
  131. </script>
  132. <style scoped lang="scss">
  133. @import url("../../static/css/en-common.css") ;
  134. .header {
  135. width: 100vw;
  136. position: fixed;
  137. left: 0;
  138. top: 0;
  139. z-index: 999999;
  140. .flexbox {
  141. // display: flex;
  142. // align-items: center;
  143. // justify-content: space-between;
  144. padding: 0 24rpx;
  145. .iconfont{
  146. color: #333333;
  147. font-size: 34rpx;
  148. }
  149. .title-text {
  150. font-size: 36rpx;
  151. font-weight: 600;
  152. }
  153. .icon-left {
  154. width: 20px;
  155. height: 20px;
  156. }
  157. .button {
  158. position: relative;
  159. z-index: 5;
  160. // width: 21px;
  161. .rightName {
  162. font-size: 14px;
  163. color: #333333;
  164. }
  165. .r-but{
  166. background-color:#FF0000 ;
  167. color: #fff;
  168. font-size: 12px;
  169. padding: 5px;
  170. border-radius: 3px;
  171. }
  172. }
  173. }
  174. .flexbox-xcx{
  175. justify-content:left;
  176. position: relative;
  177. .right-button{
  178. position: absolute;
  179. right: 220rpx;
  180. }
  181. }
  182. }
  183. .w-right{
  184. width: 20rpx;
  185. }
  186. .box-title {
  187. width: 100vw;
  188. }
  189. </style>