App.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <div id="app">
  3. <div v-if="!loading">
  4. <transition name="fade">
  5. <keep-alive>
  6. <router-view v-if="$route.meta.keepAlive" />
  7. </keep-alive>
  8. </transition>
  9. <transition name="fade">
  10. <router-view v-if="!$route.meta.keepAlive" />
  11. </transition>
  12. </div>
  13. </div>
  14. </template>
  15. <script>
  16. import { queryTeacherInfo } from "@/api/app";
  17. export default {
  18. name: "app",
  19. data() {
  20. return {
  21. loading: true,
  22. };
  23. },
  24. async created() {
  25. const whiteList = ["#/order"];
  26. // const routePath = this.$route.path;
  27. const locationHash = window.location.hash;
  28. // console.log(this.$route.path, locationHash);
  29. this.loading = true;
  30. if (locationHash.indexOf("#/order") == -1 && locationHash.indexOf("#/shareCreation") == -1) {
  31. try {
  32. let Authorization = this.getQueryVariable("Authorization") || null;
  33. if (window.location.hash.indexOf("+") >= 0) {
  34. Authorization = Authorization ? Authorization.split("+")[1] : null;
  35. Authorization = "Bearer " + Authorization;
  36. } else {
  37. Authorization = decodeURI(Authorization);
  38. }
  39. if (Authorization && Authorization != "null") {
  40. localStorage.setItem("Authorization", Authorization);
  41. localStorage.setItem("userInfo", Authorization);
  42. }
  43. const auth = localStorage.getItem("Authorization") || "";
  44. const userInfo = localStorage.getItem("userInfo") || "";
  45. if (userInfo || auth) {
  46. await queryTeacherInfo().then((res) => {
  47. const result = res.data || null;
  48. const tenantId = result.data.tenantId || 0;
  49. sessionStorage.setItem("tenantId", tenantId);
  50. sessionStorage.setItem("userId", result.data.id || 0);
  51. });
  52. }
  53. } catch (e) {
  54. console.log(e);
  55. }
  56. }
  57. this.loading = false;
  58. },
  59. async mounted() {
  60. if (document.querySelector("#m_loading")) {
  61. document.querySelector("#m_loading").remove();
  62. }
  63. },
  64. methods: {
  65. getQueryVariable(variable) {
  66. if (window.location.hash.indexOf("?") < 0) {
  67. return null;
  68. }
  69. let query = window.location.hash.split("?")[1];
  70. let vars = query.split("&");
  71. for (let i = 0; i < vars.length; i++) {
  72. let pair = vars[i].split("=");
  73. if (pair[0] == variable) {
  74. return pair[1];
  75. }
  76. }
  77. return false;
  78. },
  79. },
  80. };
  81. </script>
  82. <style lang="less">
  83. @import url("./assets/commonLess/common");
  84. #app {
  85. font-family: "Avenir", Helvetica, Arial, sans-serif;
  86. -webkit-font-smoothing: antialiased;
  87. -moz-osx-font-smoothing: grayscale;
  88. background: #f3f4f8;
  89. // overflow-x: hidden;
  90. // overflow-y: auto;
  91. user-select: none;
  92. -webkit-text-size-adjust: none !important;
  93. overflow: hidden;
  94. }
  95. // /deep/.van-icon.van-icon-success{
  96. // }
  97. // .fade-enter-active,
  98. // .fade-leave-active {
  99. // transition: opacity 0.5s;
  100. // }
  101. // .fade-enter,
  102. // .fade-leave-active {
  103. // opacity: 0;
  104. // }
  105. body {
  106. -webkit-text-size-adjust: none !important;
  107. }
  108. </style>