nav-bar.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <uni-nav-bar :height="`${height}rpx`" :backgroundColor="backgroundColor" :fixed="true" :border="false" :statusBar="true" :leftWidth="showLeftIcon?'48rpx':'0rpx'" :rightWidth="showRightIcon?'48rpx':'0rpx'">
  3. <template v-slot:left v-if="showLeftIcon">
  4. <uni-icons type="left" :color="leftIconColor" style="font-size: 40rpx;" @click="GoBack()" />
  5. </template>
  6. <view class="center_view">
  7. <view v-if="showTitle" class="title">
  8. <text class="nav_title" :style="{'color':navTitleColor}">{{title}}</text>
  9. </view>
  10. </view>
  11. </uni-nav-bar>
  12. </template>
  13. <script setup>
  14. import uniNavBar from '@/uni_modules/uni-nav-bar/components/uni-nav-bar/uni-nav-bar.vue';
  15. import uniIcons from '@/uni_modules/uni-icons/components/uni-icons/uni-icons.vue';
  16. const emit = defineEmits(['GoBack']);
  17. const props = defineProps({
  18. height: {
  19. type: String,
  20. default: () => ''
  21. },
  22. showLeftIcon: {
  23. type: Boolean,
  24. default: () => false
  25. },
  26. showRightIcon: {
  27. type: Boolean,
  28. default: () => false
  29. },
  30. showTitle: {
  31. type: Boolean,
  32. default: () => false
  33. },
  34. title: {
  35. type: String,
  36. default: () => ''
  37. },
  38. backgroundColor:{
  39. type: String,
  40. default: () => '#FFFFFF'
  41. },
  42. leftIconColor:{
  43. type: String,
  44. default: () => '#333333'
  45. },
  46. navTitleColor:{
  47. type: String,
  48. default: () => '#333333'
  49. },
  50. backPath: {
  51. type: String,
  52. default: () => ''
  53. }
  54. });
  55. const GoBack = () => {
  56. if (props.backPath == 'myIndex') {
  57. uni.switchTab({
  58. url: '/pages/my/index'
  59. });
  60. } else {
  61. emit('GoBack');
  62. }
  63. }
  64. </script>
  65. <style scoped lang="scss">
  66. :deep(.uni-navbar__header) {
  67. padding: 0;
  68. position: relative;
  69. z-index: 999;
  70. }
  71. :deep(.uni-navbar__header-container) {
  72. padding: 0;
  73. }
  74. :deep(.uni-navbar__header-btns-left) {
  75. position: absolute;
  76. left: 24rpx;
  77. top: 0;
  78. height: 88rpx;
  79. z-index: 2;
  80. }
  81. .center_view {
  82. width: 100%;
  83. .title {
  84. height: 88rpx;
  85. padding: 0 72rpx;
  86. display: flex;
  87. align-items: center;
  88. justify-content: center;
  89. .nav_title {
  90. flex: 1;
  91. font-size: 32rpx;
  92. color: #333333;
  93. font-weight: 500;
  94. height: 32rpx;
  95. line-height: 32rpx;
  96. text-align: center;
  97. overflow: hidden;
  98. text-overflow: ellipsis;
  99. white-space: nowrap;
  100. }
  101. }
  102. }
  103. </style>