<template>
  <router-view class="bg-white" />
</template>
<script lang="ts" setup>
import { defineComponent, provide } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import Cookie from 'js-cookie'
defineComponent({
  name: 'IndentManageIndex',
})
provide('mediaRegExp', /^(https?:)?\/\/.+(.com.au\/|.com\/)/)
const $route = useRoute()
const token = Cookie.get('indent-token')

// 访问非登录页, 未登录状态调整登录页
if (!token && $route.path !== '/indent-manage/login') {
  const $router = useRouter()
  const originQuery = $route.query as {
    [key: string]: string
  }
  const params: any = {
    origin: encodeURIComponent($route.fullPath),
  }

  if (originQuery.u?.length && originQuery.p?.length) {
    params.action = 'autoLogin'
    params.p = originQuery.p.trim()
    params.u = originQuery.u.trim()
  }
  console.log('未登录重定向')
  $router.replace({
    path: '/indent-manage/login',
    query: params,
  })
}
</script>
<style>
.bg-white {
  background-color: #fefefe;
}
</style>
