uni-NavBar.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view class="navbar dis a-c j-s" :style="{background:background}">
  3. <image class="icon-left" :src="backActionimg" mode="" @tap="back()"></image>
  4. <template v-if="!isSlot">
  5. <text class="title font-weight" :style="titleStyle">{{headerTitle}}</text>
  6. <template v-if="!rightSlot">
  7. <view class="dis f-c a-c" :style="{opacity:isShared?1:0}">
  8. <image v-if="rightIcon" class="icon-right" :src="computedRightIcon" mode="" @tap="share">
  9. </image>
  10. <text v-if="rightText" class="right-text" @tap="share" :style="rightTextStyle">{{rightText}}</text>
  11. </view>
  12. </template>
  13. <template v-else>
  14. <view class="dis a-c ">
  15. <slot name="rightSlot">
  16. </slot>
  17. </view>
  18. </template>
  19. </template>
  20. <template v-else>
  21. <slot name="search">
  22. </slot>
  23. </template>
  24. </view>
  25. </template>
  26. <script>
  27. // import {
  28. // turnBase64Image
  29. // } from '@/plugins/utils.js';
  30. export default {
  31. name: 'name', //插件名称
  32. props: {
  33. isSlot: {
  34. type: Boolean,
  35. default: false,
  36. },
  37. rightSlot: {
  38. type: Boolean,
  39. default: false,
  40. },
  41. headerTitle: {
  42. type: String,
  43. default: 'xxxx'
  44. },
  45. background: {
  46. type: String,
  47. default: '#fff'
  48. },
  49. titleStyle: {
  50. type: Object,
  51. default: () => {
  52. return {};
  53. }
  54. },
  55. rightTextStyle: {
  56. type: Object,
  57. default: () => {
  58. return {};
  59. }
  60. },
  61. rightIcon: {
  62. type: Boolean,
  63. default: true,
  64. },
  65. iconImage: {
  66. type: String,
  67. default: null
  68. },
  69. rightBtnType: {
  70. type: String,
  71. default: 'icon' //icon 图标按钮 text 文字按钮
  72. },
  73. rightText: {
  74. type: String,
  75. default: "",
  76. },
  77. isShared: {
  78. type: Boolean,
  79. default: true,
  80. }
  81. },
  82. computed: {
  83. },
  84. data() {
  85. return {
  86. backActionimg: '/static/icon/backAction.png', //返回图标
  87. shareimg: '',
  88. computedRightIcon: "",
  89. };
  90. },
  91. async mounted() {
  92. },
  93. methods: {
  94. share() {
  95. this.$emit('share')
  96. },
  97. back() {
  98. uni.navigateBack({
  99. delta: 1
  100. });
  101. }
  102. }
  103. };
  104. </script>
  105. <!--使用scss,只在本组件生效-->
  106. <style lang="scss" scoped>
  107. .navbar {
  108. padding: 116rpx 40rpx 28rpx;
  109. box-sizing: border-box;
  110. position: relative;
  111. z-index: 999;
  112. .title {
  113. font-size: 36rpx;
  114. color: #333;
  115. position: absolute;
  116. /* 绝对定位 */
  117. left: 50%;
  118. /* 从左侧50%开始 */
  119. transform: translateX(-50%);
  120. /* 向左移动自身宽度的一半 */
  121. }
  122. .icon-left {
  123. width: 64rpx;
  124. height: 60rpx;
  125. }
  126. .icon-right {
  127. width: 48rpx;
  128. height: 48rpx;
  129. }
  130. .right-text {
  131. color: #333;
  132. font-size: 20rpx;
  133. }
  134. }
  135. </style>