bottom-nav.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. // index 是 TabBar 页面,已登录用 switchTab,未登录用 navigateTo
  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. // shop 已从 TabBar 移除,统一用 navigateTo
  46. uni.navigateTo({ url: '/pages/shop/index' })
  47. } else if (tab === 'mind') {
  48. // 心智文章页(非 TabBar)
  49. uni.navigateTo({ url: '/pages/mind/articles' })
  50. }
  51. }
  52. }
  53. }
  54. </script>
  55. <style scoped>
  56. .bottom-nav {
  57. position: fixed;
  58. bottom: 0;
  59. left: 0;
  60. right: 0;
  61. height: 100rpx;
  62. background: #fff;
  63. border-top: 1rpx solid #eee;
  64. display: flex;
  65. align-items: center;
  66. justify-content: space-around;
  67. padding-bottom: env(safe-area-inset-bottom);
  68. z-index: 100;
  69. }
  70. .nav-item {
  71. display: flex;
  72. flex-direction: column;
  73. align-items: center;
  74. justify-content: center;
  75. flex: 1;
  76. height: 100%;
  77. }
  78. .nav-item.active .nav-text { color: #FF6B6B; }
  79. .nav-icon { font-size: 40rpx; }
  80. .nav-text { font-size: 20rpx; color: #999; margin-top: 4rpx; }
  81. .nav-item.active .nav-text { font-weight: bold; }
  82. </style>