<template>
  <div class="ele-body"> </div>
</template>

<script lang="ts" setup>
  // 自动登录
  import { onMounted, unref } from 'vue';
  import { login } from '@/api/passport/login';
  import { cleanPageTabs, goHomeRoute } from '@/utils/page-tab-util';
  import { message } from 'ant-design-vue';
  import { getToken } from '@/utils/token-util';
  import { useRouter } from 'vue-router';

  const { currentRoute } = useRouter();
  // 以游客身份登录网站
  onMounted(() => {
    login({
      tenantId: 5,
      password: '123456',
      remember: true,
      username: '游客'
    })
      .then(() => {
        cleanPageTabs();
        goHome();
      })
      .catch((e: Error) => {
        message.error(e.message);
      });
  });

  /* 跳转到首页 */
  const goHome = () => {
    const { query } = unref(currentRoute);
    goHomeRoute(query.from as string);
  };

  if (getToken()) {
    goHome();
  }
</script>

<script lang="ts">
  export default {
    name: 'AutomaticLogin'
  };
</script>
