<template>
  <div v-loading="loading" style="width: 100vw; height: 100vh" />
</template>

<script>
import Cookies from "js-cookie";

export default {
  data() {
    return {
      loading: true,
      loginForm: {
        code: "",
      },
    };
  },
  created() {
    console.log("0-前端进入登录判断username参数，分发到不同路径。");
    this.loginForm.code = this.$route.query.username;

    if (this.$route.query.username) {
      console.log("2、CAS登录回来了，现在开始登录岗检系统。");
      this.$store
        .dispatch("LoginSso", this.loginForm)
        .then(() => {
          console.log("请回回来了，关闭弹窗-前");
          this.loading = false;
          console.log("请回回来了，关闭弹窗-后，转发到首页 / ");
          const redirect = window.localStorage.getItem("redirect");
          if (redirect) {
            this.$router.push({ path: redirect }).catch(() => {});
            window.localStorage.removeItem("redirect");
          } else {
            this.$router.push({ path: "/" }).catch(() => {});
          }
        })
        .catch(() => {
          this.loading = false;
        });
    }
    // else if(this.$route.query.service){
    //   console.log("3、系统发现没有Token了，跳转CAS退出页面，CAS会自己转回到CAS登录。")
    //   console.log("3、系统发现没有Token了，跳转CAS退出页面，CAS会自己转回到CAS登录。")
    //   window.location.href = 'http://10.152.70.21:8080/cas/logout?service=http://10.152.164.68:8180/redirectpostcheck'
    // }
    else {
      console.log("1、前端去登录CAS，清除Cookies信息。");
      Cookies.remove("username");
      Cookies.remove("password");
      Cookies.remove("rememberMe");

      console.log(
        "1、前端去登录CAS， window.location.href = 'http://10.152.164.68:8180/redirectpostcheck'"
      );
      this.loading = false;
      // window.location.href = "http://10.152.164.68:8180/redirectpostcheck";
      window.location.href = `${this.getBaseUrl()}/redirectpostcheck`;
      // this.$store.dispatch("casLogin")
      // .then(() => {
      //   this.loading = false;
      // })
      // .catch(() => {
      //   this.loading = false;
      // });
    }
  },
};
</script>

<style></style>
