提交 | 用户 | 时间
|
cb6cd2
|
1 |
<template> |
H |
2 |
<div :class="'login-background linear-gradient-'+bgImgRandom"> |
|
3 |
<div class="login-box"> |
|
4 |
<h3 class="title"> 正在使用 code 授权码,进行 accessToken 访问令牌的获取 </h3> |
|
5 |
</div> |
|
6 |
<div class="power-by">Powered By <a target="_blank" href="https://xxxx">iailab</a></div> |
|
7 |
</div> |
|
8 |
</template> |
|
9 |
|
|
10 |
<script lang="ts" setup> |
|
11 |
import {useRouter} from "vue-router"; |
|
12 |
import {onMounted, ref} from "vue"; |
|
13 |
import axios from "axios"; |
|
14 |
|
|
15 |
defineOptions({ name: 'Callback' }) |
|
16 |
|
|
17 |
const {currentRoute} = useRouter(); |
|
18 |
|
|
19 |
import { config } from '@/config/axios/config' |
|
20 |
import * as authUtil from "@/utils/auth"; |
|
21 |
|
|
22 |
const { base_url} = config |
|
23 |
|
|
24 |
let router = useRouter(); |
|
25 |
|
|
26 |
const bgImgRandom = ref(Math.ceil(Math.random() * 5)) |
|
27 |
|
|
28 |
onMounted(() => { |
|
29 |
ssoPasswordLogin() |
|
30 |
}) |
|
31 |
|
|
32 |
const ssoPasswordLogin = () => { |
|
33 |
|
|
34 |
// 获得 code 授权码 |
|
35 |
const code = currentRoute.value.query.code; |
|
36 |
if (!code) { |
|
37 |
alert('获取不到 code 参数,请排查!') |
|
38 |
return; |
|
39 |
} |
|
40 |
|
|
41 |
// 提交 |
|
42 |
const redirectUri = 'http://127.0.0.1:9000/callback'; // 需要修改成,你回调的地址,就是在 index.html 拼接的 redirectUri |
|
43 |
axios({ |
|
44 |
url: base_url + "/ansteel/auth/loginBycode?code=" + code + '&redirectUri=' + redirectUri, |
|
45 |
method: 'POST', |
|
46 |
headers: { |
|
47 |
'tenant-id': '172', // 多租户编号,写死 |
|
48 |
} |
|
49 |
}).then((result) => { |
|
50 |
const res = result.data |
|
51 |
console.log(res.data) |
|
52 |
if (res.code != 0) { |
|
53 |
alert('获得访问令牌失败!') |
|
54 |
return; |
|
55 |
} |
|
56 |
// 设置到 localStorage 中 |
|
57 |
authUtil.setToken(res.data) |
|
58 |
alert('获得访问令牌成功!点击确认,跳转回首页') |
|
59 |
// 跳转回首页 |
|
60 |
router.push("/index") |
|
61 |
}) |
|
62 |
} |
|
63 |
|
|
64 |
</script> |
|
65 |
<style lang="scss" scoped> |
|
66 |
|
|
67 |
.title { |
|
68 |
margin: 0px auto 40px auto; |
|
69 |
text-align: center; |
|
70 |
color: #505458; |
|
71 |
} |
|
72 |
|
|
73 |
.login-box { |
|
74 |
margin: 0 auto; |
|
75 |
width: 350px; |
|
76 |
padding: 120px 35px 15px 35px; |
|
77 |
} |
|
78 |
|
|
79 |
.power-by { |
|
80 |
position: absolute; |
|
81 |
bottom: 0; |
|
82 |
text-align: center; |
|
83 |
color: #888; |
|
84 |
padding: 10px 0; |
|
85 |
width: 100%; |
|
86 |
} |
|
87 |
|
|
88 |
.power-by a { |
|
89 |
color: #888; |
|
90 |
padding: 10px 0; |
|
91 |
width: 100%; |
|
92 |
} |
|
93 |
</style> |
|
94 |
|