<template> <div class="autoLogin"></div> </template> <script setup> import { setToken } from '@/utils/auth'; import { platformLogin } from '@/api/login'; import { useRoute, useRouter } from 'vue-router'; import usePermissionStore from '@/store/modules/permission'; const router = useRouter(); const route = useRoute(); const permissionStore = usePermissionStore(); const { userToken } = route.query; if (userToken) { platformLogin({ userToken }) .then(res => { if (res.code === 200) { const token = res.data?.access_token || ''; if (token) { setToken(token); // 登录成功之后都加载对应路由 permissionStore.generateRoutes(); router.push({ path: '/sponeScreen/chengguanweiScreen' }); } else { router.push('/door'); } } else { router.push('/door'); } }) .catch(error => { console.log(error); router.push('/door'); }); } else { router.push('/door'); } onMounted(() => { localStorage.removeItem('fromDoorXG'); }); </script> <style lang="scss" scoped></style>