navbar.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view class="navbar__container">
  3. <Theme>
  4. <up-navbar
  5. placeholder
  6. :border="border"
  7. :fixed="fixed"
  8. :bgColor="bgColor"
  9. :height="height"
  10. :style="{ '--borderColor': borderColor }"
  11. @leftClick="handleLeftClick"
  12. @rightClick="handleRightClick"
  13. v-if="!navShow"
  14. >
  15. <template #left>
  16. <slot name="left">
  17. <view class="left">
  18. <u-icon
  19. :size="iconSize"
  20. :color="leftIconColor"
  21. :name="!leftShow ? 'arrow-left' : leftIcon"
  22. ></u-icon>
  23. <view class="left_text" :style="leftStyle" v-if="!!leftText">{{
  24. t(leftText)
  25. }}</view>
  26. </view>
  27. </slot>
  28. </template>
  29. <template #center>
  30. <slot name="center">
  31. <trans
  32. class="nav_title"
  33. :style="navStyle"
  34. v-if="!!title"
  35. :_t="title"
  36. />
  37. </slot>
  38. </template>
  39. <template #right>
  40. <slot name="right"></slot>
  41. </template>
  42. </up-navbar>
  43. </Theme>
  44. </view>
  45. </template>
  46. <script setup>
  47. import { t } from "@/locale";
  48. const props = defineProps({
  49. autoBack: Boolean,
  50. fixed: Boolean,
  51. leftText: {
  52. type: [String, Number],
  53. default: "",
  54. },
  55. bgColor: {
  56. type: String,
  57. default: "var(--light)",
  58. },
  59. iconSize: {
  60. type: Number,
  61. default: 20,
  62. },
  63. leftIconColor: {
  64. type: String,
  65. default: "var(--text)",
  66. },
  67. title: {
  68. type: String,
  69. default: "",
  70. },
  71. leftIcon: {
  72. type: String,
  73. default: "",
  74. },
  75. leftShow: Boolean,
  76. border: Boolean,
  77. height: {
  78. type: String,
  79. default: "44px",
  80. },
  81. leftStyle: {
  82. type: Object,
  83. default: () => ({}),
  84. },
  85. navStyle: {
  86. type: Object,
  87. default: () => ({}),
  88. },
  89. borderColor: {
  90. type: String,
  91. default: "var(--bor-color)",
  92. },
  93. navShow: Boolean,
  94. });
  95. const emit = defineEmits(["leftClick", "rightClick"]);
  96. const handleLeftClick = () => {
  97. if (props.autoBack) return emit("leftClick");
  98. if (props.leftShow) return;
  99. uni.navigateBack();
  100. };
  101. const handleRightClick = () => {
  102. if (props.leftShow) return;
  103. emit("rightClick");
  104. };
  105. </script>
  106. <style lang="less" scoped>
  107. @import url("../style.less");
  108. .navbar__container {
  109. max-width: 1536rpx;
  110. }
  111. .left {
  112. .flex_position(center, flex-end);
  113. /deep/ .u-icon--right {
  114. .u-icon__icon {
  115. font-weight: 700 !important;
  116. }
  117. }
  118. .left_text {
  119. .size(15px);
  120. color: var(--text);
  121. margin-left: 3px;
  122. }
  123. }
  124. .nav_title {
  125. width: 12.5rem;
  126. .size(14px);
  127. color: var(--text);
  128. text-align: center;
  129. font-weight: 700;
  130. }
  131. /deep/ .u-border-bottom {
  132. border-color: var(--bor-color) !important;
  133. }
  134. /deep/ .u-navbar--fixed {
  135. z-index: 1000;
  136. }
  137. </style>