<template>
  <div class="not-container">
    <img src="@/assets/images/500.png" class="not-img" alt="500" />
    <div class="not-detail">
      <h2>500</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="500">
import { onMounted } from "vue";
import { HOME_URL, LOGIN_URL } from "@/config";
import { useRouter } from "vue-router";
import { useUserStore } from "@/stores/modules/user";
const router = useRouter();
const userStore = useUserStore();

const refresh = () => {
  let goPath: string = (router.currentRoute.value.query?.redirect as string) ?? HOME_URL;
  goPath = goPath.replace(/\$and\$/g, "&");
  router.push(goPath);
};

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

onMounted(() => {
  if (window.navigator.onLine) {
    refresh();
  }
});
</script>

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