navbar.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view id="navbar">
  3. <uv-navbar :title="title" @leftClick="leftClick" :left-icon-color="showLeft
  4. || leftText?color:'transparent'" height="4rem" :safeAreaInsetTop="true" :bgColor="bgColor" :placeholder="place">
  5. <template v-slot:left>
  6. <view class="uv-nav-left" v-if="showLeft">
  7. <uv-icon name="arrow-left" size="1.25rem" :color="leftColor?leftColor:color"></uv-icon>
  8. </view>
  9. <view class="left-text" v-if="leftText">
  10. {{leftText}}
  11. </view>
  12. </template>
  13. <template v-slot:center v-if="title">
  14. <view class="uv-nav-title" :style="'color:'+color">
  15. {{title}}<text v-if="onLine>0"
  16. :class="[onLine==1?'online':'offline']">({{onLine==1?'在线':'离线'}})</text>
  17. </view>
  18. </template>
  19. <template v-slot:right v-if="rightText">
  20. <view class="right-text" v-if="rightUrl" @click="gotoPage(rightUrl)" :style="'color:'+rightTextColor">
  21. {{rightText}}
  22. </view>
  23. <view class="right-text" v-else :style="'color:'+rightTextColor">
  24. {{rightText}}
  25. </view>
  26. </template>
  27. <template v-slot:right v-if="rightIcon">
  28. <uv-image class="right-icon" :src="rightIcon" v-if="rightUrl" :width="righticonSize"
  29. :height="righticonSize" @click="gotoPage(rightUrl)"></uv-image>
  30. <uv-image class="right-icon" :src="rightIcon" :width="righticonSize" :height="righticonSize"
  31. v-else></uv-image>
  32. </template>
  33. </uv-navbar>
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. name: "navbar",
  39. props: {
  40. title: {
  41. type: String,
  42. default: ''
  43. },
  44. color: {
  45. type: String,
  46. default: '#fff'
  47. },
  48. leftColor: {
  49. type: String,
  50. default: ''
  51. },
  52. rightTextColor: {
  53. type: String,
  54. default: '#000'
  55. },
  56. place: {
  57. type: [Boolean, String],
  58. default: true
  59. },
  60. bgColor: {
  61. type: String,
  62. default: 'transparent'
  63. },
  64. showLeft: {
  65. type: [Boolean, Number],
  66. default: true
  67. },
  68. leftUrl: {
  69. type: String,
  70. default: ''
  71. },
  72. leftText: {
  73. type: String,
  74. default: ''
  75. },
  76. rightUrl: {
  77. type: String,
  78. default: ''
  79. },
  80. rightText: {
  81. type: String,
  82. default: ''
  83. },
  84. rightIcon: {
  85. type: String,
  86. default: ''
  87. },
  88. onLine: {
  89. type: Number,
  90. default: 0
  91. },
  92. righticonSize: {
  93. type: String,
  94. default: '1.5rem !important'
  95. },
  96. },
  97. data() {
  98. return {
  99. style: {
  100. color: '#fff',
  101. }
  102. };
  103. },
  104. created() {
  105. },
  106. methods: {
  107. leftClick() {
  108. let _this = this
  109. if (this.showLeft == 2) {
  110. console.log('返回1')
  111. uni.$emit('onBack', '返回')
  112. } else if (this.showLeft) {
  113. uni.$emit('reload', {
  114. msg: '返回刷新'
  115. })
  116. if (this.leftUrl) {
  117. uni.navigateTo({
  118. url: this.leftUrl,
  119. fail() {
  120. uni.switchTab({
  121. url: _this.leftUrl
  122. });
  123. }
  124. });
  125. } else {
  126. console.log('历史返回')
  127. uni.navigateBack();
  128. }
  129. } else {
  130. console.log('不返回')
  131. return false;
  132. }
  133. },
  134. clickRigt() {
  135. this.$emit('clickRight', '点击右侧菜单')
  136. }
  137. }
  138. }
  139. </script>
  140. <style lang="scss" scoped>
  141. #navbar {
  142. position: relative;
  143. z-index: 99;
  144. width: 100%;
  145. // min-height: 80rpx;
  146. }
  147. .icon-left {
  148. margin-left: 20rpx;
  149. }
  150. .left-text {
  151. font-size: 1.125rem;
  152. }
  153. .uv-nav-title {
  154. font-size: 1.125rem;
  155. max-width: 14rem;
  156. font-weight: 500;
  157. white-space: normal;
  158. text-overflow: -o-ellipsis-lastline;
  159. overflow: hidden;
  160. text-overflow: ellipsis;
  161. display: -webkit-box;
  162. -webkit-line-clamp: 1;
  163. line-clamp: 1;
  164. -webkit-box-orient: vertical;
  165. }
  166. .right-text {
  167. font-size: 1rem;
  168. }
  169. .right-icon {
  170. img {
  171. width: 100%;
  172. height: 100%;
  173. }
  174. }
  175. </style>