Skip to content

Commit f29fcae

Browse files
committed
【修复】钉钉登录时,重定向后 type 丢失导致报错的问题
1 parent 44e8ae3 commit f29fcae

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/views/login.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ export default {
258258
// 设置登录中
259259
this.loading = true;
260260
// 计算 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 || "/")); // 重定向不能丢
262263
// const redirectUri = 'http://127.0.0.1:48080/api/gitee/callback';
263264
// const redirectUri = 'http://127.0.0.1:48080/api/dingtalk/callback';
264265
// 进行跳转

src/views/socialLogin.vue

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,19 @@ export default {
104104
state: undefined,
105105
};
106106
},
107-
// watch: {
108-
// $route: {
109-
// handler: function(route) {
110-
// this.redirect = route.query && route.query.redirect;
111-
// },
112-
// immediate: true
113-
// }
114-
// },
115107
created() {
116108
this.getCookie();
117109
// 验证码开关
118110
this.captchaEnable = getCaptchaEnable();
119111
// 重定向地址
120-
this.redirect = this.$route.query.redirect ? decodeURIComponent(this.$route.query.redirect) : undefined;
112+
this.redirect = this.getUrlValue('redirect');
121113
// 社交登录相关
122-
this.type = this.$route.query.type;
114+
this.type = this.getUrlValue('type');
123115
this.code = this.$route.query.code;
124116
this.state = this.$route.query.state;
117+
118+
// 尝试登录一下
119+
this.loading = true;
125120
this.$store.dispatch("SocialLogin", {
126121
code: this.code,
127122
state: this.state,
@@ -183,6 +178,10 @@ export default {
183178
});
184179
}
185180
});
181+
},
182+
getUrlValue(key) {
183+
const url = new URL(decodeURIComponent(location.href));
184+
return url.searchParams.get(key);
186185
}
187186
}
188187
};

0 commit comments

Comments
 (0)