<template>
  <div
    v-loading="true"
    style="width: 100vw;height: 100vh"
    element-loading-text="登录中..."
  />
</template>

<script>
import CryptoJS from 'crypto-js'
import config from '@/config/index'

export default {
  name: 'Accept',
  async mounted() {
    try {
      // 解密token
      const decData = CryptoJS.enc.Base64.parse(this.$route.query.t).toString(CryptoJS.enc.Utf8)
      const decJson = CryptoJS.AES.decrypt(decData, config.secretKey).toString(CryptoJS.enc.Utf8)
      const { token } = JSON.parse(decJson)
      // 根据 token 获取用户信息...
      await this.$store.dispatch('user/loginByToken', token)
      await this.$router.push('/welcome/dashboard')
    } catch (e) {
      await this.$router.push('/login')
    }
  }
}
</script>
