<template>
|
<div :class="'login-background linear-gradient-'+bgImgRandom">
|
<div class="login-box">
|
<h3 class="title"> 正在使用 code 授权码,进行 accessToken 访问令牌的获取 </h3>
|
</div>
|
<div class="power-by">Powered By <a target="_blank" href="https://xxxx">iailab</a></div>
|
</div>
|
</template>
|
|
<script lang="ts" setup>
|
import {useRouter} from "vue-router";
|
import {onMounted, ref} from "vue";
|
import axios from "axios";
|
|
defineOptions({ name: 'Callback' })
|
|
const {currentRoute} = useRouter();
|
|
import { config } from '@/config/axios/config'
|
import * as authUtil from "@/utils/auth";
|
|
const { base_url} = config
|
|
let router = useRouter();
|
|
const bgImgRandom = ref(Math.ceil(Math.random() * 5))
|
|
onMounted(() => {
|
ssoPasswordLogin()
|
})
|
|
const ssoPasswordLogin = () => {
|
|
// 获得 code 授权码
|
const code = currentRoute.value.query.code;
|
if (!code) {
|
alert('获取不到 code 参数,请排查!')
|
return;
|
}
|
|
// 提交
|
const redirectUri = 'http://127.0.0.1:9000/callback'; // 需要修改成,你回调的地址,就是在 index.html 拼接的 redirectUri
|
axios({
|
url: base_url + "/sms/auth/loginBycode?code=" + code + '&redirectUri=' + redirectUri,
|
method: 'POST',
|
headers: {
|
'tenant-id': '172', // 多租户编号,写死
|
}
|
}).then((result) => {
|
const res = result.data
|
console.log(res.data)
|
if (res.code != 0) {
|
alert('获得访问令牌失败!')
|
return;
|
}
|
// 设置到 localStorage 中
|
authUtil.setToken(res.data)
|
alert('获得访问令牌成功!点击确认,跳转回首页')
|
// 跳转回首页
|
router.push("/index")
|
})
|
}
|
|
</script>
|
<style lang="scss" scoped>
|
|
.title {
|
margin: 0px auto 40px auto;
|
text-align: center;
|
color: #505458;
|
}
|
|
.login-box {
|
margin: 0 auto;
|
width: 350px;
|
padding: 120px 35px 15px 35px;
|
}
|
|
.power-by {
|
position: absolute;
|
bottom: 0;
|
text-align: center;
|
color: #888;
|
padding: 10px 0;
|
width: 100%;
|
}
|
|
.power-by a {
|
color: #888;
|
padding: 10px 0;
|
width: 100%;
|
}
|
</style>
|