App.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. import { setupNotifications } from "@/utils/notifications.js";
  18. import { useWalletStore } from "@/stores/modules/walletStore";
  19. import { useWebSocketStore } from "@/stores/modules/webSocketStore.js";
  20. const route = useRoute();
  21. const router = useRouter();
  22. const walletStore = useWalletStore();
  23. const wsStore = useWebSocketStore();
  24. const height = ref(0);
  25. const notchStyle = ref({});
  26. const appMainViewStyle = computed(() => {
  27. let mainHeight = 0;
  28. if (route.meta.navbar) mainHeight = height.value + 46;
  29. if (route.meta.tabbar) mainHeight = mainHeight + 60;
  30. return {
  31. height: `calc(100vh - ${mainHeight}px)`,
  32. };
  33. });
  34. const goBack = () => {
  35. if (route.meta.navbar) {
  36. if (route.meta.to) {
  37. router.push({
  38. path: route.meta.to,
  39. });
  40. return;
  41. }
  42. router.back();
  43. }
  44. };
  45. onBeforeMount(async () => {
  46. const getLoadingNode = document.getElementById("Loading");
  47. const { body } = document;
  48. if (getLoadingNode) {
  49. body.removeChild(getLoadingNode);
  50. }
  51. height.value = await getNotchHeight();
  52. notchStyle.value = {
  53. paddingTop: `${height.value}px`,
  54. };
  55. console.log("process.env.NODE_ENV=",process.env.NODE_ENV)
  56. // 检查更新:开发环境不检测更新
  57. if (process.env.NODE_ENV !== "development") {
  58. checkAndUpdate();
  59. }
  60. });
  61. onMounted(() => {
  62. // 0.5秒后执行
  63. // setTimeout(() => {
  64. // setupNotifications(2);
  65. // }, 500);
  66. // setTimeout(() => {
  67. // setupNotifications(3);
  68. // }, 500);
  69. // setTimeout(() => {
  70. // setupNotifications(4);
  71. // }, 500);
  72. // setTimeout(() => {
  73. // setupNotifications(5);
  74. // }, 500);
  75. // setTimeout(() => {
  76. // setupNotifications(5);
  77. // }, 2500);
  78. // setTimeout(() => {
  79. // setupNotifications(15);
  80. // }, 1500);
  81. // setupNotifications(5);
  82. // setupNotifications(6);
  83. });
  84. watch(
  85. () => walletStore.account,
  86. (val) => {
  87. if (val) {
  88. wsStore.connect(walletStore.getAccount);
  89. }
  90. },
  91. {
  92. immediate: true, // 默认立即执行
  93. }
  94. );
  95. onUnmounted(() => {
  96. wsStore.close();
  97. });
  98. </script>
  99. <style lang="less">
  100. body {
  101. margin: 0;
  102. overflow: hidden;
  103. height: 100%;
  104. background-color: @bg-color2;
  105. }
  106. </style>
  107. <style scoped lang="less">
  108. .app-container {
  109. background-color: #000;
  110. }
  111. .app-bar-header {
  112. :deep(.van-nav-bar__title) {
  113. font-weight: 500;
  114. font-size: 19px;
  115. color: #000000;
  116. }
  117. :deep(.van-icon) {
  118. color: @font-color3;
  119. }
  120. }
  121. </style>