index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <view class="container">
  3. <view class="content" :class="tabValue">
  4. <course-home v-if="tabValue === 'courseHome'"></course-home>
  5. <course-mine v-if="tabValue === 'courseMine'"></course-mine>
  6. </view>
  7. <view class="bottom-block"></view>
  8. <view class="bottom-box">
  9. <view class="menu-box">
  10. <view class="menu-item-box" :class="{'is-active': tabValue === 'courseHome'}" @click="selectTab('courseHome')">
  11. <view class="iconfont icon-home"></view>
  12. <view class="text">首页</view>
  13. </view>
  14. <view class="menu-item-box" :class="{'is-active': tabValue === 'courseMine'}" @click="selectTab('courseMine')">
  15. <view class="iconfont icon-user-s"></view>
  16. <view class="text">我的</view>
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import courseHome from './courseHome/courseHome.vue';
  24. import courseMine from './courseMine/courseMine.vue';
  25. export default {
  26. data() {
  27. return {
  28. tabValue: 'courseHome', // 默认选中的 Tab
  29. };
  30. },
  31. components: {
  32. courseHome,
  33. courseMine,
  34. },
  35. methods: {
  36. selectTab(value) {
  37. this.tabValue = value; // 设置当前选中的 Tab
  38. },
  39. },
  40. };
  41. </script>
  42. <style>
  43. ::v-deep(.u-tab-item) {
  44. margin-right: 40rpx;
  45. }
  46. </style>
  47. <style scoped lang="scss">
  48. .container {
  49. display: flex;
  50. flex-direction: column;
  51. height: 100vh;
  52. width: 100vw;
  53. }
  54. .content {
  55. flex: 1;
  56. /* 内容区填充剩余空间 */
  57. padding: 0 30rpx;
  58. /* 内边距 */
  59. }
  60. .courseHome {
  61. background-color: #fff;
  62. }
  63. .courseMine {
  64. background-color: #f7f7f7;
  65. }
  66. .tabbar-block {
  67. flex: 0 0 auto;
  68. height: 150rpx;
  69. padding-bottom: env(safe-area-inset-bottom, 0);
  70. }
  71. .tabbar {
  72. -webkit-tap-highlight-color: rgba(0,0,0,0);
  73. position: fixed;
  74. width: 100vw;
  75. // height: 100rpx;
  76. bottom: 0;
  77. display: flex;
  78. justify-content: space-around;
  79. /* 平分 TabBar 各项 */
  80. background-color: #fff;
  81. /* TabBar 背景色 */
  82. padding-bottom: env(safe-area-inset-bottom, 0);
  83. /* 避免与底部黑条重叠 */
  84. /* 仅在上方添加阴影 */
  85. box-shadow: 5px -1px 0px rgba(0, 0, 0, 0.1);
  86. /* 上边阴影效果 */
  87. height: 150rpx;
  88. align-items: center;
  89. border-top: none;
  90. /* 去掉上边的边框,如果之前有的话 */
  91. border-bottom: none;
  92. /* 去掉下边的边框 */
  93. }
  94. .tab-item {
  95. // padding: 15rpx 0;
  96. flex: 1;
  97. /* 每个 TabBar 项均分 */
  98. text-align: center;
  99. /* 内容居中 */
  100. cursor: pointer;
  101. /* 鼠标指针样式 */
  102. display: flex;
  103. /* 激活状态下加粗显示 */
  104. flex-direction: column;
  105. align-items: center;
  106. font-size: 20rpx;
  107. image {
  108. width: 50rpx;
  109. height: 50rpx;
  110. }
  111. }
  112. .tab-item.active {
  113. color: #0069f6;
  114. /* 激活状态下的文本颜色 */
  115. }
  116. .bottom-block {
  117. flex: 0 0 auto;
  118. height: calc(112rpx + env(safe-area-inset-bottom, 0));
  119. }
  120. .bottom-box {
  121. padding: 5rpx 20rpx;
  122. background-color: $uni-bg-color-grey;
  123. border: 1rpx solid #E9E9E9;
  124. padding-bottom: calc(5rpx + env(safe-area-inset-bottom, 0));
  125. @include bottomMagnet();
  126. .menu-box {
  127. height: 100rpx;
  128. display: flex;
  129. align-items: center;
  130. .menu-item-box {
  131. width: calc(100% / 2);
  132. text-align: center;
  133. .iconfont {
  134. font-size: 55rpx;
  135. }
  136. .text {
  137. font-size: $uni-font-size-2;
  138. }
  139. }
  140. .is-active {
  141. color: $uni-color-primary;
  142. }
  143. }
  144. }
  145. </style>