index.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <router-view
  3. v-slot="{ Component }"
  4. >
  5. <keep-alive v-if="route.meta.keepAlive">
  6. <component :is="Component" />
  7. </keep-alive>
  8. <component :is="Component" v-if="!route.meta.keepAlive" />
  9. </router-view>
  10. <van-tabbar v-if="route.meta.tabbar" route active-color="#4765DD" inactive-color="#C4D0FF">
  11. <van-tabbar-item v-for="item in tabbarOptions" :key="item.to" replace :to="item.to">
  12. <template #icon="props">
  13. <svg-icon class="tabbar-icon" :name="item.icon" />
  14. </template>
  15. {{ item.title }}
  16. </van-tabbar-item>
  17. </van-tabbar>
  18. </template>
  19. <script setup>
  20. import { getNotchHeight} from "@/utils/statusBar";
  21. const route = useRoute();
  22. const mainStyle = ref({});
  23. const tabbarOptions = [
  24. // {
  25. // title: "社交",
  26. // icon: "tabbar-im",
  27. // to: "/im",
  28. // },
  29. {
  30. title: "交易",
  31. icon: "tabbar-transaction",
  32. to: "/transaction",
  33. },
  34. {
  35. title: "钱包",
  36. icon: "tabbar-wallet",
  37. to: "/wallet",
  38. },
  39. {
  40. title: "DAPP",
  41. icon: "tabbar-dapp",
  42. to: "/dapp",
  43. },
  44. {
  45. title: "我的",
  46. icon: "tabbar-me",
  47. to: "/me",
  48. },
  49. ];
  50. onBeforeMount(async () => {
  51. const height = await getNotchHeight();
  52. if (route.meta.navbar) {
  53. mainStyle.value.marginTop = `0 px`;
  54. } else {
  55. mainStyle.value = {
  56. marginTop: `${height}px`,
  57. };
  58. }
  59. });
  60. </script>
  61. <style scoped lang="less">
  62. .tabbar-icon{
  63. width: 25px;
  64. height: 25px;
  65. }
  66. .van-tabbar--fixed{
  67. height: calc(60px + var(--safe-area-bottom));
  68. padding: 8px 0 var(--safe-area-bottom) 0;
  69. // padding-top: 10px;
  70. box-sizing: border-box;
  71. }
  72. </style>