App.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <script setup>
  2. import { ref, onMounted, nextTick, watch, onBeforeUnmount, getCurrentInstance } from 'vue';
  3. import { useI18n } from "vue-i18n";
  4. const { locale } = useI18n();
  5. import {
  6. onLoad,
  7. onShow,
  8. onLaunch
  9. } from '@dcloudio/uni-app'
  10. import {
  11. updateRoute
  12. } from "@/hooks/useRoute";
  13. import useGlobalStore from "@/stores/use-global-store";
  14. import { useAppUpdate } from '@/hooks/useAppUpdate'
  15. import liveChat from '@/utils/liveChat';
  16. const { checkUpdate } = useAppUpdate()
  17. const globalStore = useGlobalStore()
  18. onLoad((options) => {
  19. updateRoute();
  20. checkUpdate()
  21. })
  22. onShow((options) => {
  23. updateRoute();
  24. checkUpdate()
  25. })
  26. onLaunch((options) => {
  27. updateRoute();
  28. checkUpdate()
  29. })
  30. const adjustLiveChatPosition = () => {
  31. // #ifdef H5
  32. const footerBody = document.getElementById('footer-body');
  33. if (footerBody) {
  34. liveChat.adjustPosition(footerBody.offsetHeight);
  35. }
  36. // #endif
  37. }
  38. watch(locale, () => {
  39. console.log(locale.value, 23123)
  40. const currentPath = route.path;
  41. menu.value.forEach((item, index) => {
  42. if (item.children) {
  43. const isActive = item.children.some(child => child.path.includes(currentPath));
  44. menu.value[index].isOpenMenu = isActive;
  45. if (isActive) {
  46. nextTick(() => {
  47. updateSubmenuHeight(index);
  48. });
  49. }
  50. }
  51. });
  52. }, { immediate: true })
  53. onBeforeUnmount(() => {
  54. // #ifdef H5
  55. if (typeof window !== 'undefined') {
  56. window.removeEventListener('resize', adjustLiveChatPosition)
  57. }
  58. // #endif
  59. })
  60. onMounted(() => {
  61. const sysInfo = uni.getSystemInfoSync();
  62. globalStore.setBarHeight(sysInfo.statusBarHeight);
  63. // ---------- 新增 H5 端专属初始化 ----------
  64. // 仅在 H5 端执行(通过环境判断)
  65. // #ifdef H5
  66. if (typeof window !== 'undefined') {
  67. const instance = getCurrentInstance()
  68. if (instance) {
  69. window.vm = instance.proxy
  70. }
  71. // 调用一次调整位置
  72. adjustLiveChatPosition()
  73. // 监听窗口大小变化,动态调整
  74. window.addEventListener('resize', adjustLiveChatPosition)
  75. }
  76. // #endif
  77. });
  78. </script>
  79. <style>
  80. /*每个页面公共css */
  81. </style>
  82. <style lang="scss">
  83. /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
  84. @import "uview-plus/index.scss";
  85. @import "@/static/scss/global/global.scss";
  86. @import "/static/scss/style.scss";
  87. /* 让整个项目文字都能选中 */
  88. * {
  89. -webkit-user-select: text !important;
  90. user-select: text !important;
  91. }
  92. /* 修复滚动层无法选中 */
  93. view,
  94. text,
  95. div,
  96. span {
  97. -webkit-user-select: text !important;
  98. user-select: text !important;
  99. }
  100. :deep(.u-toolbar__wrapper__confirm) {
  101. font-size: 20px !important;
  102. }
  103. :deep(.u-toolbar__wrapper__cancel) {
  104. font-size: 20px !important;
  105. }
  106. .page {
  107. /* padding: 31px 31px 110px 31px; */
  108. box-sizing: border-box;
  109. /* background: var(--main-bg); */
  110. }
  111. html {
  112. font-size: 32px !important;
  113. }
  114. uni-page-body {
  115. height: 100%;
  116. }
  117. </style>