<template>
    <div class="error404">
         <error code="403" title="您的账号权限不足，请联系管理员添加权限！" :show-btn="false">
            <template #content>
                <div class="flex justify-center">
                    <img class="w-[150px] h-[150px]" src="@/assets/images/no_perms.png" alt="" />
                </div>
            </template>
        </error>
    </div>
</template>

<script lang="ts" setup>
import Error from './components/error.vue'
import { onMounted } from 'vue'
import { useRoute } from 'vue-router'
import {PageEnum} from "@/enums/pageEnum"
import {clearAuthInfo} from "@/utils/auth";
const router = useRouter()

const route = useRoute()

// 从环境变量获取白名单
const allowedDomains = import.meta.env.VITE_ALLOWED_DOMAINS?.split(',') || []
console.warn("***allowedDomains***",allowedDomains)
onMounted(() => {
    const redirectUrl = allowedDomains[0]
    // const redirectUrl = route.query.redirect as string
    if (redirectUrl) {
        try {
            const url = new URL(decodeURIComponent(redirectUrl))
            // const isAllowed = allowedDomains.some((domain: string) =>
            //     url.hostname.endsWith(domain)
            // )

            if (url) {
                setTimeout(() => {
                    // window.location.href = url.toString()
                  clearAuthInfo()
                  router.push(PageEnum.LOGIN)
                }, 1500)
            } else {
                console.error(`不安全的跳转地址:`, redirectUrl)
            }
        } catch (e) {
            console.error('URL 解析错误:', e)
        }
    }
})
</script>
