cu-custom.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <view class="cu-custom" style="z-index:9999">
  3. <view class="cu-bar fixed" :style="style" :class="[bgImage!=''?'none-bg text-white bg-img':'',bgColor]">
  4. <!-- <view class="action border-custom" v-if="isBack" style="width:160rpx;">
  5. <text class="cuIcon-back text-white" @tap="back"></text>
  6. <text class="cuIcon-homefill text-white" @tap="toHome"></text>
  7. </view> -->
  8. <view class="action" v-if="isBack" style="width:100rpx;" @tap="back">
  9. <text class="cuIcon-back" style="color:#333333"></text>
  10. </view>
  11. <view class="action" v-if="!isBack" style="width:160rpx;">
  12. </view>
  13. <view class="content" :style="[{top:statusBar + 'px'}]">
  14. <slot name="content"></slot>
  15. </view>
  16. <view class="action right" style="width:160rpx;">
  17. <slot name="right"></slot>
  18. </view>
  19. </view>
  20. </view>
  21. <!-- #ifdef APP-PLUS|H5 -->
  22. <view :style="[{height:customBar*2 + 'upx'}]"></view>
  23. <!-- #endif -->
  24. <!-- #ifdef MP -->
  25. <view :style="[{height:(customBar + 13) + 'px'}]"></view>
  26. <!-- #endif -->
  27. </template>
  28. <script setup>
  29. import {useChatStore} from "@/store/chatStore";
  30. import {computed, getCurrentInstance, ref} from "vue";
  31. const {proxy} = getCurrentInstance();
  32. const chatStore = useChatStore();
  33. const statusBar = ref(proxy.statusBar);
  34. const customBar = ref(proxy.customBar);
  35. const props = defineProps({
  36. bgColor: {
  37. type: String,
  38. default: ''
  39. },
  40. isBack: {
  41. type: [Boolean, String],
  42. default: false
  43. },
  44. isShare: {
  45. type: [Boolean, String],
  46. default: true
  47. },
  48. bgImage: {
  49. type: String,
  50. default: ''
  51. },
  52. });
  53. const style = computed(() => {
  54. // #ifdef MP
  55. let st = `height:${customBar.value*2}rpx;padding-top:${statusBar.value}px;`;
  56. // // #endif
  57. // #ifndef MP
  58. let st = `height:${customBar.value*2}upx;padding-top:${statusBar.value}upx;`;
  59. // // #endif
  60. if (props.bgImage) {
  61. st = `${st}background-image:url(${props.bgImage});`;
  62. }
  63. return st;
  64. })
  65. const back = () => {
  66. // #ifdef H5
  67. let canBack = true
  68. const pages = getCurrentPages()
  69. if ('pages/index/index' === pages[0].route) {
  70. chatStore.setOpenChatId(null);
  71. }
  72. // 有可返回的页面则直接返回,uni.navigateBack默认返回失败之后会自动刷新页面 ,无法继续返回
  73. if (pages.length > 1) {
  74. uni.navigateBack()
  75. return;
  76. }
  77. // #endif
  78. uni.navigateBack()
  79. }
  80. const toHome = () => {
  81. uni.reLaunch({
  82. url: "/pages/index/index"
  83. })
  84. }
  85. </script>
  86. <style scoped>
  87. .cu-bar {
  88. background-size: cover;
  89. }
  90. .cu-bar .right {
  91. justify-content: flex-end;
  92. }
  93. .border-custom{
  94. height:70%!important;
  95. }
  96. </style>