<template>
  <div v-loading="wstLoading" class="login1">
    <div class="main">
      <img src="../../assets/img/login_bg.jpg" alt class="img1" />
    </div>
  </div>
</template>

<script>
import singleLogin from "@/utils/singleLogin/index";
import { getToken } from "./service";
import { TOKEN_KEY } from "@/utils/enum/token";
import { DataCenterRouter } from "@/route/dataCenter";

export default {
  name: "sso",
  data() {
    return {
      wstLoading: false,
    };
  },
  watch: {},
  created() {
    localStorage.removeItem(TOKEN_KEY);
    this.wstLogin();
  },
  mounted() {},
  methods: {
    wstLogin() {
      this.wstLoading = true;
      singleLogin()
        .then(async (res) => {
          const { data } = res;
          localStorage.setItem(TOKEN_KEY, data);

          this.$router.push(DataCenterRouter.DATA_MAP);
        })
        .catch(() => {
          this.$message.error("身份验证失败");
          this.$router.push("/login");
        })
        .finally(() => {
          this.wstLoading = false;
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.login1 {
  width: 100%;
  height: 100%;
  .main {
    width: 100%;
    height: 100%;
    .img1 {
      width: 100%;
      height: 100%;
    }
  }
}
</style>
