Commit 7093ed399737ef6484a62c50ae89f19976a8aef0

Authored by YunaiV
1 parent 3cd256f7

【修复】钉钉登录时,重定向后 type 丢失导致报错的问题

yudao-ui-admin/src/views/login.vue
@@ -258,7 +258,8 @@ export default { @@ -258,7 +258,8 @@ export default {
258 // 设置登录中 258 // 设置登录中
259 this.loading = true; 259 this.loading = true;
260 // 计算 redirectUri 260 // 计算 redirectUri
261 - const redirectUri = location.origin + '/social-login?type=' + socialTypeEnum.type + '&redirect=' + (this.redirect || "/"); // 重定向不能丢 261 + const redirectUri = location.origin + '/social-login?'
  262 + + encodeURIComponent('type=' + socialTypeEnum.type + '&redirect=' + (this.redirect || "/")); // 重定向不能丢
262 // const redirectUri = 'http://127.0.0.1:48080/api/gitee/callback'; 263 // const redirectUri = 'http://127.0.0.1:48080/api/gitee/callback';
263 // const redirectUri = 'http://127.0.0.1:48080/api/dingtalk/callback'; 264 // const redirectUri = 'http://127.0.0.1:48080/api/dingtalk/callback';
264 // 进行跳转 265 // 进行跳转
yudao-ui-admin/src/views/socialLogin.vue
@@ -104,24 +104,19 @@ export default { @@ -104,24 +104,19 @@ export default {
104 state: undefined, 104 state: undefined,
105 }; 105 };
106 }, 106 },
107 - // watch: {  
108 - // $route: {  
109 - // handler: function(route) {  
110 - // this.redirect = route.query && route.query.redirect;  
111 - // },  
112 - // immediate: true  
113 - // }  
114 - // },  
115 created() { 107 created() {
116 this.getCookie(); 108 this.getCookie();
117 // 验证码开关 109 // 验证码开关
118 this.captchaEnable = getCaptchaEnable(); 110 this.captchaEnable = getCaptchaEnable();
119 // 重定向地址 111 // 重定向地址
120 - this.redirect = this.$route.query.redirect ? decodeURIComponent(this.$route.query.redirect) : undefined; 112 + this.redirect = this.getUrlValue('redirect');
121 // 社交登录相关 113 // 社交登录相关
122 - this.type = this.$route.query.type; 114 + this.type = this.getUrlValue('type');
123 this.code = this.$route.query.code; 115 this.code = this.$route.query.code;
124 this.state = this.$route.query.state; 116 this.state = this.$route.query.state;
  117 +
  118 + // 尝试登录一下
  119 + this.loading = true;
125 this.$store.dispatch("SocialLogin", { 120 this.$store.dispatch("SocialLogin", {
126 code: this.code, 121 code: this.code,
127 state: this.state, 122 state: this.state,
@@ -183,6 +178,10 @@ export default { @@ -183,6 +178,10 @@ export default {
183 }); 178 });
184 } 179 }
185 }); 180 });
  181 + },
  182 + getUrlValue(key) {
  183 + const url = new URL(decodeURIComponent(location.href));
  184 + return url.searchParams.get(key);
186 } 185 }
187 } 186 }
188 }; 187 };