tabbar.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <view class="tab-bar" :style="{ backgroundColor: mainColor }">
  3. <!-- 循环每个 item 菜单 -->
  4. <view v-for="(item,index) in tabBarList" :key="index"
  5. :class="{'tab-bar-item': true,currentTar: selected == item.id}" @click="switchTab(item, index)">
  6. <view class="tab_text" :style="{color: selected == index ? selectedColor : color}">
  7. <image class="tab_img" :src="selected == index ? item.selectedIconPath : item.iconPath"></image>
  8. <view>{{ item.text }}</view>
  9. </view>
  10. </view>
  11. </view>
  12. </template>
  13. <script setup>
  14. import {
  15. onMounted,
  16. defineProps,
  17. ref
  18. } from 'vue'
  19. import {
  20. useColortore
  21. } from '@/store/index.js';
  22. import {
  23. useI18n
  24. } from 'vue-i18n'
  25. const {
  26. locale,
  27. t
  28. } = useI18n();
  29. const mainColor = ref('')
  30. onMounted(() => {
  31. const colorStore = useColortore()
  32. mainColor.value = colorStore.mainRed
  33. })
  34. // 子组件传递参数
  35. const props = defineProps({
  36. selected: {
  37. type: String,
  38. default: '0'
  39. }
  40. })
  41. let color = ref('#ffffff')
  42. let selectedColor = ref('#ffffff')
  43. let tabBarList = ref([{
  44. "id": 0,
  45. "pagePath": "/pages/index/index",
  46. "iconPath": "../../static/tabBar/home.png",
  47. "selectedIconPath": "../../static/tabBar/home-selected.png",
  48. "text": t("tabbar.home")
  49. }, {
  50. "id": 1,
  51. "pagePath": "/pages/project/index",
  52. "iconPath": "../../static/tabBar/project.png",
  53. "selectedIconPath": "../../static/tabBar/project-selected.png",
  54. "text": t("tabbar.project")
  55. }, {
  56. "id": 2,
  57. "pagePath": "/pages/user/index",
  58. "iconPath": "../../static/tabBar/user.png",
  59. "selectedIconPath": "../../static/tabBar/user-selected.png",
  60. "text": t("tabbar.me")
  61. }])
  62. // 跳转tabBar菜单栏
  63. const switchTab = (item) => {
  64. let url = item.pagePath;
  65. uni.switchTab({
  66. url
  67. })
  68. }
  69. // 隐藏原生TabBar
  70. uni.hideTabBar();
  71. </script>
  72. <style lang="scss" scoped>
  73. // 外部装修
  74. .tab-bar {
  75. position: fixed;
  76. bottom: 0;
  77. width: 100vw;
  78. height: 100rpx;
  79. // background: #EC0000;
  80. padding: 20rpx 0;
  81. display: flex;
  82. justify-content: center;
  83. align-items: center;
  84. z-index: 9999;
  85. .currentTar {
  86. border-radius: 15rpx;
  87. transition: all 0.5s ease-in-out;
  88. }
  89. .tab-bar-item {
  90. //flex: 0.5;
  91. text-align: center;
  92. display: flex;
  93. justify-content: center;
  94. align-items: center;
  95. flex-direction: column;
  96. width: 150rpx;
  97. background-color: transparent;
  98. transition: all 0.5s ease-in-out;
  99. margin: auto;
  100. .tab_img {
  101. width: 50rpx;
  102. height: 50rpx;
  103. }
  104. .tab_text {
  105. font-size: 24rpx;
  106. margin-top: 10rpx;
  107. flex: 1;
  108. }
  109. }
  110. }
  111. </style>