<template>
  <div id="app">
    <transition name="fade">
      <keep-alive>
        <router-view v-if="$route.meta.keepAlive" />
      </keep-alive>
    </transition>
    <transition name="fade">
      <router-view v-if="!$route.meta.keepAlive" />
    </transition>
  </div>
</template>

<script>
import { queryTeacherInfo } from "@/api/app";
export default {
  name: "app",
  async created() {
    const whiteList = ["#/order"];
    // const routePath = this.$route.path;
    const locationHash = window.location.hash;
    // console.log(this.$route.path, locationHash);
    if (locationHash.indexOf('#/order') == -1) {
      try {
        let Authorization = this.getQueryVariable("Authorization") || null;
        if (window.location.hash.indexOf("+") >= 0) {
          Authorization = Authorization ? Authorization.split("+")[1] : null;
          Authorization = "bearer " + Authorization;
        } else {
          Authorization = decodeURI(Authorization);
        }
        if (Authorization && Authorization != "null") {
          localStorage.setItem("Authorization", Authorization);
          localStorage.setItem("userInfo", Authorization);
        }
        const auth = localStorage.getItem("Authorization") || "";
        const userInfo = localStorage.getItem("userInfo") || "";
        if (userInfo || auth) {
          await queryTeacherInfo().then((res) => {
            const result = res.data || null;
            const tenantId = result.data.tenantId || 0;
            sessionStorage.setItem("tenantId", tenantId);
          });
        }
      } catch (e) {
        console.log(e);
      }
    }
  },
  async mounted() {
    if (document.querySelector("#m_loading")) {
      document.querySelector("#m_loading").remove();
    }
  },
  methods: {
    getQueryVariable(variable) {
      if (window.location.hash.indexOf("?") < 0) {
        return null;
      }
      let query = window.location.hash.split("?")[1];
      let vars = query.split("&");
      for (let i = 0; i < vars.length; i++) {
        let pair = vars[i].split("=");
        if (pair[0] == variable) {
          return pair[1];
        }
      }
      return false;
    },
  },
};
</script>

<style lang="less">
@import url("./assets/commonLess/common");
#app {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: #f3f4f8;
  // overflow-x: hidden;
  // overflow-y: auto;
  user-select: none;
  -webkit-text-size-adjust: none !important;
}

// /deep/.van-icon.van-icon-success{

// }
// .fade-enter-active,
// .fade-leave-active {
//   transition: opacity 0.5s;
// }
// .fade-enter,
// .fade-leave-active {
//   opacity: 0;
// }
body {
  -webkit-text-size-adjust: none !important;
}
</style>
