<template>
  <div id="app">
    <div v-if="!loading">
      <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>
  </div>
</template>

<script>
import { queryTeacherInfo } from "@/api/app";
export default {
  name: "app",
  data() {
    return {
      loading: true,
    };
  },
  async created() {
    const whiteList = ["#/order"];
    // const routePath = this.$route.path;
    const locationHash = window.location.hash;
    // console.log(this.$route.path, locationHash);
    this.loading = true;
    if (locationHash.indexOf("#/order") == -1 && locationHash.indexOf("#/shareCreation") == -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);
            sessionStorage.setItem("userId", result.data.id || 0);
          });
        }
      } catch (e) {
        console.log(e);
      }
    }
    this.loading = false;
  },
  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;
  overflow: hidden;
}

// /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>
