CustomBottomNav.uvue 2.0 KB

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