<template>
  <div class="not-container">
    <img src="@/assets/images/404.png" class="not-img" alt="404" />
    <div class="not-detail">
      <h2>408</h2>
      <h4>请求超时！请您稍后重试</h4>
      <div class="flx">
        <el-button type="primary" @click="refresh">重试</el-button>
        <el-button type="primary" plain @click="router.push(HOME_URL)">返回首页</el-button>
        <el-button @click="gotoLogin">返回登录页</el-button>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts" name="408">
import { onMounted } from "vue";
import { HOME_URL, LOGIN_URL } from "@/config";
import { useRouter } from "vue-router";
import { useUserStore } from "@/stores/modules/user";
import { useGlobalStore } from "@/stores/modules/global";
const router = useRouter();
const userStore = useUserStore();
const globalStore = useGlobalStore();

const refresh = () => {
  let goPath: string = (router.currentRoute.value.fullPath as string) ?? HOME_URL;
  console.log("goPath :", goPath);
  goPath = goPath.replace(/\$and\$/g, "&");
  goPath.indexOf("redirect=") > -1 && (goPath = goPath.split("redirect=")[1]);
  console.log("goPath after:>> ", goPath);
  router.push(goPath);
};

const gotoLogin = () => {
  userStore.setToken("");
  router.replace(LOGIN_URL);
};

onMounted(() => {
  if (!globalStore.is408) {
    globalStore.setGlobalState("is408", true);
  } else {
    refresh();
    globalStore.setGlobalState("is408", false);
  }
});
</script>

<style scoped lang="scss">
@import "./index.scss";
</style>
