index.vue 1.7 KB

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