<template>
  <div id="app" v-cloak>
    <router-view />
  </div>
</template>
<script>
export default {
  name: "App",
  data() {
    return {
      code: "",
    };
  },
  async created() {
    await this.getMenu();
  },
  methods: {
    async getMenu() {
      this.$store
        .dispatch("user/getMenuList", this)
        .then(async (res) => {
          if (res === "noToken") {
            await this.logout();
          } else if (res === "success") {
            if (
              this.$route.path === "/loadingPage" ||
              this.$route.path === "/" ||
              this.$route.path === "/login"
            ) {
              window.vm.$router.replace("/welcome");
            }
          } else {
            await this.logout();
          }
        })
        .catch(async (err) => {
          await this.logout();
        });
    },
    async logout() {
      if (this.$route.path !== "/login") {
        await this.$store.dispatch("user/logout");
        console.log(this.$route.fullPath);
        this.$router.push(`/login`);
      }
    },
  },
};
</script>
<style lang="scss">
@import "./assets/css/index.scss";
//因为element-ui的confim组件并不是vue生成的不具有[data-v....]，所以全局注入一个class
// .lzx_BtnErr{
//   background: #f56c6c !important;
//   color: #fff !important;
// }
</style>
