en-nav.vue 3.7 KB

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