<template>
  <div id="app" :class="{ mobileApp: isMobile }">
    <router-view />
  </div>
</template>

<script>
import settting from "@/settings.js";

export default {
  name: "App",
  data() {
    let isMobile = this.getIsMobile();
    return {
      isMobile: isMobile,
    };
  },
  created() {
    if (settting.reflushRouter!== true && process.env.NODE_ENV !== "development") {
      window.addEventListener(
        "hashchange",
        (event) => {
          var currentPath = window.location.hash.slice(1).split("?")[0]; // 获取输入的路由
          if (
            currentPath != "/404" &&
            currentPath != "/login" &&
            this.$router.path !== currentPath
          ) {
            this.$store.dispatch("tagsView/delAllViews").then((visitedViews) => {
              this.$router.replace({ path: "/redirect" + "/home" });
            });
          }
        },
        false
      );

      window.addEventListener("beforeunload", async (event) => {
        // 如果按下的键是 F5，则执行相应的操作
        var currentPath = window.location.hash.slice(1).split("?")[0]; // 获取输入的路由
        if (
          currentPath != "/home" &&
          currentPath != "/" &&
          currentPath != "/login" &&
          currentPath != "/404"
        ) {
          sessionStorage.setItem("toHome", "1");
        }
      });
    }

    document.title = settting.title;
  },
  mounted() {},
  methods: {
    getIsMobile() {
      const userAgent = navigator.userAgent;
      const mobileRegex = /Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/i;
      return mobileRegex.test(userAgent);
    },
  },
};
</script>
<style>
.inner-dialog .el-dialog__wrapper {
  top: 0;
}

/* #app .el-submenu .el-menu {
  height: 500px;
} */
</style>
