App.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <script setup>
  2. import config from "./config";
  3. import store from "@/store";
  4. import { getToken, setToken, removeToken } from "@/utils/auth";
  5. import { defineComponent, getCurrentInstance, inject, nextTick, onMounted, watchEffect } from "vue";
  6. import { onLoad, onShow, onHide, onLaunch, onReady } from "@dcloudio/uni-app";
  7. let tab = inject("$tab");
  8. const { proxy } = getCurrentInstance();
  9. function initApp() {
  10. // 初始化应用配置
  11. initConfig();
  12. // 检查用户登录状态
  13. //#ifdef H5
  14. // checkLogin();
  15. //#endif
  16. //初始化获取安全区高度
  17. proxy.$settingStore.systemHeightTop();
  18. }
  19. function initConfig() {
  20. getApp().globalData.config = config;
  21. }
  22. function checkLogin() {
  23. if (!getToken()) {
  24. proxy.$tab.reLaunch("/pages/login");
  25. }
  26. }
  27. watchEffect(() => {
  28. //#ifdef APP-PLUS
  29. if (uni.getStorageSync("serveUrl")) {
  30. config.baseUrl = "http://" + uni.getStorageSync("serveUrl") + "/prod-api";
  31. }
  32. //#endif
  33. });
  34. onLaunch(() => {
  35. console.log("App Launch");
  36. uni.hideTabBar(); //隐藏自带tabbar
  37. // #ifdef APP-PLUS
  38. plus.screen.lockOrientation("portrait-primary"); //设置不可横屏
  39. // #endif
  40. //初始化默认主题
  41. if (!proxy.$settingStore.$state.themeColor) {
  42. proxy.$settingStore.SET_THEMECOLOR(proxy.$constData.themeList[0]);
  43. } else {
  44. proxy.$settingStore.SET_THEMECOLOR(proxy.$settingStore.$state.themeColor);
  45. }
  46. // setToken(
  47. // "eyJhbGciOiJIUzUxMiJ9.eyIiOjEwMzIsInVzZXJfaWQiOjYzLCJ1c2VyX2tleSI6IjYwMjNkZjg1OTIyODRlYTM5MmEwMWEzMzgyOTViZmRhIiwidXNlcm5hbWUiOiJmaHMxIn0.6GsrVyPh7T3vWmX6iB1fPv3wi-noOtgGcrDwBPctB3LLGcWqw89He6DK7waMCWZFBsOy0HLRD2PJdQs489hAxw"
  48. // );
  49. // proxy.$tab.reLaunch("/pages/mine/index");
  50. // proxy.$tab.reLaunch("/pages/index");
  51. // proxy.$tab.reLaunch("/pages/info/info");
  52. // proxy.$tab.reLaunch("/pages/business/mhxf/xunJian/collect/index");
  53. initApp();
  54. });
  55. onLoad(() => {});
  56. onReady(() => {});
  57. onShow(() => {
  58. console.log("App Show");
  59. });
  60. onHide(() => {
  61. console.log("App Hide");
  62. });
  63. </script>
  64. <style lang="scss">
  65. @import "@/static/scss/index.scss";
  66. </style>
  67. <style lang="scss">
  68. @import "@/uni_modules/uview-plus/index.scss";
  69. uni-page-body,
  70. uni-page-refresh {
  71. height: 100%;
  72. }
  73. //默认返回按钮样式
  74. :deep(.uni-page-head-btn) {
  75. background-color: rgba(0, 0, 0, 0) !important;
  76. }
  77. //默认头部导航title样式
  78. :deep(.uni-page-head__title) {
  79. font-size: 16px;
  80. font-weight: 600;
  81. }
  82. //uview-plus导航栏title样式
  83. :deep(.u-navbar__content__title) {
  84. font-size: 16px;
  85. font-weight: bold;
  86. }
  87. :deep(.u-nav-slot .u-navbar__content__title) {
  88. font-size: 18px;
  89. }
  90. </style>