App.vue 2.7 KB

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