App.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <van-nav-bar
  3. v-if="route.meta.navbar"
  4. :left-arrow="route.meta.leftArrow"
  5. @click-left="goBack()"
  6. :title="$t(route.meta.title)"
  7. class="app-bar-header"
  8. :style="notchStyle"
  9. />
  10. <div class="main" :style="appMainViewStyle">
  11. <RouterView />
  12. </div>
  13. </template>
  14. <script setup>
  15. import { checkAndUpdate } from "@/updater/index";
  16. import { getNotchHeight } from "@/utils/statusBar";
  17. const route = useRoute();
  18. const router = useRouter();
  19. const height = ref(0);
  20. const notchStyle = ref({});
  21. const appMainViewStyle = computed(() => {
  22. let mainHeight = 0
  23. if (route.meta.navbar) mainHeight = height.value + 46;
  24. if (route.meta.tabbar) mainHeight = mainHeight + 60
  25. return {
  26. height: `calc(100vh - ${mainHeight}px)`
  27. };
  28. });
  29. const goBack = () => {
  30. if (route.meta.navbar) {
  31. if (route.meta.to) {
  32. router.push({
  33. path: route.meta.to,
  34. });
  35. return;
  36. }
  37. router.back();
  38. }
  39. };
  40. onBeforeMount(async () => {
  41. const getLoadingNode = document.getElementById("Loading");
  42. const { body } = document;
  43. if (getLoadingNode) {
  44. body.removeChild(getLoadingNode);
  45. }
  46. height.value = await getNotchHeight();
  47. notchStyle.value = {
  48. paddingTop: `${height.value}px`,
  49. };
  50. });
  51. onMounted(() => {
  52. checkAndUpdate()
  53. })
  54. </script>
  55. <style lang="less">
  56. body {
  57. margin: 0;
  58. overflow: hidden;
  59. height: 100%;
  60. background-color: @bg-color2;
  61. }
  62. </style>
  63. <style scoped lang="less">
  64. .app-container {
  65. background-color: #000;
  66. }
  67. .app-bar-header {
  68. :deep(.van-nav-bar__title) {
  69. font-weight: 500;
  70. }
  71. :deep(.van-icon) {
  72. color: @font-color3;
  73. }
  74. }
  75. </style>