CustomBottomNav.uvue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view class="bottom-nav">
  3. <!-- 底座(可加背景色或阴影) -->
  4. <view class="tabbar-platform">
  5. </view>
  6. <view v-for="(item, index) in tabs" :key="index" class="nav-item" :class="{ active: currentIndex === index }"
  7. @click="handleClick(index)">
  8. <text class="nav-text">
  9. {{ item.text }}
  10. </text>
  11. </view>
  12. </view>
  13. </template>
  14. <script setup lang="ts">
  15. // Props & Emits
  16. interface TabItem {
  17. text : string;
  18. }
  19. interface Props {
  20. currentIndex : number;
  21. }
  22. const props = defineProps<Props>();
  23. const emit = defineEmits<{
  24. (e : 'change', index : number) : void;
  25. }>();
  26. // 配置数据(可从 props 接收)
  27. const tabs : TabItem[] = [
  28. { text: '小丁' },
  29. { text: '理疗' },
  30. { text: '预约' },
  31. { text: '商户' },
  32. { text: '我的' }
  33. ];
  34. // 方法
  35. const handleClick = (index : number) => {
  36. emit('change', index);
  37. };
  38. </script>
  39. <style scoped>
  40. .tabbar-platform{
  41. background-color: #ffffff;
  42. box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
  43. height: 100rpx;
  44. position: fixed;
  45. bottom: 0;
  46. left: 0;
  47. right: 0;
  48. }
  49. /* 底部导航容器 */
  50. .bottom-nav {
  51. position: fixed;
  52. bottom: 0;
  53. left: 0;
  54. right: 0;
  55. display: flex;
  56. flex-direction: row;
  57. justify-content: space-around;
  58. align-items: flex-end;
  59. padding: 10rpx 0 ;
  60. z-index: 1;
  61. }
  62. /* 单个导航项 */
  63. .nav-item {
  64. width: 80rpx;
  65. height: 80rpx;
  66. border-radius: 40rpx;
  67. /* half of width to make circle */
  68. display: flex;
  69. justify-content: center;
  70. align-items: center;
  71. background-color: #ffa500;
  72. /* 橙色背景 */
  73. color: #ffffff;
  74. /* 白色文字 */
  75. font-size: 26rpx;
  76. font-weight: bold;
  77. transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  78. position: relative;
  79. }
  80. /* 选中状态 */
  81. .nav-item.active {
  82. width: 110rpx;
  83. height: 110rpx;
  84. transform: translateY(-10rpx);
  85. /* 上浮 */
  86. z-index: 10;
  87. background-color: #ffffff;
  88. /* 白底 */
  89. color: #ffa500;
  90. /* 橙色文字 */
  91. box-shadow: 0 8rpx 20rpx rgba(255, 165, 0, 0.4);
  92. }
  93. /* 文字样式 */
  94. .nav-text {
  95. line-height: 1;
  96. }
  97. </style>