cu-custom.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <view>
  3. <view class="cu-custom" :style="[{ height: CustomBar + 'px' }]">
  4. <view
  5. class="cu-bar fixed"
  6. :style="style"
  7. :class="[bgImage != '' ? 'none-bg text-white bg-img' : '', bgColor]"
  8. >
  9. <view class="action" @tap="BackPage" v-if="isBack">
  10. <u-icon name="arrow-left" color="#020305" size="32rpx" />
  11. <slot name="backText"></slot>
  12. </view>
  13. <view class="content" :style="[{ top: StatusBar + 'px' }]">
  14. <slot name="content"></slot>
  15. </view>
  16. <view class="cu-bar-right">
  17. <slot name="right"></slot>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. data() {
  26. return {
  27. StatusBar: this.StatusBar,
  28. CustomBar: this.CustomBar,
  29. };
  30. },
  31. name: "cu-custom",
  32. computed: {
  33. style() {
  34. var StatusBar = this.StatusBar;
  35. var CustomBar = this.CustomBar;
  36. var bgImage = this.bgImage;
  37. var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
  38. if (this.bgImage) {
  39. style = `${style}background-image:url(${bgImage});`;
  40. }
  41. if (this.textColor) {
  42. style = `${style}color: ${this.textColor}`;
  43. }
  44. return style;
  45. },
  46. },
  47. props: {
  48. bgColor: {
  49. type: String,
  50. default: "",
  51. },
  52. isBack: {
  53. type: [Boolean, String],
  54. default: false,
  55. },
  56. bgImage: {
  57. type: String,
  58. default: "",
  59. },
  60. textColor: {
  61. type: String,
  62. default: "",
  63. },
  64. isGoWater: {
  65. type: Boolean,
  66. default: false,
  67. },
  68. },
  69. methods: {
  70. BackPage() {
  71. if (this.isGoWater) {
  72. uni.switchTab({
  73. url: "/waterPages/index",
  74. });
  75. } else {
  76. if (getCurrentPages().length < 2 && "undefined" !== typeof __wxConfig) {
  77. let url = "/" + __wxConfig.pages[0];
  78. return uni.redirectTo({ url });
  79. }
  80. // uni.navigateBack({
  81. // delta: 1
  82. // })
  83. if (getCurrentPages().length === 1) {
  84. uni.switchTab({
  85. url: "/pages/index",
  86. });
  87. } else {
  88. uni.navigateBack({
  89. delta: 1,
  90. });
  91. }
  92. }
  93. },
  94. },
  95. };
  96. </script>
  97. <style lang="scss" scoped>
  98. .cu-bar {
  99. display: flex;
  100. align-items: center;
  101. position: relative;
  102. &.bg-transparent {
  103. background-color: transparent;
  104. }
  105. &.bg-gray {
  106. background-color: #f7f7f7;
  107. }
  108. .cu-bar-right {
  109. position: relative;
  110. z-index: 10;
  111. right: 32rpx;
  112. }
  113. .content {
  114. position: absolute;
  115. left: 50%;
  116. transform: translateX(-50%);
  117. color: #020305;
  118. font-family: "Source Han Sans CN VF";
  119. font-weight: 700;
  120. font-size: 32rpx;
  121. }
  122. }
  123. </style>