From 7093ed399737ef6484a62c50ae89f19976a8aef0 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 12 Nov 2022 13:27:46 +0800 Subject: [PATCH] 【修复】钉钉登录时,重定向后 type 丢失导致报错的问题 --- yudao-ui-admin/src/views/login.vue | 3 ++- yudao-ui-admin/src/views/socialLogin.vue | 19 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/yudao-ui-admin/src/views/login.vue b/yudao-ui-admin/src/views/login.vue index 785235d..280cbd2 100644 --- a/yudao-ui-admin/src/views/login.vue +++ b/yudao-ui-admin/src/views/login.vue @@ -258,7 +258,8 @@ export default { // 设置登录中 this.loading = true; // 计算 redirectUri - const redirectUri = location.origin + '/social-login?type=' + socialTypeEnum.type + '&redirect=' + (this.redirect || "/"); // 重定向不能丢 + const redirectUri = location.origin + '/social-login?' + + encodeURIComponent('type=' + socialTypeEnum.type + '&redirect=' + (this.redirect || "/")); // 重定向不能丢 // const redirectUri = 'http://127.0.0.1:48080/api/gitee/callback'; // const redirectUri = 'http://127.0.0.1:48080/api/dingtalk/callback'; // 进行跳转 diff --git a/yudao-ui-admin/src/views/socialLogin.vue b/yudao-ui-admin/src/views/socialLogin.vue index 0dc1abe..9364cad 100644 --- a/yudao-ui-admin/src/views/socialLogin.vue +++ b/yudao-ui-admin/src/views/socialLogin.vue @@ -104,24 +104,19 @@ export default { state: undefined, }; }, - // watch: { - // $route: { - // handler: function(route) { - // this.redirect = route.query && route.query.redirect; - // }, - // immediate: true - // } - // }, created() { this.getCookie(); // 验证码开关 this.captchaEnable = getCaptchaEnable(); // 重定向地址 - this.redirect = this.$route.query.redirect ? decodeURIComponent(this.$route.query.redirect) : undefined; + this.redirect = this.getUrlValue('redirect'); // 社交登录相关 - this.type = this.$route.query.type; + this.type = this.getUrlValue('type'); this.code = this.$route.query.code; this.state = this.$route.query.state; + + // 尝试登录一下 + this.loading = true; this.$store.dispatch("SocialLogin", { code: this.code, state: this.state, @@ -183,6 +178,10 @@ export default { }); } }); + }, + getUrlValue(key) { + const url = new URL(decodeURIComponent(location.href)); + return url.searchParams.get(key); } } }; -- libgit2 0.21.4