index.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <view class="nav-bar" :style="{ paddingTop: 12 + BarHeight + 'px' }">
  3. <view class="go-back">
  4. <slot name="left">
  5. <u-icon name="arrow-left" :color="color" size="32" @click="goBack" v-if="isBack"></u-icon>
  6. </slot>
  7. </view>
  8. <view class="nav-title" :style="{ color: color }">
  9. {{ title }}
  10. </view>
  11. <view class="go-back">
  12. <slot name="right"></slot>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. props: {
  19. title: "",
  20. color: {
  21. type: String,
  22. default: 'rgba(51, 51, 51, 1)'
  23. },
  24. backUrl: {
  25. type: String,
  26. default: ''
  27. },
  28. goMy: {
  29. type: String,
  30. default: ''
  31. },
  32. isBack: {
  33. type: Boolean,
  34. default: true // 这里默认是 true
  35. },
  36. },
  37. data() {
  38. return {
  39. BarHeight: '',
  40. };
  41. },
  42. mounted() {
  43. // #ifdef APP-PLUS
  44. let systemInfo = uni.getSystemInfoSync();
  45. this.BarHeight = systemInfo.statusBarHeight;
  46. // #endif
  47. },
  48. methods: {
  49. goBack() {
  50. if (this.goMy) {
  51. uni.switchTab({
  52. url: this.goMy
  53. })
  54. return;
  55. }
  56. if (this.backUrl) {
  57. const isTabPage = [
  58. '/pages/index/index',
  59. '/pages/index/game/gameList',
  60. '/pages/msg/index',
  61. '/pages/my/index'
  62. ].includes(this.backUrl)
  63. if (isTabPage) {
  64. uni.switchTab({
  65. url: this.backUrl
  66. })
  67. } else {
  68. uni.redirectTo({
  69. url: this.backUrl
  70. })
  71. }
  72. console.log(
  73. '我进第一个了'
  74. )
  75. } else {
  76. console.log('我进eles')
  77. uni.navigateBack()
  78. }
  79. }
  80. }
  81. };
  82. </script>
  83. <style lang="scss" scoped>
  84. .nav-bar {
  85. width: 100%;
  86. padding: 24rpx 32rpx 20rpx 32rpx;
  87. box-sizing: border-box;
  88. color: rgba(255, 255, 255, 1);
  89. font-family: DM Sans;
  90. font-size: 32rpx;
  91. font-weight: 400;
  92. line-height: 26px;
  93. display: flex;
  94. // justify-content: center;
  95. align-items: center;
  96. position: relative;
  97. z-index: 9999;
  98. .go-back {
  99. width: 32.61px;
  100. height: 26px;
  101. }
  102. .nav-title {
  103. flex: 1;
  104. text-align: center;
  105. }
  106. }
  107. </style>