bottom-nav.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <view class="bottom-nav">
  3. <view
  4. class="nav-item"
  5. :class="{ active: current === 'index' }"
  6. @click="goNav('index')"
  7. >
  8. <text class="nav-icon">🏠</text>
  9. <text class="nav-text">首页</text>
  10. </view>
  11. <view
  12. class="nav-item"
  13. :class="{ active: current === 'action' }"
  14. @click="goNav('action')"
  15. >
  16. <text class="nav-icon">🎯</text>
  17. <text class="nav-text">行动</text>
  18. </view>
  19. <view
  20. class="nav-item"
  21. :class="{ active: current === 'mind' }"
  22. @click="goNav('mind')"
  23. >
  24. <text class="nav-icon">🧠</text>
  25. <text class="nav-text">心智</text>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. props: {
  32. current: { type: String, default: 'index' }
  33. },
  34. methods: {
  35. goNav(tab) {
  36. if (tab === this.current) return
  37. if (tab === 'index') {
  38. // 首页是 TabBar 页面
  39. if (uni.getStorageSync('token')) {
  40. uni.switchTab({ url: '/pages/index/index' })
  41. } else {
  42. uni.navigateTo({ url: '/pages/index/index' })
  43. }
  44. } else if (tab === 'action') {
  45. // 行动是 TabBar 页面
  46. if (uni.getStorageSync('token')) {
  47. uni.switchTab({ url: '/pages/action/index' })
  48. } else {
  49. uni.navigateTo({ url: '/pages/action/index' })
  50. }
  51. } else if (tab === 'mind') {
  52. // 心智文章页(非 TabBar)
  53. uni.navigateTo({ url: '/pages/mind/articles' })
  54. }
  55. }
  56. }
  57. }
  58. </script>
  59. <style scoped>
  60. .bottom-nav {
  61. position: fixed;
  62. bottom: 0;
  63. left: 0;
  64. right: 0;
  65. height: 100rpx;
  66. background: #fff;
  67. border-top: 1rpx solid #eee;
  68. display: flex;
  69. align-items: center;
  70. justify-content: space-around;
  71. padding-bottom: env(safe-area-inset-bottom);
  72. z-index: 100;
  73. }
  74. .nav-item {
  75. display: flex;
  76. flex-direction: column;
  77. align-items: center;
  78. justify-content: center;
  79. flex: 1;
  80. height: 100%;
  81. }
  82. .nav-item.active .nav-text { color: #FF6B6B; }
  83. .nav-icon { font-size: 40rpx; }
  84. .nav-text { font-size: 20rpx; color: #999; margin-top: 4rpx; }
  85. .nav-item.active .nav-text { font-weight: bold; }
  86. </style>