index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 scoped lang="scss">
  43. .container {
  44. display: flex;
  45. flex-direction: column;
  46. height: 100vh;
  47. width: 100vw;
  48. }
  49. .content {
  50. flex: 1;
  51. /* 内容区填充剩余空间 */
  52. padding: 0 30rpx;
  53. /* 内边距 */
  54. }
  55. .courseHome {
  56. background-color: #fff;
  57. }
  58. .courseMine {
  59. background-color: #f7f7f7;
  60. }
  61. .tabbar-block {
  62. flex: 0 0 auto;
  63. height: 150rpx;
  64. padding-bottom: env(safe-area-inset-bottom, 0);
  65. }
  66. .tabbar {
  67. -webkit-tap-highlight-color: rgba(0,0,0,0);
  68. position: fixed;
  69. width: 100vw;
  70. // height: 100rpx;
  71. bottom: 0;
  72. display: flex;
  73. justify-content: space-around;
  74. /* 平分 TabBar 各项 */
  75. background-color: #fff;
  76. /* TabBar 背景色 */
  77. padding-bottom: env(safe-area-inset-bottom, 0);
  78. /* 避免与底部黑条重叠 */
  79. /* 仅在上方添加阴影 */
  80. box-shadow: 5px -1px 0px rgba(0, 0, 0, 0.1);
  81. /* 上边阴影效果 */
  82. height: 150rpx;
  83. align-items: center;
  84. border-top: none;
  85. /* 去掉上边的边框,如果之前有的话 */
  86. border-bottom: none;
  87. /* 去掉下边的边框 */
  88. }
  89. .tab-item {
  90. // padding: 15rpx 0;
  91. flex: 1;
  92. /* 每个 TabBar 项均分 */
  93. text-align: center;
  94. /* 内容居中 */
  95. cursor: pointer;
  96. /* 鼠标指针样式 */
  97. display: flex;
  98. /* 激活状态下加粗显示 */
  99. flex-direction: column;
  100. align-items: center;
  101. font-size: 20rpx;
  102. image {
  103. width: 50rpx;
  104. height: 50rpx;
  105. }
  106. }
  107. .tab-item.active {
  108. color: #0069f6;
  109. /* 激活状态下的文本颜色 */
  110. }
  111. .bottom-block {
  112. flex: 0 0 auto;
  113. height: calc(112rpx + env(safe-area-inset-bottom, 0));
  114. }
  115. .bottom-box {
  116. padding: 5rpx 20rpx;
  117. background-color: $uni-bg-color-grey;
  118. border: 1rpx solid #E9E9E9;
  119. padding-bottom: calc(5rpx + env(safe-area-inset-bottom, 0));
  120. @include bottomMagnet();
  121. .menu-box {
  122. height: 100rpx;
  123. display: flex;
  124. align-items: center;
  125. .menu-item-box {
  126. width: calc(100% / 2);
  127. text-align: center;
  128. .iconfont {
  129. font-size: 55rpx;
  130. }
  131. .text {
  132. font-size: $uni-font-size-2;
  133. }
  134. }
  135. .is-active {
  136. color: $uni-color-primary;
  137. }
  138. }
  139. }
  140. </style>