<script setup>
import {useRouter} from 'vue-router';
import {useAuthStore} from '@/stores/userstore'
import {ElLoading} from 'element-plus'

const authStore = useAuthStore()
const router = useRouter();
const tokenValue = reactive(router.currentRoute.value.query.token)
const init = () => {
  const loading = ElLoading.service({
    lock: true,
    text: '登录中...',
    background: 'rgba(0, 0, 0, 0.7)',
  })
  if (authStore.casToken(tokenValue)) {
    loading.close()
    const toView = sessionStorage.getItem('toView')
    if (toView) {
      let parse = JSON.parse(toView);
      window.location.href = window.location.origin + parse.path + parse.query
    } else {
      router.push('/')
    }
  }
}
init()
</script>

