<template>
    <div>
        <SldHomeTopSearch/>
        <NavCatHeader/>
        <div class="bottom_line"></div>
        <div class="error_page flex_column_center_center">
            <div class="error_page_logo"></div>
            <div class="error_page_tips">The page is jumping......</div>
        </div>
    </div>
</template>
<script>
    import {ref, onMounted} from 'vue';
    import {useUserInfo} from "@/store/user.js";
    import {useFiltersStore} from "@/store/filter.js";

    export default {
        name: "OauthLink",
        setup() {
            const route = useRoute()
            const router = useRouter();
            const oauthKey = ref("");
            const configInfo = useUserInfo();
            const filtersStore = useFiltersStore();

            onMounted(() => {
                oauthKey.value = route.query.oauthKey;
                if (oauthKey.value != null && oauthKey.value != "" && oauthKey.value != undefined) {
                    let param = {};
                    param.oauthKey = oauthKey.value;
                    post("v3/open/api/sso/login/pc", param, 1000 * 30).then(res => {
                        if (res.state == 200) {
                            //将用户信息存缓存，并跳转到首页
                            filtersStore.setLoginStatus(true);
                            filtersStore.setToken(res.data.access_token);
                            filtersStore.setRefreshToken(res.data.refresh_token)
                            filtersStore.setTime(new Date().getTime().toString())//存储refresh_token更新时间
                            get("v3/member/front/member/getInfo").then(res => {
                                if (res.state == 200) {
                                    filtersStore.setMemberInfo(res.data)
                                    if (window.history.state.back) {
                                        router.back();
                                    } else {
                                        router.replace({path: '/member/home'})
                                    }
                                } else {
                                    router.replace({path: '/login'})
                                }
                            });
                        } else {
                            router.replace({path: '/login'})
                        }
                    });

                } else {
                    router.replace({path: '/login'})
                }
            })

            return {configInfo, oauthKey}
        },
    };
</script>

<style lang="scss" scoped>
    .error_page {
        padding-top: 80px;
        padding-bottom: 100px;
        border-top: 3px solid $colorMain;

        .error_page_logo {
            width: 249px;
            height: 271px;
            background-image: url('/jump_logo.png');
            background-position: center;
            background-repeat: no-repeat;
            background-size: contain;
        }

        .error_page_tips {
            line-height: 70px;
            color: #333333;
            font-size: 24px;
            font-weight: bold;
            margin-top: 85px;
            margin-bottom: 0px;
            cursor: default;
        }
    }
</style>
