<template>
  <div />
</template>

<script>
import CryptoJS from 'crypto-js'
import Cookie from 'js-cookie'

export default {
    name: 'SSOLogin',
    data() {
        return {
            loading: false,
            redirect: undefined
        }
    },
    watch: {},
    created() {
        // console.log('this.$route', this.$route)
        // console.log('window.location.href', window.location.href)
        window.localStorage.clear()
        // 第三方平台登录
        this.getLoginByToken()
    },
    methods: {
        // 第三方平台单点登录系统
        getLoginByToken() {
            // 获取地址栏中的token
            var token = this.$route.query
            // alert('token: ' + token)
            // console.log('token===', token)
            // console.log('loginid===', token.loginid)
            // 调用登录的接口
            if (token == '' || token == undefined || token == null) {
                // 无token，跳转到登录页面
                this.$router.push({ path: '/login' }).catch(() => {})
            } else {
                // 免密登录
                const postForm = {
                    url: 'loginSecret',
                    username: token.loginid,
                    password: '',
                    validateCode: ''
                }
                this.$store
                    .dispatch('user/ssoLogin', postForm)
                    .then((res) => {
                        console.log('res', res)
                        if (res.result) {
                            this.$router.push({ path: '/backstage?menuIndex=1296067156231847936&subMenu=1296067784098185216' })
                        } else {
                            this.$message(res.msg)
                            this.$router.push({ path: '/login' }).catch(() => {})
                        }
                    }).catch((e) => {
                        this.$router.push({ path: '/login' }).catch(() => {})
                    // console.log(e)
                    })
            }
        },
        baseRequest(opUrl, postData) {
            return this.$channel.globeRequest('pub', opUrl, postData, 'project')
        }
    }
}
</script>
