index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <view class="mall-index">
  3. <!-- 内容区域 -->
  4. <view class="content-area">
  5. <home-page v-if="currentTab === 0" @switchTab="switchTab" ref="homePage"></home-page>
  6. <category-page v-if="currentTab === 1" ref="categoryPage"></category-page>
  7. <cart-page v-if="currentTab === 2" @goHome="switchTab(0)" ref="cartPage"></cart-page>
  8. <my-page v-if="currentTab === 3" ref="myPage"></my-page>
  9. </view>
  10. <!-- 底部导航栏 -->
  11. <view class="tab-bar">
  12. <view class="tab-item" :class="{active: currentTab === 0}" @click="switchTab(0)">
  13. <u-icon :name="currentTab === 0 ? 'home-fill' : 'home'" size="26"
  14. :color="currentTab === 0 ? '#2583EB' : '#999'"></u-icon>
  15. <text>首页</text>
  16. </view>
  17. <view class="tab-item" :class="{active: currentTab === 1}" @click="switchTab(1)">
  18. <u-icon :name="currentTab === 1 ? 'grid-fill' : 'grid'" size="26"
  19. :color="currentTab === 1 ? '#2583EB' : '#999'"></u-icon>
  20. <text>分类</text>
  21. </view>
  22. <view class="tab-item" :class="{active: currentTab === 2}" @click="switchTab(2)">
  23. <view class="icon-wrap">
  24. <u-icon :name="currentTab === 2 ? 'shopping-cart-fill' : 'shopping-cart'" size="26"
  25. :color="currentTab === 2 ? '#2583EB' : '#999'"></u-icon>
  26. <view class="badge">1</view>
  27. </view>
  28. <text>购物车</text>
  29. </view>
  30. <view class="tab-item" :class="{active: currentTab === 3}" @click="switchTab(3)">
  31. <u-icon :name="currentTab === 3 ? 'account-fill' : 'account'" size="26"
  32. :color="currentTab === 3 ? '#2583EB' : '#999'"></u-icon>
  33. <text>我的</text>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import HomePage from './home.vue'
  40. import CategoryPage from './category.vue'
  41. import CartPage from './cart.vue'
  42. import MyPage from './my.vue'
  43. export default {
  44. components: {
  45. HomePage,
  46. CategoryPage,
  47. CartPage,
  48. MyPage
  49. },
  50. data() {
  51. return {
  52. currentTab: 0
  53. }
  54. },
  55. onShow() {
  56. const tabCart = uni.getStorageSync('tabCart')
  57. if (tabCart) {
  58. this.currentTab = 2
  59. uni.removeStorageSync('tabCart')
  60. }
  61. uni.hideTabBar();
  62. },
  63. onUnload() {
  64. uni.showTabBar();
  65. },
  66. onBackPress() {
  67. uni.showTabBar();
  68. uni.switchTab({
  69. url: '/pages_im/pages/conversation/conversationList/index'
  70. })
  71. },
  72. methods: {
  73. switchTab(index) {
  74. this.currentTab = index;
  75. }
  76. }
  77. }
  78. </script>
  79. <style scoped lang="scss">
  80. .mall-index {
  81. display: flex;
  82. flex-direction: column;
  83. height: 100vh;
  84. background-color: #f8f8f8;
  85. }
  86. .content-area {
  87. flex: 1;
  88. height: 0; // Allow flex item to scroll internally
  89. overflow: hidden;
  90. position: relative;
  91. }
  92. .tab-bar {
  93. height: 100rpx;
  94. background-color: #fff;
  95. display: flex;
  96. align-items: center;
  97. justify-content: space-around;
  98. border-top: 1rpx solid #eee;
  99. padding-bottom: constant(safe-area-inset-bottom);
  100. padding-bottom: env(safe-area-inset-bottom);
  101. position: fixed;
  102. bottom: 0;
  103. left: 0;
  104. right: 0;
  105. z-index: 9999;
  106. .tab-item {
  107. display: flex;
  108. flex-direction: column;
  109. align-items: center;
  110. justify-content: center;
  111. text {
  112. font-size: 24rpx;
  113. margin-top: 6rpx;
  114. color: #999999;
  115. }
  116. &.active text {
  117. color: #2583EB;
  118. }
  119. .icon-wrap {
  120. position: relative;
  121. .badge {
  122. position: absolute;
  123. top: -10rpx;
  124. right: -10rpx;
  125. background: #fa436a;
  126. color: #fff;
  127. font-size: 18rpx;
  128. width: 30rpx;
  129. height: 30rpx;
  130. border-radius: 50%;
  131. display: flex;
  132. align-items: center;
  133. justify-content: center;
  134. }
  135. }
  136. }
  137. }
  138. </style>