page-title.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <view class="back-btn" :style="`height: ${statusHeigth + 50}px;`">
  3. <view class="back-box">
  4. <u-icon name="arrow-left" color="#fff" size="20" customStyle="margin:0 auto" class="arrow-left"
  5. @click="backToBefore()"></u-icon>
  6. <text class="back-text">
  7. <slot></slot>
  8. </text>
  9. <slot name="search"></slot>
  10. </view>
  11. <view class="search-box">
  12. <u-icon v-if="showSearch" name="search" color="#fff" size="30" @click="goToSearch()"></u-icon>
  13. <view v-if="rightText" @click="rightTextClick()" class="">
  14. {{rightText}}
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script setup>
  20. import {
  21. ref,
  22. defineEmits,
  23. defineProps,
  24. } from "vue";
  25. import {
  26. onLoad,
  27. onLaunch
  28. } from "@dcloudio/uni-app";
  29. /**
  30. * 标题名 插槽形式录入
  31. * @showSearch 是否展示搜索按钮
  32. * @url 搜索按钮跳转的页面
  33. * 搜索及搜索插槽功能暂不可用
  34. */
  35. const props = defineProps({
  36. showSearch: {
  37. type: Boolean,
  38. default: false
  39. },
  40. rightText: {
  41. type: String,
  42. default: null
  43. },
  44. url: {
  45. type: String,
  46. default: null
  47. }
  48. })
  49. const emit = defineEmits(['searchClick', 'rightTextClick'])
  50. let statusHeigth = ref(null)
  51. // 返回上一级
  52. function backToBefore() {
  53. uni.navigateBack({
  54. delta: 1,
  55. })
  56. };
  57. // 去到搜索页
  58. function goToSearch() {
  59. emit("searchClick")
  60. }
  61. function rightTextClick() {
  62. emit("rightTextClick")
  63. }
  64. onLoad(() => {
  65. uni.getSystemInfo({
  66. success(res) {
  67. statusHeigth.value = res.statusBarHeight
  68. }
  69. })
  70. })
  71. </script>
  72. <style lang="scss">
  73. .back-btn {
  74. position: fixed;
  75. top: 0;
  76. display: flex;
  77. width: 100%;
  78. z-index: 10000;
  79. background-color: #1763E7;
  80. box-shadow: 0rpx 8rpx 20rpx 0rpx rgba(12, 69, 167, 0.35);
  81. font-size: 35rpx;
  82. font-weight: 500;
  83. color: #FFF;
  84. display: flex;
  85. align-items: flex-end;
  86. justify-content: space-between;
  87. .back-box {
  88. height: 50px;
  89. display: flex;
  90. align-items: center;
  91. justify-content: flex-start;
  92. .arrow-left {
  93. margin-left: 28rpx;
  94. }
  95. .back-text {
  96. margin-left: 28rpx;
  97. }
  98. }
  99. .search-box {
  100. height: 50px;
  101. display: flex;
  102. align-items: center;
  103. justify-content: flex-start;
  104. margin-right: 28rpx;
  105. color: #fff;
  106. }
  107. }
  108. </style>