index.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <up-navbar :title="title" :bgColor="bgColor" :titleStyle="titleStyle">
  3. <template #left>
  4. <view class="u-nav-slot" slot="left" style="display: flex;background-color: transparent;">
  5. <image v-if="showback" src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/09/19/27b15a2d-2974-4f2e-a06e-8d13c0519113.png" style="width: 40rpx;height: 40rpx;" @tap="toBack(backUrl)"></image>
  6. </view>
  7. </template>
  8. </up-navbar>
  9. </template>
  10. <script setup lang="ts">
  11. import { ref } from 'vue'
  12. // 定义组件属性
  13. const props = defineProps({
  14. title: {
  15. type: String,
  16. default: ''
  17. },
  18. showback: {
  19. type: Boolean,
  20. default: true
  21. },
  22. backUrl: {
  23. type: String,
  24. default: ''
  25. },
  26. bgColor: {
  27. type: String,
  28. default: '#ffffff'
  29. },
  30. leftIconColor: {
  31. type: String,
  32. default: '#111111'
  33. },
  34. titleStyle: {
  35. type: Object,
  36. default: () => ({
  37. fontSize: '36rpx',
  38. fontWeight: 'bold',
  39. color: '#111111'
  40. })
  41. },
  42. backAlert: {
  43. type: Boolean,
  44. default: false
  45. }
  46. })
  47. // 定义组件状态
  48. const tabUrls = ref([
  49. '/pages/home',
  50. '/pages/nonprofit',
  51. '/pages/my'
  52. ])
  53. // 导出方法供模板使用
  54. const toBack = (url: string) => {
  55. if (props.backAlert) {
  56. } else {
  57. dealBack(url)
  58. }
  59. }
  60. const dealBack = (url: string) => {
  61. if (!url) {
  62. if (uni.getStorageSync('options')) {
  63. const options = JSON.parse(decodeURIComponent(uni.getStorageSync('options')))
  64. uni.redirectTo(options)
  65. uni.removeStorageSync('options')
  66. return
  67. }
  68. const pages = getCurrentPages()
  69. if (pages && pages.length > 1) {
  70. uni.navigateBack()
  71. } else {
  72. uni.reLaunch({ url: '/pages/home' })
  73. }
  74. } else {
  75. if (tabUrls.value.find(u => u === url)) {
  76. uni.reLaunch({ url })
  77. } else {
  78. uni.redirectTo({ url })
  79. }
  80. }
  81. }
  82. </script>
  83. <style lang="scss" scoped>
  84. .u-navbar--fixed {
  85. z-index: 99999 !important;
  86. }
  87. </style>