tabbar_hexiao_jxs.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <view class="tabbar-container">
  3. <view class="tabbar-item" @click="navigate('/pages/hexiao/jxs/index', 0)">
  4. <uni-icons type="home-filled" :color="current === 0 ? activeColor : inactiveColor" size="26"></uni-icons>
  5. <view class="text" :style="{ color: current === 0 ? activeColor : inactiveColor }">首页</view>
  6. </view>
  7. <view class="tabbar-item" @click="navigate('/pages/hexiao/jxs/order', 1)">
  8. <uni-icons type="shop" :color="current === 1 ? activeColor : inactiveColor" size="26"></uni-icons>
  9. <view class="text" :style="{ color: current === 1 ? activeColor : inactiveColor }">订单</view>
  10. </view>
  11. <view class="tabbar-item" @click="navigate('/pages/hexiao/jxs/my', 2)">
  12. <uni-icons type="person" :color="current === 2 ? activeColor : inactiveColor" size="26"></uni-icons>
  13. <view class="text" :style="{ color: current === 2 ? activeColor : inactiveColor }">我的</view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. name: "my-tab-bar",
  20. props: {
  21. // 通过 props 接收当前页面的索引,用于高亮
  22. // 0: 首页, 1: 门店, 2: 我的
  23. current: {
  24. type: Number,
  25. required: true
  26. }
  27. },
  28. data() {
  29. return {
  30. // 定义高亮和非高亮颜色
  31. activeColor: '#409EFF', // 蓝色
  32. inactiveColor: '#909399' // 灰色
  33. };
  34. },
  35. methods: {
  36. navigate(path, index) {
  37. // 如果点击的已经是当前页,则不跳转,防止重复加载
  38. if (this.current === index) {
  39. return;
  40. }
  41. // 使用 reLaunch 跳转可以关闭所有其他页面,适合tabBar之间的切换
  42. uni.redirectTo({
  43. url: path
  44. });
  45. }
  46. }
  47. }
  48. </script>
  49. <style lang="scss" scoped>
  50. .tabbar-container {
  51. position: fixed;
  52. bottom: 0;
  53. left: 0;
  54. width: 100%;
  55. height: 100rpx;
  56. background-color: #ffffff;
  57. display: flex;
  58. justify-content: space-around;
  59. align-items: center;
  60. border-top: 1rpx solid #f0f0f0;
  61. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.03);
  62. /* 适配iPhone X等机型的底部安全区域 */
  63. padding-bottom: constant(safe-area-inset-bottom);
  64. padding-bottom: env(safe-area-inset-bottom);
  65. z-index: 999;
  66. }
  67. .tabbar-item {
  68. display: flex;
  69. flex-direction: column;
  70. align-items: center;
  71. justify-content: center;
  72. flex: 1; // 保证均分
  73. height: 100%;
  74. }
  75. .text {
  76. font-size: 24rpx;
  77. margin-top: 2rpx;
  78. }
  79. </style>