<template>
  <div class="school" v-if="isShow">
    <!-- 左边区域 -->
    <SchoolLeft />

    <!-- 右边区域 -->
    <SchoolRight />
  </div>
</template>

<script setup lang="ts">
import SchoolLeft from "@/components/school/schoolLeft.vue";
import SchoolRight from "@/components/school/schoolRight.vue";
import { onMounted, ref } from "vue";
// @ts-ignore
import { getQueryString } from "@/utils/getParams.ts";
import { useRouter } from "vue-router";
// @ts-ignore
import { handleVerifyToken } from "@/utils/verifyToken.ts";

// 路由器实例
const $router = useRouter();

// 是否展示页面
const isShow = ref(false);

onMounted(() => {
  let token = sessionStorage.getItem("WANZAI-TOKEN");
  // console.log(token);

  if (token) {
    handleVerify(token);
  } else {
    // 获取token
    getToken();
  }
});

// 获取token
const getToken = async () => {
  let token = getQueryString("token");
  // console.log(token);

  // 判断是否存在token
  if (!token) {
    $router.push("404");
  } else {
    handleVerify(token);
  }
};

const handleVerify = async (token: string) => {
  let flag = await handleVerifyToken(token);
  // console.log(flag);
  if (flag) {
    sessionStorage.setItem("WANZAI-TOKEN", token);
    isShow.value = true;
  } else {
    $router.push("404");
  }
};
</script>

<style lang="scss" scoped>
.school {
  position: relative;
  display: flex;
  justify-content: space-between;
  padding: 25px 17px 0 17px;
  height: 997px;
}
</style>
