<template></template>

<script setup>
import { ref, onMounted } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import {
  setItem
} from "@/utils/storage";
const loginDialog = ref(false);
const deptList = ref([]);
const deptId = ref("");
const store = useStore();
const origin = location.origin;
function redirectAuth() {

  let token = location.hash.slice(20) || null;
  if (token != null) {
    token = token.replace(/\ +/g, "");
    setItem("SSOTOKEN", token)
    handleLogin({ token: token, systemId: "XLFK_ZHJMXFZAGK" });
  } else {
    const str = `${origin}/#/oatuh_login`
    window.location.href = `http://80.149.27.78:8001/login?callbackurl=${encodeURIComponent(str)}`;
  }
}

const handleLogin = (e) => {
  store.dispatch("user/oatuhLogin", e).then((res) => {
    // 登录后操作
    if (res.deptList.length === 1) {
      window.location.hash = "/situationPresentation";
    } else {
      deptList.value = [...res.deptList];
      loginDialog.value = true;
      authorization.value = res.jwtToken;
    }
  });
};
onMounted(() => {
  redirectAuth();
});
</script>

<style></style>