index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <view class="custom-tabbar">
  3. <view class="tabbar-border"></view>
  4. <view class="tabbar-list">
  5. <view
  6. class="tabbar-item"
  7. v-for="(item, index) in list"
  8. :key="index"
  9. @click="switchTab(item.pagePath)"
  10. >
  11. <image
  12. class="tabbar-icon"
  13. :src="currentPath === item.pagePath ? item.selectedIconPath : item.iconPath"
  14. ></image>
  15. <view
  16. class="tabbar-text"
  17. :class="{'tabbar-text-active': currentPath === item.pagePath}"
  18. >
  19. {{ item.text }}
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script setup>
  26. import { ref } from 'vue';
  27. const props = defineProps({
  28. currentPath: {
  29. type: String,
  30. required: true
  31. }
  32. });
  33. const list = ref([
  34. {
  35. pagePath: "pages/home/index",
  36. text: "任务中心",
  37. iconPath: "/static/tabbar/home.svg",
  38. selectedIconPath: "/static/tabbar/home-active.svg"
  39. },
  40. {
  41. pagePath: "pages/orders/index",
  42. text: "我的订单",
  43. iconPath: "/static/tabbar/order.svg",
  44. selectedIconPath: "/static/tabbar/order-active.svg"
  45. },
  46. {
  47. pagePath: "pages/mine/index",
  48. text: "我的",
  49. iconPath: "/static/tabbar/mine.svg",
  50. selectedIconPath: "/static/tabbar/mine-active.svg"
  51. }
  52. ]);
  53. const switchTab = (path) => {
  54. if (props.currentPath === path) return;
  55. uni.reLaunch({
  56. url: '/' + path
  57. });
  58. };
  59. </script>
  60. <style scoped>
  61. .custom-tabbar {
  62. position: fixed;
  63. bottom: 0;
  64. left: 0;
  65. width: 100%;
  66. height: 50px;
  67. background-color: #ffffff;
  68. display: flex;
  69. flex-direction: column;
  70. z-index: 999;
  71. padding-bottom: env(safe-area-inset-bottom);
  72. }
  73. .tabbar-border {
  74. height: 1px;
  75. background-color: rgba(0, 0, 0, 0.1);
  76. transform: scaleY(0.5);
  77. }
  78. .tabbar-list {
  79. display: flex;
  80. flex: 1;
  81. align-items: center;
  82. justify-content: space-around;
  83. }
  84. .tabbar-item {
  85. display: flex;
  86. flex-direction: column;
  87. align-items: center;
  88. justify-content: center;
  89. height: 100%;
  90. flex: 1;
  91. }
  92. .tabbar-icon {
  93. width: 24px;
  94. height: 24px;
  95. margin-bottom: 2px;
  96. }
  97. .tabbar-text {
  98. font-size: 10px;
  99. color: #999999;
  100. }
  101. .tabbar-text-active {
  102. color: #FF5722;
  103. }
  104. </style>